我正在尝试使用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
触发的,因为我已经尝试将 spec 文件中的所有内容注释掉但仍然得到相同的错误。
我原以为Devise测试助手可以直接使用;难道我错过了某些配置吗?谢谢。
:request
,那么也适用于请求规格。 - oneWorkingHeadphone