我正在用
测试test/models/user_test.rb
test "should validate login" do
visit new_user_session
fill_in "email", with: 'test@test.com'
fill_in "password", with: 'testtest'
click_button "Sign in"
assert_equal some_url, current_path
end
当我运行 ruby -Itest test/models/user_test.rb
时,我收到此错误消息
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>'
如果我将 new_user_session
更改为 rake routes
提供的任何其他 path
,我会收到相同的消息,即 undefined local variable或方法
路径'`。有人可以帮忙吗?
最佳答案
看起来您正在进行集成测试,但将其编写在模型测试中。模型测试不会加载路线和其他细节供您使用。
关于ruby-on-rails - rails 测试无法识别路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20148433/