2011-04-01 113 views
6

我試圖讓水豚與軌道3(和測試單元),但工作的時候我嘗試運行rake test:integration我得到一個錯誤:ArgumentError: @request must be an ActionDispatch::Request Rails 3的水豚錯誤

測試

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 

integration_test_helper:

require 'test_helper' 
require 'capybara/rails' 

module ActionDispatch 
    class IntegrationTest 
    include Capybara 
    end 
end 

我真的不知道WH ats going wrong ...

回答

3

這是一個水豚問題,在visit之後沒有分配任何東西給@request變量。

一種解決方案是使用軌道內置方法,即

get '/login' 
assert_response :success 

在rspec的,我使用斷言上page而非@request

some discussion here.

+1

您的問題官方解釋:https://github.com/jnicklas/capybara/issues/240 – user664833 2012-07-22 22:53:15