rails/rails-dom-testing

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:in block 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:in extract_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:in new' /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:in block (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.'
end

From 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.