【发布时间】:2017-03-05 03:44:43
【问题描述】:
我无法让 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/test_helper.rb
require 'clearance/test_unit'
test/controller/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
【问题讨论】:
-
'sign_in_as' 方法是在 ApplicationController 中定义的还是在辅助模块中定义的?
标签: ruby-on-rails unit-testing clearance