测试该表单有4个输入不起作用,我正在复制文档中的行:
assert_select "form input", 4
有什么想法吗?
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
完整的错误消息是:
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>'
任何帮助将不胜感激。
在阅读了他们的指南后,根据stackoverflow不知道我的问题为什么出错。
答案 0 :(得分:2)
您要从文档中复制的assert_select
方法是一种Rails方法,该方法已从Rails移出到rails-dom-testing
gem周围的Rails 4.2中。但是,您实际上调用的assert_select
方法是Capybara提供的方法-https://www.rubydoc.info/gems/capybara/Capybara/Minitest/Assertions#assert_select-instance_method-处理
assert_css "form input", count: 4
与assert_selector :css, "form input", count: 4
相同,如果assert_selector "form input", count: 4
也可以写成Capybara.default_selector == :css
。