Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid email or password error when testing devise sign in with RSpec feature spec

I keep getting Invalid email or password. error in RSpec feature test when I try to test sign in implemented using Devise.

spec/features/signing_in_spec.rb

require 'spec_helper'

feature 'Signing in' do
  let!(:user) { create :user }

  scenario 'signs in user with valid credentials', js: true do
    visit '/users/sign_in'

    fill_in 'Email', with: user.email
    fill_in 'Password', with: user.password
    click_button 'Sign in'

    expect(page).to have_content 'Dashboard'
  end
end

spec/factories/users.rb

FactoryGirl.define do
  factory :user do
    email '[email protected]'
    password '12345678'
    password_confirmation '12345678'

    factory :admin do
      email '[email protected]'
    end
  end
end

I already verified that user is saved into DB and that sing in works in development.

like image 911
Marek Takac Avatar asked Dec 22 '25 12:12

Marek Takac


1 Answers

I actually had the same issue

this https://github.com/plataformatec/devise/wiki/How-To:-Test-with-Capybara helped me.

I had to add this file to my support folder

https://github.com/railscasts/391-testing-javascript-with-phantomjs/blob/master/checkout-after/spec/support/share_db_connection.rb

like image 196
Leo Royzengurt Avatar answered Dec 24 '25 03:12

Leo Royzengurt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!