我无法让 Clearance 身份验证与 Rails 控制器单元测试一起使用。我已按照https://github.com/thoughtbot/clearance “控制器测试助手”中的说明进行操作。您如何对需要身份验证的控制器进行单元测试?
我收到以下错误:
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: "testuser@test.com", password: "password")
sign_in_as(user)
@goal = goals(:one)
end