简体   繁体   English

Capybara Minitest `has_field?` 工作,但 `assert_field` 给出错误“未使用的参数传递给 Capybara::Queries::SelectorQuery”

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

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]:将 Capybara 与 Minitest 一起使用,driver:rack_test,以下选择器会找到输入,但并行断言会出错 [已编辑以包含跟踪]:

(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? Capybara Capybara::Minitest::Assertions#assert_field的 rubydocs 说该方法是直接从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.编辑:迟来的意识到这可能是相关的......我在测试中包括 Capybara::Minitest::Assertions,并使用 Sean P. Doyle 的 gem ActionDispatch::Testing::Integration::Capybara在集成测试中使用 Capybara。

Thanks to the eagle eye of @ThomasWalpole for pointing the way — I didn't know it mattered so much where require s and include s are located in the ancestry of a class.感谢@ThomasWalpole 的鹰眼指路——我不知道requireinclude位于 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;首先,我正在使用的实验gem的作者告诉我,我的手册中包含的 Capybara 类是多余的; they are already included by the gem.它们已经包含在 gem 中。 I removed the gem to isolate the problem, which was present already had before adding the gem.我删除了 gem 以隔离问题,该问题在添加 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.它的核心是, require capybara/railsrequire capybara/minitest并在我的test_helper.rbinclude Capybara::DSL ,但在我单独的CapybaraIntegrationTestCase.rb中包含 Capybara include Capybara::Minitest::Assertions似乎已经放置了调用堆栈乱序。 Moving all Capybara requires and includes to the CapybaraIntegrationTestCase cleared this up.将所有 Capybara 需要和包含到CapybaraIntegrationTestCase清除了这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM