assert_select and css_select not working
aaronhumerickhouse opened this issue · 2 comments
I'm using the code css_select('tr.user') and assert_css('tr.user', 3). Both of them are running into the same problem. The node is nil and an exception is being thrown on node.document. However in my html, I have: <tr class="user">.
NoMethodError: undefined method
'document' for nil:NilClass /Users/aaronhumerickhouse/.rvm/gems/ruby-2.2.3@bowling-app/gems/rails-dom-testing-1.0.7/lib/rails/dom/testing/assertions/selector_assertions.rb:304:innodeset'
/Users/aaronhumerickhouse/.rvm/gems/ruby-2.2.3@bowling-app/gems/rails-dom-testing-1.0.7/lib/rails/dom/testing/assertions/selector_assertions.rb:167:inblock in assert_select' /Users/aaronhumerickhouse/.rvm/gems/ruby-2.2.3@bowling-app/gems/rails-dom-testing-1.0.7/lib/rails/dom/testing/assertions/selector_assertions/html_selector.rb:66:incall'
/Users/aaronhumerickhouse/.rvm/gems/ruby-2.2.3@bowling-app/gems/rails-dom-testing-1.0.7/lib/rails/dom/testing/assertions/selector_assertions/html_selector.rb:66:inextract_root' /Users/aaronhumerickhouse/.rvm/gems/ruby-2.2.3@bowling-app/gems/rails-dom-testing-1.0.7/lib/rails/dom/testing/assertions/selector_assertions/html_selector.rb:9:ininitialize'
/Users/aaronhumerickhouse/.rvm/gems/ruby-2.2.3@bowling-app/gems/rails-dom-testing-1.0.7/lib/rails/dom/testing/assertions/selector_assertions.rb:167:innew' /Users/aaronhumerickhouse/.rvm/gems/ruby-2.2.3@bowling-app/gems/rails-dom-testing-1.0.7/lib/rails/dom/testing/assertions/selector_assertions.rb:167:inassert_select'
./spec/features/users/index_spec.rb:15:inblock (2 levels) in <top (required)>' -e:1:inload'
-e:1:in `
The problems seem to lay within:
root = args.size == 1 ? document_root_element : args.shift
nodeset(root).css(args.first) nodeset document_root_element`document_root_element is returning with nil and not raising NotImplementedError
def document_root_element
raise NotImplementedError, 'Implementing document_root_element makes ' \
'assert_select work without needing to specify an element to select from.'
endFrom Gemfile.lock: rails-dom-testing (1.0.7)
@aaronhumerickhouse Did you ever figure out what the problem was?
I just got this on a bunch of tests and discovered that in each case, I had accidentally removed render from my before block.
Not to say this was the same thing ~7 years ago, but someone else searching for the issue might find this helpful.