1
votes

I tried to follow these steps https://github.com/plataformatec/devise/wiki/How-To:-Test-with-Capybara but I don't pass login page. could you correct me and show what i'm doing wrong? 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:

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

Update 1
I've implemented warden.rb commenting out in the factory password_confirmation & changing confirmed_at Time.now I get this error:

  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
1

1 Answers

0
votes

I created a warden.rb in my spec/support dir:

RSpec.configure do |config|

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

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

end

Then, in my request spec:

before(:each) do
  @user = create(:user)
  login_as(@user, :scope => :user)
end