按照 github 上的文档做的
# Transactional fixtures do not work with Selenium tests, because Capybara
# uses a separate server thread, which the transactions would be hidden
# from. We hence use DatabaseCleaner to truncate our test database.
DatabaseCleaner.strategy = :truncation
class ActionDispatch::IntegrationTest
# Make the Capybara DSL available in all integration tests
include Capybara::DSL
# Stop ActiveRecord from wrapping tests in transactions
self.use_transactional_fixtures = false
teardown do
DatabaseCleaner.clean # Truncate the database
Capybara.reset_sessions! # Forget the (simulated) browser state
Capybara.use_default_driver # Revert Capybara.current_driver to Capybara.default_driver
end
end
rails g scaffold user email:string username:string
rake db:migrate
class UserTest < ActionDispatch::IntegrationTest
# setup do
# Capybara.javascript_driver = :webkit
# Capybara.current_driver = Capybara.javascript_driver
# end
test "should show username and email" do
get "/users/new"
fill_in "email", with: "[email protected]"
fill_in "Username", with: "aisensiy"
click_button "Create User"
assert_equal path, "/users"
end
end
然后就报错
ArgumentError: rack-test requires a rack application, but none was given
何故呢?