err*_*ler 6 testing ruby-on-rails testunit ruby-on-rails-3
我试图让Capybara使用rails 3(和测试单元)但是当我尝试运行时rake test:integration出现错误:ArgumentError: @request must be an ActionDispatch::Request
测试:
require 'integration_test_helper'
class UserNotesTest < ActionDispatch::IntegrationTest
test "User should login" do
user = Factory.create(:user)
visit '/login'
assert_response :success
fill_in 'user_email', :with => user.email
fill_in 'user_password', :with => user.password
click_button 'Sign in'
assert_redirect_to notes_path
end
end
Run Code Online (Sandbox Code Playgroud)
integration_test_helper:
require 'test_helper'
require 'capybara/rails'
module ActionDispatch
class IntegrationTest
include Capybara
end
end
Run Code Online (Sandbox Code Playgroud)
我不确定哪里出错了......
@request这是水豚在之后没有为变量分配任何内容的问题visit。
一种解决方案是使用 Rails 内置方法,即
get '/login'
assert_response :success
Run Code Online (Sandbox Code Playgroud)
在 rspec 中,我使用断言 onpage而不是@request.
这里有一些讨论。