Ruby 在 Rails 未抓到的投掷 :warden
Ruby on Rails uncaught throw :warden
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,但我仍然得到未捕获的 throw :warden,这让我发疯。救救我? :[
啊,我的危机是通过在测试中创建一个用户而不是使用固定装置来避免的
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') %>
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,但我仍然得到未捕获的 throw :warden,这让我发疯。救救我? :[
啊,我的危机是通过在测试中创建一个用户而不是使用固定装置来避免的
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') %>