gpt4 book ai didi

ruby-on-rails - FactoryGirl错误:warden with RSpec in Rails 4

转载 作者:行者123 更新时间:2023-11-28 21:28:23 24 4
gpt4 key购买 nike

当我测试我的规范之一时,我继续收到此问题:

Failure/Error: visit "/"
UncaughtThrowError:
uncaught throw :warden

下面是代码的各个部分:

#_spec.rb
require "rails_helper"

RSpec.feature "Users can create a new discussion" do
before do
login_as(FactoryGirl.create(:user))

visit "/"
click_link "Discussions"
click_link "Start a discussion"
end

scenario "with valid attributes" do
click_button "Post"
end
end

#_factory.rb
FactoryGirl.define do
factory :user do
sequence(:email) { |n| "test#{n}@example.com" }
password "password"
sequence(:user_name) { |n| "User#{n}" }
first_name "Test"
last_name "User"
country "United States"
state "Nevada"
city "Las Vegas"
end
end

#rails_helper
config.include Warden::Test::Helpers, type: :feature
config.after(type: :feature) { Warden.test_reset! }

显然,测试在 _spec 文件中标记了访问行,但我不确定原因。如果我可以添加任何其他代码来提供帮助,请告诉我,谢谢!

更新

所以这个问题是因为我在 Devise 中使用了 confirmable;但是,我不清楚如何通过测试来确认用户。这是我可以在工厂或规范本身中放置的东西吗?我会认为规范本身?

最佳答案

只需向用户发出一个简单的.confirm!,即:

before do
user = FactoryGirl.create(:user)
user.confirm!
login_as(user)

visit "/"
click_link "Discussions"
click_link "Start a discussion"
end

您似乎还缺少将 warden 设置为测试模式(将其放入 rails_helper):

RSpec.configure do |config|
config.include Warden::Test::Helpers
config.before :suite do
Warden.test_mode!
end
end

在此处查看其他详细信息:https://github.com/plataformatec/devise/wiki/How-To%3a-Test-with-Capybara .

关于ruby-on-rails - FactoryGirl错误:warden with RSpec in Rails 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32543878/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com