Rails Minitest with Capybara,如何使 assert_select "button"、"label" 正常工作?
Rails Minitest with Capybara, how get assert_select "button", "label" to work correctly?
在(未启用水豚的)IntegrationTest 中,此断言有效:
assert_select "button", "Update"
页面包含:
... <button name="button" type="submit" class="btn btn-primary">Update Account</button> ...
我需要 Capybara 进行一些 IntegrationTest 测试。
当包含 Capybara::Minitest::Assertions 时,如何执行相同的断言(例如,简单地断言有一个带有文本更新的按钮)?
我将水豚添加到 test_helper.rb 中,如下所示;现在,同样的断言现在抛出这个错误:
TypeError: no implicit conversion of String into Hash
如果我将断言的格式更改为:
assert_select "button", text: "Update Account"
它现在抛出这个失败:
expected to find select box "button" that is not disabled but there were no matches
如果我将断言的格式更改为:
assert_selector "button", text: "Update Account"
它现在抛出这个失败:
expected to find css "button" but there were no matches
# test_helper.rb
require 'capybara/rails'
require 'capybara/minitest'
class ActionDispatch::IntegrationTest
include Devise::Test::IntegrationHelpers
include FactoryBot::Syntax::Methods
# Make the Capybara DSL available in all integration tests
include Capybara::DSL
include Capybara::Minitest::Assertions #### THIS LINE changes minitest assert_select #####
# Reset sessions and driver between tests
teardown do
Capybara.reset_sessions!
Capybara.use_default_driver
end
end
你想要
assert_selector :button, "Update Account"
但是您还需要使用 Capybara 方法进行会话控制,visit
,等等 -- Capybara 不使用来自集成测试的 get
、post
等响应.
在(未启用水豚的)IntegrationTest 中,此断言有效:
assert_select "button", "Update"
页面包含:
... <button name="button" type="submit" class="btn btn-primary">Update Account</button> ...
我需要 Capybara 进行一些 IntegrationTest 测试。
当包含 Capybara::Minitest::Assertions 时,如何执行相同的断言(例如,简单地断言有一个带有文本更新的按钮)?
我将水豚添加到 test_helper.rb 中,如下所示;现在,同样的断言现在抛出这个错误:
TypeError: no implicit conversion of String into Hash
如果我将断言的格式更改为:
assert_select "button", text: "Update Account"
它现在抛出这个失败:
expected to find select box "button" that is not disabled but there were no matches
如果我将断言的格式更改为:
assert_selector "button", text: "Update Account"
它现在抛出这个失败:
expected to find css "button" but there were no matches
# test_helper.rb
require 'capybara/rails'
require 'capybara/minitest'
class ActionDispatch::IntegrationTest
include Devise::Test::IntegrationHelpers
include FactoryBot::Syntax::Methods
# Make the Capybara DSL available in all integration tests
include Capybara::DSL
include Capybara::Minitest::Assertions #### THIS LINE changes minitest assert_select #####
# Reset sessions and driver between tests
teardown do
Capybara.reset_sessions!
Capybara.use_default_driver
end
end
你想要
assert_selector :button, "Update Account"
但是您还需要使用 Capybara 方法进行会话控制,visit
,等等 -- Capybara 不使用来自集成测试的 get
、post
等响应.