我無法使Clearance身份驗證與Rails控制器單元測試一起使用。我遵循https://github.com/thoughtbot/clearance「控制器測試助手」的說明。你如何對需要認證的控制器進行單元測試?Rails間隙,單元測試控制器
我得到以下錯誤:
GoalsControllerTest#test_should_get_index:
NoMethodError: undefined method `sign_in_as' for #<GoalsControllerTest:0x007f8c41c6b9c8>
test/controllers/goals_controller_test.rb:7:in `block in <class:GoalsControllerTest>'
測試/ test_helper.rb中
require 'clearance/test_unit'
測試/控制器/ goals_controller_test.rb
require 'test_helper'
class GoalsControllerTest < ActionDispatch::IntegrationTest
setup do
user = User.new(fname: "Test", lname: "User", email: "[email protected]", password: "password")
sign_in_as(user)
@goal = goals(:one)
end
是在ApplicationController或輔助模塊中定義的'sign_in_as'方法嗎? – Linus