【发布时间】:2017-05-31 19:56:25
【问题描述】:
我已将 Capybara 包含在我的集成测试中。我已经根据文档设置了我的 test_helper 文件。
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'capybara'
require 'capybara/dsl'
require 'vcr'
class ActiveSupport::TestCase
include Devise::Test::IntegrationHelpers
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
fixtures :all
# Add more helper methods to be used by all tests here...
VCR.configure do |c|
c.hook_into :webmock
c.cassette_library_dir = 'vcr_cassettes'
c.default_cassette_options = { :record => :once }
end
end
class ActionDispatch::IntegrationTest
# Make the Capybara DSL available in all integration tests
include Capybara::DSL
# Reset sessions and driver between tests
# Use super wherever this method is redefined in your individual test classes
def teardown
Capybara.reset_sessions!
Capybara.use_default_driver
end
end
为了使用 Capybara 测试我的集成测试,我在我的 portfolio_flow_test 文件中设置了一个方法(也需要 test_helper.rb)
test "signed in user can visit portfolio index page" do
@user = users(:nicholas)
sign_in @user
visit portfolios_path
assert_select "h1", "Portfolios"
end
我在所有测试中都收到此错误
ArgumentError: rack-test requires a rack application, but none was given
Capybara 的默认驱动程序是机架测试,所以我不清楚为什么在运行测试时它会失败。
【问题讨论】: