diff options
author | Timm <kaspth@gmail.com> | 2013-08-01 22:22:32 +0200 |
---|---|---|
committer | Timm <kaspth@gmail.com> | 2014-06-16 21:04:00 +0200 |
commit | 9020abe0e92c78085ba2b826d442701921ff88ac (patch) | |
tree | eba77865c0d4d64fe454478f28002993fb5778a9 /actionpack/lib/action_dispatch/testing | |
parent | 77d0333c08d3124120b604c821196db688ee9722 (diff) | |
download | rails-9020abe0e92c78085ba2b826d442701921ff88ac.tar.gz rails-9020abe0e92c78085ba2b826d442701921ff88ac.tar.bz2 rails-9020abe0e92c78085ba2b826d442701921ff88ac.zip |
Reworked the wrapping root in NodeSet implementation in css_select.
Diffstat (limited to 'actionpack/lib/action_dispatch/testing')
-rw-r--r-- | actionpack/lib/action_dispatch/testing/assertions/selector.rb | 8 |
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. |