Skip to content

Instantly share code, notes, and snippets.

@tochman
Last active November 29, 2016 16:39
Show Gist options
  • Save tochman/f106de9545a67e74b0c3ea19c45e1cff to your computer and use it in GitHub Desktop.
Save tochman/f106de9545a67e74b0c3ea19c45e1cff to your computer and use it in GitHub Desktop.
SlowFood Sinatra setup
ENV['RACK_ENV'] = 'test'
require './lib/controller.rb'
require 'capybara'
require 'capybara/cucumber'
require 'rspec'
require 'pry'
require 'database_cleaner'
require 'database_cleaner/cucumber'
Capybara.app = SlowFood
World do
SlowFood.new
end
class SlowFoodWorld
include Capybara::DSL
include RSpec::Expectations
include RSpec::Matchers
end
DatabaseCleaner.strategy = :truncation
Around do |_scenario, block|
DatabaseCleaner.cleaning(&block)
end
Warden.test_mode!
World Warden::Test::Helpers
After { Warden.test_reset! }
When(/^I visit the site$/) do
visit '/'
end
Given(/^I fill in "([^"]*)" with "([^"]*)"$/) do |field, value|
fill_in field, with: value
end
Then(/^I should see "([^"]*)"$/) do |content|
expect(page).to have_content content
end
Then(/^show me the page$/) do
save_and_open_page
end
And(/^I click "([^"]*)"$/) do |link|
click_link_or_button link
end
And(/^I click the "([^"]*)" button$/) do |button|
click_button button
end
Given(/^that there are no users in the system$/) do
User.first.destroy if User.any?
end
And(/^the following users exist$/) do |table|
table.hashes.each do |user_instance|
User.create(user_instance)
end
end
Feature: As a User
In order to access the system
I want to be authenticated by submitting my credentials
Background:
Given that there are no users in the system
And the following users exist
| username | password |
| admin | password |
Scenario: User provides the right combination of user name and password
When I visit the site
And I click "Log In"
Given I fill in "Username" with "admin"
And I fill in "Password" with "password"
And I click the "Log In" button
Then I should see "Logged in as admin"
And I should see "Successfully logged in admin"
Scenario: User inputs the wrong password
When I visit the site
And I click "Log In"
Given I fill in "Username" with "admin"
And I fill in "Password" with "wrong-password"
And I click the "Log In" button
Then I should see "The username and password combination"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment