From 205bfe9af80ad6bfee323f72e421587e6ad7e26f Mon Sep 17 00:00:00 2001 From: Timm Date: Sat, 20 Jul 2013 13:43:58 +0200 Subject: Changed css_select and pulled out response_from_page from Selector. --- .../action_dispatch/testing/assertions/selector.rb | 40 +++++++++------------- 1 file 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), -- cgit v1.2.3