1

我尝试按照这些步骤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
4

1 回答 1

0

我在我的规范/支持目录中创建了一个warden.rb:

RSpec.configure do |config|

 config.include Warden::Test::Helpers, :type => :request
 Warden.test_mode!

 config.after(:each) do
  Warden.test_reset!
 end

end

然后,在我的请求规范中:

before(:each) do
  @user = create(:user)
  login_as(@user, :scope => :user)
end
于 2013-09-03T19:16:36.597 回答