There are three scenarios only for when the sign up validations fail, so is there a better way of representing them rather than having 4 scenarios? I don't want to create a model folder so please don't suggest that.
Is there a better way of representing this RSpec code on Rails using Capybara?
feature 'Login' do
before do
FactoryGirl.create(:user)
end
scenario "success login", js: true do
# set_speed(:slow)
visit root_path
click_link 'Login'
fill_in 'email', :with => '[email protected]'
fill_in 'password', :with => 'password'
click_button 'Login'
expect(page).to have_content('Logged in successfully')
end
scenario "failed login", js: true do
# set_speed(:slow)
visit root_path
click_link 'Login'
fill_in 'email', :with => '[email protected]'
fill_in 'password', :with => 'something failed'
click_button 'Login'
expect(page).to have_content('Invalid login/password combination')
end
end
feature "Sign Up" do
scenario "success sign up", js:true do
visit root_path
click_link 'Login'
click_link 'Sign Up'
fill_in 'user[email]', :with=>'[email protected]'
fill_in 'user[password]', :with=> 'password'
fill_in 'user[password_confirmation]', :with=> 'password'
click_button 'Create User'
expect(page).to have_content('User successfully added.')
end
scenario "failed sign up/Wrong email format", js:true do
visit root_path
click_link 'Login'
click_link 'Sign Up'
fill_in 'user[email]', :with=>'signup.example.com'
fill_in 'user[password]', :with=> 'password'
fill_in 'user[password_confirmation]', :with=> 'password'
click_button 'Create User'
expect(page).to have_content('is invalid')
end
scenario "failed sign up/Short Email address", js:true do
visit root_path
click_link 'Login'
click_link 'Sign Up'
fill_in 'user[email]', :with=>'sign'
fill_in 'user[password]', :with=> 'password'
fill_in 'user[password_confirmation]', :with=> 'password'
click_button 'Create User'
expect(page).to have_content('is too short (minimum is 5 characters)')
end
scenario "failed sign up/Long Email address", js:true do
visit root_path
click_link 'Login'
click_link 'Sign Up'
fill_in 'user[email]', :with=>'[email protected]'
fill_in 'user[password]', :with=> 'password'
fill_in 'user[password_confirmation]', :with=> 'password'
click_button 'Create User'
expect(page).to have_content('is too long (maximum is 50 characters)')
end
end