From 1b0a4b9351c47140cd6ae6336c1eb52159766d9d Mon Sep 17 00:00:00 2001 From: Timm Date: Wed, 24 Jul 2013 18:16:11 +0200 Subject: Changed css_select to not count on multiple selectors. Fixed bug in determine_root_from where @selected was an Array. Changed assert_select_encoded to use a fragment instead of a document. --- .../lib/action_dispatch/testing/assertions/selector.rb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'actionpack/lib/action_dispatch/testing/assertions/selector.rb') diff --git a/actionpack/lib/action_dispatch/testing/assertions/selector.rb b/actionpack/lib/action_dispatch/testing/assertions/selector.rb index 0ba3fffd5a..615f68e622 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/selector.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/selector.rb @@ -59,10 +59,10 @@ module ActionDispatch def css_select(*args) raise ArgumentError, "you at least need a selector" if args.empty? - if args.first.is_a?(String) # use nokogiri's ability for more selectors - root, selectors = response_from_page, args + if args.first.is_a?(String) + root, selectors = response_from_page, args.first else - root, selectors = args.shift, args + root, selectors = args.shift, args.first end root.css(selectors) @@ -248,7 +248,7 @@ module ActionDispatch end selected = elements.map do |elem| - root = Loofah.document(CGI.unescapeHTML("#{elem.text}")).root + root = Loofah.fragment(CGI.unescapeHTML("#{elem.text}")) css_select(root, "encoded:root", &block)[0] end @@ -311,12 +311,10 @@ module ActionDispatch end # +equals+ must contain :minimum, :maximum and :count keys - def assert_size_match!(size, equals, selector, message = nil) + def assert_size_match!(size, equals, css_selector, message = nil) min, max, count = equals[:minimum], equals[:maximum], equals[:count] - # FIXME: minitest provides messaging when we use assert_operator, - # so is this custom message really needed? - message ||= %(Expected #{count_description(min, max, count)} matching "#{selector.to_s}", found #{size}.) + message ||= %(Expected #{count_description(min, max, count)} matching "#{css_selector}", found #{size}.) if count assert_equal size, count, message else @@ -380,6 +378,10 @@ module ActionDispatch root_or_selector elsif @selected # nested call - wrap in document + if @selected.is_a?(Array) + doc = @selected.empty? ? @page.document : @selected[0].document + @selected = Nokogiri::XML::NodeSet.new(doc, @selected) + end Loofah.fragment('').tap { |d| d.add_child @selected } else @page -- cgit v1.2.3