我尝试按照这些步骤https://github.com/plataformatec/devise/wiki/How-To:-Test-with-Capybara但我没有通过登录页面。你能纠正我并说明我做错了什么吗?rspec
require 'spec_helper'
include Warden::Test::Helpers
Warden.test_mode!
describe "Business::Contacts" do describe "GET /business_contacts", js: true do
before(:each) do
@account = create :business_account
@account.confirmed_at = Time.now
@account.save
login_as(@account, scope: :account, run_callbacks: false)
end
> it "show page with restricted access", slow: true do
> visit business_contacts_path
> save_and_open_page
> end
工厂:
factory :business_account, class: 'Account' do
email { Faker::Internet.email }
username { Faker::Name.name }
first_name { Faker::Name.name }
last_name { Faker::Name.name }
password "foAAbar123"
password_confirmation { |u| u.password }
confirmed_at Time.now - 1.day
phone_number "2234567890"
end
更新 1
我已经warden.rb
在工厂 password_confirmation 中实现了注释并更改confirmed_at Time.now
我收到此错误:
1) Business::Contacts GET /business_contacts visit restricted webpage
Failure/Error: Unable to find matching line from backtrace
NoMethodError:
undefined method `env' for nil:NilClass