Here I am trying to avoid hardcoding in flash messages by using I18n. Also, I have tried to use a CSS selector for submitting the form to make the tests less brittle (I don't really care that much about what the text on the button is - more what happens when submitting).
Is this a good approach for making tests less brittle due to translation changes?
RSpec.feature "Classic Authentication" do
let(:submit) { find(:css, 'input[type="submit"]') }
let(:user) { FactoryGirl.create(:user) }
context 'Registation' do
background do
visit new_user_registration_path
page.fill_in 'Email', with: 'test@example.com'
page.fill_in 'Password', with: 'P4ssword'
page.fill_in 'Password confirmation', with: 'P4ssword'
end
scenario "when I sign up with valid info" do
submit.click
expect(page).to have_content I18n.t('devise.registrations.signed_up')
expect(page).to have_content I18n.t('user.sign_out')
end
scenario "when I sign up with invalid info" do
page.fill_in 'Email', with: 'testasdas'
submit.click
expect(page).to have_content 'Email is invalid'
expect(page).to_not have_content I18n.t('devise.registrations.signed_up')
end
end
context 'Log in' do
background do
visit '/'
click_link I18n.t('user.sign_in')
page.fill_in 'Email', with: user.email
end
scenario 'when I sign in with valid details.' do
page.fill_in 'Password', with: 'P4ssword'
submit.click
expect(page).to have_content I18n.t('devise.sessions.signed_in')
expect(page).to have_link I18n.t('user.sign_out')
end
scenario 'when I sign in with an invalid password' do
page.fill_in 'Password', with: 'H4XX0R'
submit.click
expect(page).to_not have_content I18n.t('devise.sessions.signed_in')
end
end
end