2
votes

The sign in spec that was generated with the rails 4 template is failing, and it seems like what is being returned in the test environment should make the spec pass.

spec: Sign in user cannot sign in if not registered Is looking for "Invalid Email or Password" on the page. When I try to login in with invalid credentials this message is definitely displayed in the flash messages. Also, you can see that the page content returned by capybara in the test env has the text 'Invalid Email or Password'. See below:

  1) Sign in user cannot sign in if not registered
     Failure/Error: expect(page).to have_content I18n.t 'devise.failure.not_found_in_database', authentication_keys: 'email'
       expected to find text "Invalid email or password." in "Toggle navigation Home About Sign in Sign up × Invalid Email or password. Sign in Sign up Email Forgot password? Password Remember me"
     # ./spec/features/users/sign_in_spec.rb:13:in `block (2 levels) in <top (required)>'

  2) Sign in user cannot sign in with wrong email
     Failure/Error: expect(page).to have_content I18n.t 'devise.failure.not_found_in_database', authentication_keys: 'email'
       expected to find text "Invalid email or password." in "Toggle navigation Home About Sign in Sign up × Invalid Email or password. Sign in Sign up Email Forgot password? Password Remember me"
     # ./spec/features/users/sign_in_spec.rb:35:in `block (2 levels) in <top (required)>'

  3) Sign in user cannot sign in with wrong password
     Failure/Error: expect(page).to have_content I18n.t 'devise.failure.invalid', authentication_keys: 'email'
       expected to find text "Invalid email or password." in "Toggle navigation Home About Sign in Sign up × Invalid Email or password. Sign in Sign up Email Forgot password? Password Remember me"
     # ./spec/features/users/sign_in_spec.rb:46:in `block (2 levels) in <top (required)>'

UPDATE:

I tried changing from this:

expect(page).to have_content I18n.t 'devise.failure.not_found_in_database', authentication_keys: 'email'

to this:

expect(page).to have_selector('#flash_alert', visible: true, text: "Invalid Email or Password.")

But now the test fails like so:

  1) Sign in user cannot sign in if not registered
     Failure/Error: expect(page).to have_selector('#flash_alert', visible: true, text: "Invalid Email or Password.")
       expected to find css "#flash_alert" with text "Invalid Email or Password." but there were no matches. Also found "Invalid Email or password.", which matched the selector but not all filters.
2

2 Answers

4
votes

you are checking 'Invalid email or password.' but the page has the content 'Invalid Email or password' with Email

2
votes

When I changed the authentication key to 'Email' instead of 'email', the test passes. ugh...

  scenario 'user cannot sign in if not registered' do
    signin('[email protected]', 'please123')
    expect(page).to have_content I18n.t 'devise.failure.not_found_in_database', authentication_keys: 'Email'
  end