[英]Rails project, while testing with capybara: ArgumentError: Unused parameters passed to Capybara::Queries::SelectorQuery : [4]
Test that the form has 4 inputs is not working, I am copy pasting the line from the documentation: 测试表单有4个输入是否无法正常工作,我正在复制文档中的行:
assert_select "form input", 4
any ideas? 有任何想法吗?
require "application_system_test_case"
class QuestionsTest < ApplicationSystemTestCase
test "visiting /ask renders the form" do
visit ask_url
assert_selector "p", text: "Ask your coach anything"
assert_select "form input", 4
end
end
The complete error message is: 完整的错误消息是:
Error:
QuestionsTest#test_visiting_/ask_renders_the_form:
ArgumentError: Unused parameters passed to Capybara::Queries::SelectorQuery : [4]
test/system/questions_test.rb:9:in `block in <class:QuestionsTest>'
Any help would be appreciate. 任何帮助将不胜感激。
Don't know why my question is wrong according to stackoverflow, after having read their guidelines. 在阅读了他们的指南之后,根据stackoverflow不知道为什么我的问题是错误的。
The assert_select
method you're copying from documentation is a Rails method that was moved out of Rails into the rails-dom-testing
gem around Rails 4.2. 您要从文档中复制的
assert_select
方法是一种Rails方法,该方法已从Rails中移出,进入了围绕Rails 4.2的rails-dom-testing
gem。 However, the assert_select
method you're actually calling is a Capybara provided method - https://www.rubydoc.info/gems/capybara/Capybara/Minitest/Assertions#assert_select-instance_method - which deals with <select> elements, doesn't take the same parameters, and isn't the correct method for what you are trying to do. 然而,
assert_select
你实际上调用方法是水豚提供的方法- https://www.rubydoc.info/gems/capybara/Capybara/Minitest/Assertions#assert_select-instance_method -与交易的<select>元素,没有按”不能使用相同的参数,也不是您尝试执行的正确方法。 With Capybara what you are trying to do is 使用水豚,您想要做的是
assert_css "form input", count: 4
which is the same as assert_selector :css, "form input", count: 4
, which can also be written assert_selector "form input", count: 4
if Capybara.default_selector == :css
. 与
assert_selector :css, "form input", count: 4
相同assert_selector :css, "form input", count: 4
,也可以写为assert_selector "form input", count: 4
如果Capybara.default_selector == :css
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.