Skip to content

Commit

Permalink
Making sign_up feature DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaschabariberi committed Dec 4, 2019
1 parent c027ad6 commit 01da833
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 62 deletions.
32 changes: 26 additions & 6 deletions src/app/features/001_sign_up.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,48 @@ As a user
I want to create an account
So that I can use the application

Scenario: User creates a new account filling all fields filled with valid data
Scenario: User creates a new account filling all fields with valid data
Given I am on the create account page
When I fill the user registration form
When I attach a profile picture
And I click the Cadastrar button
Then I should see the welcome page

Scenario: User creates a new account successfully checking the checkbox to see near colleges
Scenario: User creates a new account successfully and check the option to see near colleges
Given I am on the create account page
When I fill the user registration form
When I attach a profile picture
And I check the checkbox to see the page's wizard
And I click the Cadastrar button
Then I should see the page's wizard

Scenario: User try to create a new account with invalid data
Scenario Outline: User try to create a new account with invalid data
Given I am on the create account page
When I fill the user registration form with invalid data
When I fill the user registration form
When I fill in "<form field>" with "<value>"
When I attach a profile picture
And I click the Cadastrar button
Then I should see the red failed toast

Scenario: User try to create a new account with existing user id
Examples:
| form field | value |
| user_email | emailinvalido.com |
| user_password_confirmation | senha errada |

Scenario: User try to create a new account with invalid password format
Given I am on the create account page
When I fill the user registration form
When I fill in "user_password" with "cinco"
When I fill in "user_password_confirmation" with "cinco"
When I attach a profile picture
And I click the Cadastrar button
Then I should see the red failed toast

Scenario: User try to create a new account with existing user nickname
Given There is an unregistered user
And I am on the create account page
When I fill the user registration form with existing user id
When I fill the user registration form
When I fill in "user_nickname" with "teste002.user"
When I attach a profile picture
And I click the Cadastrar button
Then I should see the red failed toast
87 changes: 31 additions & 56 deletions src/app/features/step_definitions/sign_up_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,51 @@
visit new_user_path
end

When(/^I fill the user registration form$/) do
@user = FactoryBot.build(:user)
When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
fill_in(field.gsub(' ', '_'), :with => value)
end

When /^I fill the user registration form$/ do
steps %Q{
When I fill in "user_first_name" with "teste001"
When I fill in "user_last_name" with "user"
When I fill in "user_nickname" with "teste001.user"
When I fill in "user_birth_date" with "1998-10-25"
When I fill in "user_email" with "[email protected]"
When I fill in "user_password" with "teste001user"
When I fill in "user_password_confirmation" with "teste001user"
When I fill in "user_country" with "Brasil"
When I fill in "user_state" with "SP"
When I fill in "user_city" with "São Paulo"
}
end

fill_in "user[email]", with: @user.email
fill_in "user[nickname]", with: @user.nickname
fill_in "user[first_name]", with: @user.first_name
fill_in "user[last_name]", with: @user.last_name
fill_in "user[birth_date]", with: @user.birth_date
fill_in "user[password]", with: @user.password
fill_in "user[password_confirmation]", with: @user.password_confirmation
fill_in "user[country]", with: @user.country
fill_in "user[state]", with: @user.state
fill_in "user[city]", with: @user.city
When /^I attach a profile picture$/ do
attach_file("user[profile_picture]", 'features/upload-files/icon-384x384.png')
end

When /^I click the (.*) button$/ do |button_name|
click_button button_name
end

When /^I check the checkbox to see the page's wizard$/ do
find(:css, "#checkbox").set(true)
end

Then(/^I should see the welcome page$/) do
expect(page).to have_xpath('.//div[@class="alert alert-success alert-dismissible"]')
expect(page).to have_xpath('.//form[@action="/users/new"]')
expect(page).to have_xpath('.//form[@action="/entrar"]')
end

Then /^I should see the page's wizard$/ do
expect(page).to have_xpath('.//div[@class="jumbotron"]/h2', text: 'Páginas de instituições próximas')
end

Then (/^I should see the red failed toast$/) do
expect(page).to have_xpath('.//div[@class="alert alert-danger"]')
end

# - - -

Given(/^I have an account$/) do
Expand Down Expand Up @@ -69,48 +88,4 @@
u.save

@user = User.find_by(nickname: "teste003.user")
end

When /^I check the checkbox to see the page's wizard$/ do
find(:css, "#checkbox").set(true)
end

Then /^I should see the page's wizard$/ do
expect(page).to have_xpath('.//div[@class="jumbotron"]/h2', text: 'Páginas de instituições próximas')
end

When (/^I fill the user registration form with invalid data$/) do
@user = FactoryBot.build(:user)

fill_in "user[email]", with: @user.email
fill_in "user[nickname]", with: @user.nickname
fill_in "user[first_name]", with: @user.first_name
fill_in "user[last_name]", with: @user.last_name
fill_in "user[birth_date]", with: @user.birth_date
fill_in "user[password]", with: @user.password
fill_in "user[password_confirmation]", with: 'senha errada'
fill_in "user[country]", with: @user.country
fill_in "user[state]", with: @user.state
fill_in "user[city]", with: @user.city
attach_file("user[profile_picture]", 'features/upload-files/icon-384x384.png')
end

When (/^I fill the user registration form with existing user id$/) do
@user = FactoryBot.build(:user)

fill_in "user[email]", with: @user.email
fill_in "user[nickname]", with: 'teste002.user'
fill_in "user[first_name]", with: @user.first_name
fill_in "user[last_name]", with: @user.last_name
fill_in "user[birth_date]", with: @user.birth_date
fill_in "user[password]", with: @user.password
fill_in "user[password_confirmation]", with: @user.password_confirmation
fill_in "user[country]", with: @user.country
fill_in "user[state]", with: @user.state
fill_in "user[city]", with: @user.city
attach_file("user[profile_picture]", 'features/upload-files/icon-384x384.png')
end

Then (/^I should see the red failed toast$/) do
expect(page).to have_xpath('.//div[@class="alert alert-danger"]')
end

0 comments on commit 01da833

Please sign in to comment.