我无法使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