Capybara Minitest `has_field?` works, but `assert_field` gives error "unused parameters passed to Capybara::Queries::SelectorQuery"

Viewed 55

In my page, I have a link like this:

<input value="" data-autofocus="true" class="form-control" 
       type="text" name="user[login]" id="user_login" />

Using Capybara with Minitest, driver :rack_test, the following selector finds the input, but the parallel assertion gets an error [edited to include the trace]:

(ruby) has_field?("user_login")
true
(ruby) assert_field("user_login")
eval error: Unused parameters passed to Capybara::Queries::SelectorQuery : [:field, "user_login"]
/home/vagrant/.rvm/gems/ruby-3.0.4/gems/capybara-3.37.1/lib/capybara/queries/selector_query.rb:52:in `initialize'
  /home/vagrant/.rvm/gems/ruby-3.0.4/gems/capybara-3.37.1/lib/capybara/node/matchers.rb:842:in `new'
  /home/vagrant/.rvm/gems/ruby-3.0.4/gems/capybara-3.37.1/lib/capybara/node/matchers.rb:842:in `_verify_selector_result'
  /home/vagrant/.rvm/gems/ruby-3.0.4/gems/capybara-3.37.1/lib/capybara/node/matchers.rb:110:in `assert_selector'
  /home/vagrant/.rvm/gems/ruby-3.0.4/gems/capybara-3.37.1/lib/capybara/session.rb:771:in `assert_selector'
  /home/vagrant/.rvm/gems/ruby-3.0.4/gems/capybara-3.37.1/lib/capybara/dsl.rb:52:in `call'
  /home/vagrant/.rvm/gems/ruby-3.0.4/gems/capybara-3.37.1/lib/capybara/dsl.rb:52:in `assert_selector'
  /home/vagrant/.rvm/gems/ruby-3.0.4/gems/capybara-3.37.1/lib/capybara/minitest.rb:288:in `block (2 levels) in <module:Assertions>'
  (rdbg)//vagrant/mo/test/integration/capybara_student_test.rb:1:in `block in test_creating_drafts'
nil

The rubydocs for Capybara::Minitest::Assertions#assert_field say that the method is built straight off Node::Matchers#has_field?. I wonder why it isn't working?

EDIT: Belatedly realizing this is probably relevant... I'm including Capybara::Minitest::Assertions in the tests, and using Sean P. Doyle's gem ActionDispatch::Testing::Integration::Capybara to use Capybara in integration tests.

1 Answers

Thanks to the eagle eye of @ThomasWalpole for pointing the way — I didn't know it mattered so much where requires and includes are located in the ancestry of a class.

First of all, the author of the experimental gem i was using informed me that my manual includes of the Capybara classes were redundant; they are already included by the gem. I removed the gem to isolate the problem, which was present already had before adding the gem.

The core of it was, having require capybara/rails, require capybara/minitest and include Capybara::DSL in my test_helper.rb, but include Capybara::Minitest::Assertions in my separate CapybaraIntegrationTestCase.rb seems to have put the call stack out of order. Moving all Capybara requires and includes to the CapybaraIntegrationTestCase cleared this up.

Related