tenderlove / nokogiri

Nokogiri (鋸) is an HTML, XML, SAX, and Reader parser with XPath and CSS selector support.

This URL has Read+Write access

nokogiri / lib / action-nokogiri.rb
100644 37 lines (32 sloc) 0.853 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require 'nokogiri'
 
#
# to use this in your Rails view or controller tests, simply:
#
# require 'action-nokogiri'
#
# class KittehControllerTest < ActionController::TestCase
# def test_i_can_does_test_with_nokogiri
# get(:index, {:wants => "cheezburgers"})
# assert @response.html.at("h2.lolcats")
# end
#
module ActionController
  module TestResponseBehavior # :nodoc:
 
    ###
    # Get your response as a Nokogiri::XML::Document using the
    # Nokogiri.HTML parser
    def html(flavor=nil)
      if flavor == :hpricot
        @_nokogiri_html_hpricot ||= Nokogiri::Hpricot(body)
      else
        @_nokogiri_html_vanilla ||= Nokogiri::HTML(body)
      end
    end
 
    ###
    # Get your response as a Nokogiri::XML::Document using the
    # Nokogiri.XML parser
    def xml
      @_nokogiri_xml ||= Nokogiri::XML(body)
    end
 
  end
end