From 9020abe0e92c78085ba2b826d442701921ff88ac Mon Sep 17 00:00:00 2001 From: Timm Date: Thu, 1 Aug 2013 22:22:32 +0200 Subject: Reworked the wrapping root in NodeSet implementation in css_select. --- actionpack/lib/action_dispatch/testing/assertions/selector.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/testing/assertions/selector.rb b/actionpack/lib/action_dispatch/testing/assertions/selector.rb index 04628539e8..167c80cd98 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/selector.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/selector.rb @@ -65,9 +65,11 @@ module ActionDispatch root, selector = args.shift, args.first end - # wrap in NodeSet to avoid this: - # .css('div') => no matches - Nokogiri::XML::NodeSet.new(root.document, [root]).css(selector) + root.css(selector).tap do |matches| + if matches.empty? && root.matches?(selector) + return Nokogiri::XML::NodeSet.new(root.document, [root]) + end + end end # An assertion that selects elements and makes one or more equality tests. -- cgit v1.2.3