Skip to content

Instantly share code, notes, and snippets.

@Industrial
Created July 10, 2020 16:17
Show Gist options
  • Save Industrial/afd6d8efd95e569c760f2dfbe79c5419 to your computer and use it in GitHub Desktop.
Save Industrial/afd6d8efd95e569c760f2dfbe79c5419 to your computer and use it in GitHub Desktop.
Feature: Login
Logging in and out of the application.
Scenario: Logging in.
Given I have initial data
Given I have opened "/login"
When I log in to the app with login "employee" and password "employee"
Then I should be on the "/venue" page
Scenario: Logging out.
Given I have initial data
Given I have opened "/login"
When I log in to the app with login "employee" and password "employee"
When I navigate to a venue page
When I log out of the app
Then I should be on the "/login" page
# frozen_string_literal: true
Given(/^I have initial data$/) do
company = FactoryBot.create :company
venue = FactoryBot.create :venue, reporter_enabled: true, companyid: company.id
venue1 = FactoryBot.create :venue, reporter_enabled: true, companyid: company.id
employee = FactoryBot.create :employee, { login: 'employee', password: 'employee' }
team = FactoryBot.create :team, company_id: company.id
team.memberships.create employee_id: employee.id
end
Given(/^I have opened "([^\"]*)"$/) do |url|
visit "http://local.somesite:3000#{url}"
page.should have_current_path url
end
And(/^I have a user with login "(.+)" and password "(.+)"$/) do |login, password|
FactoryBot.create :employee, { login: login, password: password }
end
When(/^I log in to the app with login "(.+)" and password "(.+)"$/) do |login, password|
within 'div.login-form' do
fill_in 'login', with: login
fill_in 'password', with: password
click_button 'Log in'
end
# page.should have_current_path '/venue'
end
When(/^I navigate to a venue page$/) do
within first '.venue' do
click_button 'Bekijk locatie'
end
page.should have_current_path '/'
end
When(/^I log out of the app$/) do
page.should have_content 'Meldingen'
find('.employee-info .title a', visible: false).click
end
Then(/^I should see "(.+)"$/) do |value|
expect(page).to have_content value
end
Then(/^I should be on the "(.+)" page$/) do |value|
expect(page).to have_current_path value
end
# frozen_string_literal: true
require 'rspec'
require 'cucumber/rails'
require 'capybara/cuprite'
require 'capybara-screenshot/cucumber'
Capybara.register_driver(:cuprite) do |app|
Capybara::Cuprite::Driver.new app, {
window_size: [1200, 800],
browser_options: {
'no-sandbox': nil
}
}
end
Capybara.javascript_driver = :cuprite
# Capybara.default_max_wait_time = 10
# Automatically save a screenshot when a test fails.
Capybara::Screenshot.autosave_on_failure = true
# TODO: Document this.
ActionController::Base.allow_rescue = false
# TODO: Document this.
Cucumber::Rails::Database.javascript_strategy = :truncation
# TODO: Document this.
begin
DatabaseCleaner.strategy = :transaction
rescue NameError
raise 'You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it.'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment