aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_dispatch/testing/assertions/selector.rb8
1 files changed, 5 insertions, 3 deletions
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:
- # <element div>.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.