update for features
+ added flash/message assertions + adjusted urls to be http://google.com for tests for now + added @db-test tags to tests that use db interactions + added a scenario for duplicate URLs being used + added before and after steps to init and clean up db tests + added initialization of a test db for tests instead of interacting with the production databasepull/11/head
parent
8639c785b7
commit
8b2780820c
|
|
@ -7,6 +7,7 @@ Feature: Homepage
|
|||
Scenario: Homepage Loads with a form
|
||||
Given I visit the "/" page
|
||||
Then I should see text "URL Shortener"
|
||||
And I should see the message "Enter a URL"
|
||||
And I should see a form field "url"
|
||||
And I should see a "Submit" button
|
||||
|
||||
|
|
@ -14,9 +15,21 @@ Feature: Homepage
|
|||
Given I visit the "/" page
|
||||
When I click the "Submit" button
|
||||
Then I should be on "/" page
|
||||
And I should see the message "Please enter a valid URL"
|
||||
|
||||
@db-test
|
||||
Scenario: Submitting the form with a correct URL
|
||||
Given I visit the "/" page
|
||||
When I type "http://google.com/" in the "url" field
|
||||
When I type "http://google.com" in the "url" field
|
||||
And I click the "Submit" button
|
||||
Then I should be on "/create" page
|
||||
And I should see the message "Link created"
|
||||
|
||||
@db-test
|
||||
Scenario: Submitting the form with an existing URL
|
||||
Given I visit the "/" page
|
||||
And A link already exists with the url "http://google.com"
|
||||
When I type "http://google.com" in the "url" field
|
||||
And I click the "Submit" button
|
||||
Then I should be on "/create" page
|
||||
And I should see the message "Link exists"
|
||||
|
|
|
|||
|
|
@ -1,9 +1,18 @@
|
|||
# BEFORE
|
||||
Before('@db-test') do
|
||||
@links = Sequel.sqlite("db/#{ENV['DB_NAME']}")[:links]
|
||||
end
|
||||
|
||||
# GIVEN
|
||||
|
||||
Given('I visit the {string} page') do |string|
|
||||
visit string
|
||||
end
|
||||
|
||||
Given('A link already exists with the url {string}') do |string|
|
||||
@links.insert(url: string, code: "aaaaaa")
|
||||
end
|
||||
|
||||
# WHEN
|
||||
|
||||
When('I click the {string} button') do |string|
|
||||
|
|
@ -31,3 +40,13 @@ end
|
|||
Then('I should be on {string} page') do |string|
|
||||
page.should have_current_path string
|
||||
end
|
||||
|
||||
Then('I should see the message {string}') do |message|
|
||||
page.should have_selector '#message', text: message
|
||||
end
|
||||
|
||||
# AFTER
|
||||
|
||||
After('@db-test') do
|
||||
@links.delete
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,11 +1,27 @@
|
|||
require_relative '../../.env'
|
||||
ENV["DB_NAME"] = "test_#{ENV["DB_NAME"]}"
|
||||
require_relative '../../app'
|
||||
require 'rubygems'
|
||||
require 'roda'
|
||||
require 'sequel'
|
||||
require 'capybara'
|
||||
require 'capybara/dsl'
|
||||
require 'rspec'
|
||||
|
||||
# DB initialization
|
||||
Sequel.extension :migration
|
||||
Sequel.sqlite("db/#{ENV['DB_NAME']}") do |db|
|
||||
Sequel::Migrator.apply(db, "db/migrations")
|
||||
end
|
||||
|
||||
# RSpec db setup
|
||||
RSpec.configure do |c|
|
||||
c.around(:each) do |example|
|
||||
DB.transaction(rollback: :always, auto_savepoint: true){example.run}
|
||||
end
|
||||
end
|
||||
|
||||
# attach app to Capybara
|
||||
Capybara.app = App
|
||||
|
||||
include Capybara::DSL
|
||||
|
|
|
|||
Loading…
Reference in New Issue