require 'test_helper'
class DashboardControllerTest < ActionController::TestCase
include Devise::TestHelpers
include Warden::Test::Helpers
Warden.test_mode!
test "should get index" do
get :index
assert_response :success
end
end
我按照其他堆叠帖子的指示包括Warden :: Test :: Helpers但是我仍然得到未被捕获的投掷:warden并且它让我发疯。救救我? :
答案 0 :(得分:1)
啊我的危机只是在测试中创建用户而不是使用灯具而避免了
describe "user does something" do
it "allows users to do something" do
User.create!(email: "example@user.com", password: "abcdef", first_name: 'Jim', last_name: 'Bo', username: 'somename')
我提出上面的代码然后提出任何期望,一切都很好。出于某种原因,当我用自动生成的测试和固定装置测试用户时,未被捕获的抛出:warden被提出
class StudentsControllerTest < ActionController::TestCase
setup do
@student = students(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:students)
end
end
上面是一个失败的基本测试的例子,下面是我使用过的东西的例子
one:
first_name: User
last_name: Example
email: example@user.com
password: abcdef
encrypted_password: <%= User.new.send(:password_digest, 'lalala') %>