【发布时间】:2014-12-04 01:17:45
【问题描述】:
我正在尝试使用 factorygirl 创建用户,然后使用 Devise 的 sign_in 方法对用户进行身份验证,然后使用 capybara 单击“退出”链接,从而为退出流程创建规范。
我在运行规范时遇到(在我看来是)一个奇怪的错误:
Failures:
1) Sign out flow successfully redirects to the welcome index (root)
Failure/Error: Unable to find matching line from backtrace
NoMethodError:
undefined method `env' for nil:NilClass
# /home/vagrant/.rvm/gems/ruby-2.0.0-p576/gems/devise-3.4.1/lib/devise/test_helpers.rb:24:in `setup_controller_for_warden'
Finished in 0.00226 seconds (files took 3.32 seconds to load)
1 example, 1 failure
这是规格:
require 'rails_helper'
describe "Sign out flow" do
include Devise::TestHelpers
describe "successfully" do
it "redirects to the welcome index (root)" do
user = create(:user)
sign_in user
within '.user-info' do
click_link 'Sign Out'
end
expect(current_path).to eq root_path
end
end
end
还有我的user.rb工厂:
FactoryGirl.define do
factory :user do
name "Fake User"
sequence(:email, 100) { |n| "person#{n}@example.com" }
password "helloworld"
password_confirmation "helloworld"
confirmed_at Time.now
end
end
错误似乎只是从include Devise::TestHelpers 行触发的,因为我尝试注释掉规范的全部内容,但仍然得到相同的错误。
我认为 Devise 测试助手可以开箱即用;我错过了一些配置吗?谢谢。
【问题讨论】:
标签: ruby-on-rails-4 rspec devise capybara factory-bot