【问题标题】:Ruby on Rails uncaught throw :wardenRuby on Rails 未捕获的抛出 :warden
【发布时间】:2015-01-03 01:48:40
【问题描述】:
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,这让我发疯。救我? :[

【问题讨论】:

标签: ruby-on-rails ruby devise warden


【解决方案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') %>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-30
    • 2014-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-30
    相关资源
    最近更新 更多