2013-11-22 169 views
0

我測試test/models/user_test.rb軌測試中無法識別路徑

test "should validate login" do 
    visit new_user_session 
    fill_in "email", with: '[email protected]' 
    fill_in "password", with: 'testtest' 
    click_button "Sign in" 
    assert_equal some_url, current_path 
    end 

當我運行ruby -Itest test/models/user_test.rb,如果我改變new_user_session任何其他pathrake routes提供我收到此錯誤信息

UserTest#test_should_validate_login: 
NameError: undefined local variable or method `new_user_session' for #<UserTest:0x007fcbd8e98378> 
    test/models/user_test.rb:22:in `block in <class:UserTest>' 

,我得到了相同的信息,即undefined local variable or method path'`。有人可以幫忙嗎?

回答

1

看起來您正在進行集成測試,但將其寫入模型測試。模型測試將不會有加載的路線和其他細節供您使用。

+0

是的,我誤導了謝謝 – user1611830

0

你需要或者pathurl追加到的new_user_session以最終獲得的實際路徑:

test "should validate login" do 
    visit new_user_session_path 
    fill_in "email", with: '[email protected]' 
    fill_in "password", with: 'testtest' 
    click_button "Sign in" 
    assert_equal some_url, current_path 
    end 

見軌道的the path and url helpers部分路線導向以獲得更多信息。