Created
December 15, 2019 07:49
-
-
Save tomrlh/934d51aedff231fc13d1860e2b6870ec to your computer and use it in GitHub Desktop.
Filling forms with Rspec + Capybara
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe 'Forms' do | |
# common function | |
def login( | |
url, user, password, user_field, password_field, | |
submit_button, message_field, expected_message | |
) | |
visit url | |
fill_in user_field, with: user | |
fill_in password_field, with: password | |
click_button submit_button | |
expect(find(message_field).visible?).to be true | |
expect(find(message_field)).to have_content expected_message | |
end | |
# global variables | |
$url = 'http://training-wheels-protocol.herokuapp.com/login' | |
$user = 'stark' | |
$password = 'jarvis!' | |
$wrong_user = 'wrong_user' | |
$wrong_password = 'wrong_password' | |
$user_field = 'userId' | |
$password_field = 'password' | |
$submit_button = 'Login' | |
$message_field = '#flash' | |
it 'successful login' do | |
# @ for local variables | |
@expected_message = 'Olá, Tony Stark. Você acessou a área logada!' | |
login( | |
$url, $user, $password, $user_field, $password_field, | |
$submit_button, $message_field, @expected_message | |
) | |
end | |
it 'wrong password' do | |
@expected_message = 'Senha é invalida!' | |
login( | |
$url, $user, $wrong_password, $user_field, $password_field, | |
$submit_button, $message_field, @expected_message | |
) | |
end | |
it 'unexistent user' do | |
@expected_message = 'O usuário informado não está cadastrado!' | |
login( | |
$url, $wrong_user, $password, $user_field, $password_field, | |
$submit_button, $message_field, @expected_message | |
) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment