* a simple cucumber test - just verifies home page is responsive

This commit is contained in:
Seth Call 2012-12-11 23:32:53 -06:00
parent a3e9dd1422
commit 4973f4ac8f
12 changed files with 29 additions and 137 deletions

View File

@ -69,8 +69,9 @@ end
group :test do
gem 'capybara', '1.1.2'
gem 'cucumber-rails', '1.3.0', :require => false
gem 'headless'
gem 'factory_girl_rails', '4.1.0'
gem 'cucumber-rails', '1.2.1', :require => false
gem 'database_cleaner', '0.7.0'
gem 'guard-spork', '0.3.2'
gem 'spork', '0.9.0'
@ -80,3 +81,5 @@ group :test do
# gem 'growl', '1.0.3'
end

View File

@ -1,10 +0,0 @@
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.string :email
t.timestamps
end
end
end

View File

@ -1,5 +0,0 @@
class AddIndexToUsersEmail < ActiveRecord::Migration
def change
add_index :users, :email, unique: true
end
end

View File

@ -1,5 +0,0 @@
class AddPasswordDigestToUsers < ActiveRecord::Migration
def change
add_column :users, :password_digest, :string
end
end

View File

@ -1,6 +0,0 @@
class AddRememberTokenToUsers < ActiveRecord::Migration
def change
add_column :users, :remember_token, :string
add_index :users, :remember_token
end
end

View File

@ -1,5 +0,0 @@
class AddAdminToUsers < ActiveRecord::Migration
def change
add_column :users, :admin, :boolean, default: false
end
end

View File

@ -1,11 +0,0 @@
class CreateMicroposts < ActiveRecord::Migration
def change
create_table :microposts do |t|
t.string :content
t.integer :user_id
t.timestamps
end
add_index :microposts, [:user_id, :created_at]
end
end

View File

@ -1,14 +0,0 @@
class CreateRelationships < ActiveRecord::Migration
def change
create_table :relationships do |t|
t.integer :follower_id
t.integer :followed_id
t.timestamps
end
add_index :relationships, :follower_id
add_index :relationships, :followed_id
add_index :relationships, [:follower_id, :followed_id], unique: true
end
end

View File

@ -11,39 +11,6 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120308215846) do
create_table "microposts", :force => true do |t|
t.string "content"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "microposts", ["user_id", "created_at"], :name => "index_microposts_on_user_id_and_created_at"
create_table "relationships", :force => true do |t|
t.integer "follower_id"
t.integer "followed_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "relationships", ["followed_id"], :name => "index_relationships_on_followed_id"
add_index "relationships", ["follower_id", "followed_id"], :name => "index_relationships_on_follower_id_and_followed_id", :unique => true
add_index "relationships", ["follower_id"], :name => "index_relationships_on_follower_id"
create_table "users", :force => true do |t|
t.string "name"
t.string "email"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "password_digest"
t.string "remember_token"
t.boolean "admin", :default => false
end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
add_index "users", ["remember_token"], :name => "index_users_on_remember_token"
ActiveRecord::Schema.define(:version => 0) do
end

View File

@ -1,13 +0,0 @@
Feature: Signing in
Scenario: Unsuccessful signin
Given a user visits the signin page
When he submits invalid signin information
Then he should see an error message
Scenario: Successful signin
Given a user visits the signin page
And the user has an account
And the user submits valid signin information
Then he should see his profile page
And he should see a signout link

View File

@ -1,31 +0,0 @@
Given /^a user visits the signin page$/ do
visit signin_path
end
When /^he submits invalid signin information$/ do
click_button "Sign in"
end
Then /^he should see an error message$/ do
page.should have_selector('div.alert.alert-error')
end
Given /^the user has an account$/ do
@user = User.create(name: "Example User", email: "user@example.com",
password: "foobar", password_confirmation: "foobar")
end
When /^the user submits valid signin information$/ do
visit signin_path
fill_in "Email", with: @user.email
fill_in "Password", with: @user.password
click_button "Sign in"
end
Then /^he should see his profile page$/ do
page.should have_selector('title', text: @user.name)
end
Then /^he should see a signout link$/ do
page.should have_link('Sign out', href: signout_path)
end

View File

@ -4,8 +4,14 @@
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
# files.
# SETH: ADDED TO FORCE OUR OWN DB LOADING
require File.expand_path('../before_cucumber', __FILE__)
BeforeCucumber.new
require 'cucumber/rails'
# Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In
# order to ease the transition to Capybara we set the default here. If you'd
# prefer to use XPath just remove this line and adjust any selectors in your
@ -32,7 +38,9 @@ ActionController::Base.allow_rescue = false
# Remove/comment out the lines below if your app doesn't have a database.
# For some databases (like MongoDB and CouchDB) you may need to use :truncation instead.
begin
DatabaseCleaner.strategy = :transaction
#DatabaseCleaner.strategy = :transaction
#DatabaseCleaner.strategy = :truncation, {:except => %w[instruments genres] }
#DatabaseCleaner.clean_with(:truncation, {:except => %w[instruments genres] })
rescue NameError
raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end
@ -41,7 +49,10 @@ end
# See the DatabaseCleaner documentation for details. Example:
#
# Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do
# DatabaseCleaner.strategy = :truncation, {:except => %w[widgets]}
# # { :except => [:widgets] } may not do what you expect here
# # as tCucumber::Rails::Database.javascript_strategy overrides
# # this setting.
# DatabaseCleaner.strategy = :truncation
# end
#
# Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do
@ -49,8 +60,19 @@ end
# end
#
Capybara.javascript_driver = :selenium
# if on jenkins, run headless
unless ENV["HEADLESS"].nil?
require 'headless'
headless = Headless.new
headless.start
end
# Possible values are :truncation and :transaction
# The :transaction strategy is faster, but might give you threading problems.
# See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature
Cucumber::Rails::Database.javascript_strategy = :truncation