diff options
author | Timm <kaspth@gmail.com> | 2013-07-20 13:43:58 +0200 |
---|---|---|
committer | Timm <kaspth@gmail.com> | 2014-06-15 23:40:57 +0200 |
commit | 205bfe9af80ad6bfee323f72e421587e6ad7e26f (patch) | |
tree | b55645b1d7f0479987c18bd0ad65d6c64f3b913c /actionpack/lib | |
parent | 0538d26c15bd64a3b0c052a62f4d480e01b914bd (diff) | |
download | rails-205bfe9af80ad6bfee323f72e421587e6ad7e26f.tar.gz rails-205bfe9af80ad6bfee323f72e421587e6ad7e26f.tar.bz2 rails-205bfe9af80ad6bfee323f72e421587e6ad7e26f.zip |
Changed css_select and pulled out response_from_page from Selector.
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_dispatch/testing/assertions/selector.rb | 40 |
1 files changed, 17 insertions, 23 deletions
diff --git a/actionpack/lib/action_dispatch/testing/assertions/selector.rb b/actionpack/lib/action_dispatch/testing/assertions/selector.rb index 2c1ad76ba9..883073ad3e 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/selector.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/selector.rb @@ -59,21 +59,15 @@ module ActionDispatch # ... # end def css_select(*args) - # See assert_select to understand what's going on here. - - parser = Selector.new(@selected, args, Proc.new do |css_selector| - # will only be called if we're a nested select, i.e. @selected is set - matches = [] - @selected.each do |selected| - subset = css_select(selected, css_selector) - subset.each do |match| - matches << match unless matches.include?(match) - end - end - return matches - end) + raise ArgumentError, "you at least need a selector" if args.empty? - parser.root.css(parser.css_selector) + if args.first.is_a?(String) # allow nokogiri's ability to use several selectors + root, selectors = response_from_page, args + else + root, selectors = args.shift, args + end + + root.css(selectors) end # An assertion that selects elements and makes one or more equality tests. @@ -347,6 +341,15 @@ module ActionDispatch yield sprintf("<%s> expected but was\n<%s>.", match_with, content) if block_given? end + def response_from_page + @html_document ||= if @response.content_type =~ /xml$/ + Loofah.xml_fragment(@response.body) + else + Loofah.fragment(@response.body) + end + @html_document.root + end + class Selector #:nodoc: attr_accessor :root, :css_selector @@ -364,15 +367,6 @@ module ActionDispatch @css_selector = css_selector(arg) end - def response_from_page - @html_document ||= if @response.content_type =~ /xml$/ - Loofah.xml_fragment(@response.body) - else - Loofah.fragment(@response.body) - end - @html_document.root - end - def determine_root_from(root_or_selector) if root_or_selector.is_a?(Nokogiri::XML::Node) # First argument is a node (tag or text, but also HTML root), |