Skip to content

Commit ca24bc8

Browse files
committed
Add Cucumber features
1 parent 2b510f4 commit ca24bc8

File tree

9 files changed

+205
-1
lines changed

9 files changed

+205
-1
lines changed

Diff for: Gemfile

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ end
2525
group :test do
2626
gem 'capybara', '1.1.2'
2727
gem 'factory_girl_rails', '1.4.0'
28+
gem 'cucumber-rails', '1.2.1', require: false
29+
gem 'database_cleaner', '0.7.0'
2830
# gem 'rb-fsevent', '0.4.3.1', :require => false
2931
# gem 'growl', '1.0.3'
3032
# gem 'guard-spork', '0.3.2'

Diff for: Gemfile.lock

+16
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ GEM
5151
coffee-script-source
5252
execjs
5353
coffee-script-source (1.3.1)
54+
cucumber (1.1.9)
55+
builder (>= 2.1.2)
56+
diff-lcs (>= 1.1.2)
57+
gherkin (~> 2.9.0)
58+
json (>= 1.4.6)
59+
term-ansicolor (>= 1.0.6)
60+
cucumber-rails (1.2.1)
61+
capybara (>= 1.1.2)
62+
cucumber (>= 1.1.3)
63+
nokogiri (>= 1.5.0)
64+
database_cleaner (0.7.0)
5465
diff-lcs (1.1.3)
5566
erubis (2.7.0)
5667
execjs (1.3.0)
@@ -63,6 +74,8 @@ GEM
6374
faker (1.0.1)
6475
i18n (~> 0.4)
6576
ffi (1.0.11)
77+
gherkin (2.9.3)
78+
json (>= 1.4.6)
6679
guard (1.0.1)
6780
ffi (>= 0.5.0)
6881
thor (~> 0.14.6)
@@ -141,6 +154,7 @@ GEM
141154
rack (~> 1.0)
142155
tilt (~> 1.1, != 1.3.0)
143156
sqlite3 (1.3.5)
157+
term-ansicolor (1.0.7)
144158
thor (0.14.6)
145159
tilt (1.3.3)
146160
treetop (1.4.10)
@@ -163,6 +177,8 @@ DEPENDENCIES
163177
bootstrap-will_paginate (= 0.0.5)
164178
capybara (= 1.1.2)
165179
coffee-rails (= 3.2.2)
180+
cucumber-rails (= 1.2.1)
181+
database_cleaner (= 0.7.0)
166182
factory_girl_rails (= 1.4.0)
167183
faker (= 1.0.1)
168184
guard-rspec (= 0.5.5)

Diff for: config/cucumber.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<%
2+
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
3+
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
4+
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
5+
%>
6+
default: <%= std_opts %> features
7+
wip: --tags @wip:3 --wip features
8+
rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip

Diff for: config/database.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ development:
1212
# Warning: The database defined as "test" will be erased and
1313
# re-generated from your development database when you run "rake".
1414
# Do not set this db to the same as development or production.
15-
test:
15+
test: &test
1616
adapter: sqlite3
1717
database: db/test.sqlite3
1818
pool: 5
@@ -23,3 +23,6 @@ production:
2323
database: db/production.sqlite3
2424
pool: 5
2525
timeout: 5000
26+
27+
cucumber:
28+
<<: *test

Diff for: features/signing_in.feature

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Feature: Signing in
2+
3+
Scenario: Unsuccessful signin
4+
Given a user visits the signin page
5+
When he submits invalid signin information
6+
Then he should see an error message
7+
8+
Scenario: Successful signin
9+
Given a user visits the signin page
10+
And the user has an account
11+
And the user submits valid signin information
12+
Then he should see his profile page
13+
And he should see a signout link

Diff for: features/step_definitions/authentication_steps.rb

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Given /^a user visits the signin page$/ do
2+
visit signin_path
3+
end
4+
5+
When /^he submits invalid signin information$/ do
6+
click_button "Sign in"
7+
end
8+
9+
Then /^he should see an error message$/ do
10+
page.should have_selector('div.alert.alert-error')
11+
end
12+
13+
Given /^the user has an account$/ do
14+
@user = User.create(name: "Example User", email: "[email protected]",
15+
password: "foobar", password_confirmation: "foobar")
16+
end
17+
18+
When /^the user submits valid signin information$/ do
19+
visit signin_path
20+
fill_in "Email", with: @user.email
21+
fill_in "Password", with: @user.password
22+
click_button "Sign in"
23+
end
24+
25+
Then /^he should see his profile page$/ do
26+
page.should have_selector('title', text: @user.name)
27+
end
28+
29+
Then /^he should see a signout link$/ do
30+
page.should have_link('Sign out', href: signout_path)
31+
end

Diff for: features/support/env.rb

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
2+
# It is recommended to regenerate this file in the future when you upgrade to a
3+
# newer version of cucumber-rails. Consider adding your own code to a new file
4+
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
5+
# files.
6+
7+
require 'cucumber/rails'
8+
9+
# Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In
10+
# order to ease the transition to Capybara we set the default here. If you'd
11+
# prefer to use XPath just remove this line and adjust any selectors in your
12+
# steps to use the XPath syntax.
13+
Capybara.default_selector = :css
14+
15+
# By default, any exception happening in your Rails application will bubble up
16+
# to Cucumber so that your scenario will fail. This is a different from how
17+
# your application behaves in the production environment, where an error page will
18+
# be rendered instead.
19+
#
20+
# Sometimes we want to override this default behaviour and allow Rails to rescue
21+
# exceptions and display an error page (just like when the app is running in production).
22+
# Typical scenarios where you want to do this is when you test your error pages.
23+
# There are two ways to allow Rails to rescue exceptions:
24+
#
25+
# 1) Tag your scenario (or feature) with @allow-rescue
26+
#
27+
# 2) Set the value below to true. Beware that doing this globally is not
28+
# recommended as it will mask a lot of errors for you!
29+
#
30+
ActionController::Base.allow_rescue = false
31+
32+
# Remove/comment out the lines below if your app doesn't have a database.
33+
# For some databases (like MongoDB and CouchDB) you may need to use :truncation instead.
34+
begin
35+
DatabaseCleaner.strategy = :transaction
36+
rescue NameError
37+
raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
38+
end
39+
40+
# You may also want to configure DatabaseCleaner to use different strategies for certain features and scenarios.
41+
# See the DatabaseCleaner documentation for details. Example:
42+
#
43+
# Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do
44+
# DatabaseCleaner.strategy = :truncation, {:except => %w[widgets]}
45+
# end
46+
#
47+
# Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do
48+
# DatabaseCleaner.strategy = :transaction
49+
# end
50+
#
51+
52+
# Possible values are :truncation and :transaction
53+
# The :transaction strategy is faster, but might give you threading problems.
54+
# See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature
55+
Cucumber::Rails::Database.javascript_strategy = :truncation
56+

Diff for: lib/tasks/cucumber.rake

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
2+
# It is recommended to regenerate this file in the future when you upgrade to a
3+
# newer version of cucumber-rails. Consider adding your own code to a new file
4+
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
5+
# files.
6+
7+
8+
unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks
9+
10+
vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
11+
$LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil?
12+
13+
begin
14+
require 'cucumber/rake/task'
15+
16+
namespace :cucumber do
17+
Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t|
18+
t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
19+
t.fork = true # You may get faster startup if you set this to false
20+
t.profile = 'default'
21+
end
22+
23+
Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t|
24+
t.binary = vendored_cucumber_bin
25+
t.fork = true # You may get faster startup if you set this to false
26+
t.profile = 'wip'
27+
end
28+
29+
Cucumber::Rake::Task.new({:rerun => 'db:test:prepare'}, 'Record failing features and run only them if any exist') do |t|
30+
t.binary = vendored_cucumber_bin
31+
t.fork = true # You may get faster startup if you set this to false
32+
t.profile = 'rerun'
33+
end
34+
35+
desc 'Run all features'
36+
task :all => [:ok, :wip]
37+
38+
task :statsetup do
39+
require 'rails/code_statistics'
40+
::STATS_DIRECTORIES << %w(Cucumber\ features features) if File.exist?('features')
41+
::CodeStatistics::TEST_TYPES << "Cucumber features" if File.exist?('features')
42+
end
43+
end
44+
desc 'Alias for cucumber:ok'
45+
task :cucumber => 'cucumber:ok'
46+
47+
task :default => :cucumber
48+
49+
task :features => :cucumber do
50+
STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***"
51+
end
52+
53+
# In case we don't have ActiveRecord, append a no-op task that we can depend upon.
54+
task 'db:test:prepare' do
55+
end
56+
57+
task :stats => 'cucumber:statsetup'
58+
rescue LoadError
59+
desc 'cucumber rake task not available (cucumber not installed)'
60+
task :cucumber do
61+
abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
62+
end
63+
end
64+
65+
end

Diff for: script/cucumber

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env ruby
2+
3+
vendored_cucumber_bin = Dir["#{File.dirname(__FILE__)}/../vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
4+
if vendored_cucumber_bin
5+
load File.expand_path(vendored_cucumber_bin)
6+
else
7+
require 'rubygems' unless ENV['NO_RUBYGEMS']
8+
require 'cucumber'
9+
load Cucumber::BINARY
10+
end

0 commit comments

Comments
 (0)