diff options
| author | mo khan <mo@mokhan.ca> | 2015-02-01 21:15:26 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2015-02-01 21:15:26 -0700 |
| commit | 2acf0153b6a21739fd8b1ae37e199cb0bf800f52 (patch) | |
| tree | 43e9b314de6c76a1d0ff4858d0057802289ba6a6 /spec | |
| parent | cf11fac246c680b970280142d2127c86592da833 (diff) | |
add spec for invalid password.
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/features/sessions_spec.rb | 33 | ||||
| -rw-r--r-- | spec/support/pages/login_page.rb | 10 |
2 files changed, 28 insertions, 15 deletions
diff --git a/spec/features/sessions_spec.rb b/spec/features/sessions_spec.rb index 82690920..3bcf9102 100644 --- a/spec/features/sessions_spec.rb +++ b/spec/features/sessions_spec.rb @@ -1,8 +1,9 @@ -require 'rails_helper' +require "rails_helper" describe "Logins" do describe "GET /login" do subject { LoginPage.new } + let(:error_message) { I18n.t("sessions.create.failure.invalid") } before :each do subject.visit_page @@ -11,26 +12,38 @@ describe "Logins" do context "when an email is registered" do let!(:user) { create(:user, password: "password") } - before :each do - subject.login_with(email: user.email, password: "password") - end + context "when the password is correct" do + before :each do + subject.login_with(email: user.email, password: "password") + end - it "logs the user in" do - expect(page).to have_content("Log Out") + it "logs the user in" do + expect(page).to have_content("Log Out") + end + + it "has no errors" do + expect(page).to_not have_content(error_message) + end end - it "has no errors" do - expect(page).to_not have_content(I18n.t('devise.failure.invalid')) + context "when the password is incorrect" do + before :each do + subject.login_with(email: user.email, password: "wrong") + end + + it "displays an error" do + expect(page).to have_content(error_message) + end end end context "when an email is not known" do before :each do - subject.login_with(email: 'test@example.com', password: 'password') + subject.login_with(email: "test@example.com", password: "password") end it "displays an error message" do - expect(page).to have_content("invalid email or password.") + expect(page).to have_content(error_message) end end end diff --git a/spec/support/pages/login_page.rb b/spec/support/pages/login_page.rb index 7e2e7542..90010093 100644 --- a/spec/support/pages/login_page.rb +++ b/spec/support/pages/login_page.rb @@ -1,14 +1,14 @@ -require_relative '../web_page.rb' +require_relative "../web_page.rb" class LoginPage < WebPage def initialize super(new_session_path) end - def login_with(email:, password: 'password') - within('.form-inline') do - fill_in('session_username', with: email) - fill_in('session_password', with: password) + def login_with(email:, password: "password") + within(".form-inline") do + fill_in("session_username", with: email) + fill_in("session_password", with: password) end click_button("Sign In") end |
