Commit 1a7914112130fe67bf8fbbad953d2ace9882a67a

Authored by Rafael Manzo
1 parent 03fa53b5

Cucumber added for feature tests

Shoulda matchers added to make easy to write lots of tests
@@ -22,11 +22,20 @@ end @@ -22,11 +22,20 @@ end
22 22
23 gem 'jquery-rails' 23 gem 'jquery-rails'
24 24
  25 +group :test do
  26 + gem "shoulda-matchers"
  27 +end
  28 +
25 group :development, :test do 29 group :development, :test do
26 gem 'rspec-rails' 30 gem 'rspec-rails'
27 gem 'factory_girl_rails' 31 gem 'factory_girl_rails'
28 end 32 end
29 33
  34 +group :cucumber do
  35 + gem 'cucumber-rails'
  36 + gem 'database_cleaner'
  37 +end
  38 +
30 # To use ActiveModel has_secure_password 39 # To use ActiveModel has_secure_password
31 # gem 'bcrypt-ruby', '~> 3.0.0' 40 # gem 'bcrypt-ruby', '~> 3.0.0'
32 41
@@ -30,6 +30,12 @@ GEM @@ -30,6 +30,12 @@ GEM
30 multi_json (~> 1.0) 30 multi_json (~> 1.0)
31 arel (3.0.2) 31 arel (3.0.2)
32 builder (3.0.4) 32 builder (3.0.4)
  33 + capybara (2.1.0)
  34 + mime-types (>= 1.16)
  35 + nokogiri (>= 1.3.3)
  36 + rack (>= 1.0.0)
  37 + rack-test (>= 0.5.4)
  38 + xpath (~> 2.0)
33 coffee-rails (3.2.2) 39 coffee-rails (3.2.2)
34 coffee-script (>= 2.2.0) 40 coffee-script (>= 2.2.0)
35 railties (~> 3.2.0) 41 railties (~> 3.2.0)
@@ -37,6 +43,17 @@ GEM @@ -37,6 +43,17 @@ GEM
37 coffee-script-source 43 coffee-script-source
38 execjs 44 execjs
39 coffee-script-source (1.6.2) 45 coffee-script-source (1.6.2)
  46 + cucumber (1.3.1)
  47 + builder (>= 2.1.2)
  48 + diff-lcs (>= 1.1.3)
  49 + gherkin (~> 2.12.0)
  50 + multi_json (~> 1.3)
  51 + cucumber-rails (1.3.1)
  52 + capybara (>= 1.1.2)
  53 + cucumber (>= 1.2.0)
  54 + nokogiri (>= 1.5.0)
  55 + rails (~> 3.0)
  56 + database_cleaner (0.9.1)
40 diff-lcs (1.2.4) 57 diff-lcs (1.2.4)
41 erubis (2.7.0) 58 erubis (2.7.0)
42 execjs (1.4.0) 59 execjs (1.4.0)
@@ -46,6 +63,8 @@ GEM @@ -46,6 +63,8 @@ GEM
46 factory_girl_rails (4.2.1) 63 factory_girl_rails (4.2.1)
47 factory_girl (~> 4.2.0) 64 factory_girl (~> 4.2.0)
48 railties (>= 3.0.0) 65 railties (>= 3.0.0)
  66 + gherkin (2.12.0)
  67 + multi_json (~> 1.3)
49 hike (1.2.2) 68 hike (1.2.2)
50 i18n (0.6.1) 69 i18n (0.6.1)
51 journey (1.0.4) 70 journey (1.0.4)
@@ -60,6 +79,7 @@ GEM @@ -60,6 +79,7 @@ GEM
60 treetop (~> 1.4.8) 79 treetop (~> 1.4.8)
61 mime-types (1.23) 80 mime-types (1.23)
62 multi_json (1.7.3) 81 multi_json (1.7.3)
  82 + nokogiri (1.5.9)
63 polyglot (0.3.3) 83 polyglot (0.3.3)
64 rack (1.4.5) 84 rack (1.4.5)
65 rack-cache (1.2) 85 rack-cache (1.2)
@@ -103,6 +123,8 @@ GEM @@ -103,6 +123,8 @@ GEM
103 railties (~> 3.2.0) 123 railties (~> 3.2.0)
104 sass (>= 3.1.10) 124 sass (>= 3.1.10)
105 tilt (~> 1.3) 125 tilt (~> 1.3)
  126 + shoulda-matchers (2.1.0)
  127 + activesupport (>= 3.0.0)
106 sprockets (2.2.2) 128 sprockets (2.2.2)
107 hike (~> 1.2) 129 hike (~> 1.2)
108 multi_json (~> 1.0) 130 multi_json (~> 1.0)
@@ -121,17 +143,22 @@ GEM @@ -121,17 +143,22 @@ GEM
121 uglifier (2.0.1) 143 uglifier (2.0.1)
122 execjs (>= 0.3.0) 144 execjs (>= 0.3.0)
123 multi_json (~> 1.0, >= 1.0.2) 145 multi_json (~> 1.0, >= 1.0.2)
  146 + xpath (2.0.0)
  147 + nokogiri (~> 1.3)
124 148
125 PLATFORMS 149 PLATFORMS
126 ruby 150 ruby
127 151
128 DEPENDENCIES 152 DEPENDENCIES
129 coffee-rails (~> 3.2.1) 153 coffee-rails (~> 3.2.1)
  154 + cucumber-rails
  155 + database_cleaner
130 factory_girl_rails 156 factory_girl_rails
131 jquery-rails 157 jquery-rails
132 rails (= 3.2.13) 158 rails (= 3.2.13)
133 rspec-rails 159 rspec-rails
134 sass-rails (~> 3.2.3) 160 sass-rails (~> 3.2.3)
  161 + shoulda-matchers
135 sqlite3 162 sqlite3
136 therubyracer 163 therubyracer
137 uglifier (>= 1.0.3) 164 uglifier (>= 1.0.3)
config/cucumber.yml 0 → 100644
@@ -0,0 +1,8 @@ @@ -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
config/database.yml
@@ -12,7 +12,7 @@ development: @@ -12,7 +12,7 @@ development:
12 # Warning: The database defined as "test" will be erased and 12 # Warning: The database defined as "test" will be erased and
13 # re-generated from your development database when you run "rake". 13 # re-generated from your development database when you run "rake".
14 # Do not set this db to the same as development or production. 14 # Do not set this db to the same as development or production.
15 -test: 15 +test: &test
16 adapter: sqlite3 16 adapter: sqlite3
17 database: db/test.sqlite3 17 database: db/test.sqlite3
18 pool: 5 18 pool: 5
@@ -23,3 +23,6 @@ production: @@ -23,3 +23,6 @@ production:
23 database: db/production.sqlite3 23 database: db/production.sqlite3
24 pool: 5 24 pool: 5
25 timeout: 5000 25 timeout: 5000
  26 +
  27 +cucumber:
  28 + <<: *test
26 \ No newline at end of file 29 \ No newline at end of file
features/support/env.rb 0 → 100644
@@ -0,0 +1,58 @@ @@ -0,0 +1,58 @@
  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 CSS3 selectors rather than XPath.
  10 +# If you'd prefer to use XPath, just uncomment this line and adjust any
  11 +# selectors in your step definitions to use the XPath syntax.
  12 +# Capybara.default_selector = :xpath
  13 +
  14 +# By default, any exception happening in your Rails application will bubble up
  15 +# to Cucumber so that your scenario will fail. This is a different from how
  16 +# your application behaves in the production environment, where an error page will
  17 +# be rendered instead.
  18 +#
  19 +# Sometimes we want to override this default behaviour and allow Rails to rescue
  20 +# exceptions and display an error page (just like when the app is running in production).
  21 +# Typical scenarios where you want to do this is when you test your error pages.
  22 +# There are two ways to allow Rails to rescue exceptions:
  23 +#
  24 +# 1) Tag your scenario (or feature) with @allow-rescue
  25 +#
  26 +# 2) Set the value below to true. Beware that doing this globally is not
  27 +# recommended as it will mask a lot of errors for you!
  28 +#
  29 +ActionController::Base.allow_rescue = false
  30 +
  31 +# Remove/comment out the lines below if your app doesn't have a database.
  32 +# For some databases (like MongoDB and CouchDB) you may need to use :truncation instead.
  33 +begin
  34 + DatabaseCleaner.strategy = :transaction
  35 +rescue NameError
  36 + raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
  37 +end
  38 +
  39 +# You may also want to configure DatabaseCleaner to use different strategies for certain features and scenarios.
  40 +# See the DatabaseCleaner documentation for details. Example:
  41 +#
  42 +# Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do
  43 +# # { :except => [:widgets] } may not do what you expect here
  44 +# # as Cucumber::Rails::Database.javascript_strategy overrides
  45 +# # this setting.
  46 +# DatabaseCleaner.strategy = :truncation
  47 +# end
  48 +#
  49 +# Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do
  50 +# DatabaseCleaner.strategy = :transaction
  51 +# end
  52 +#
  53 +
  54 +# Possible values are :truncation and :transaction
  55 +# The :transaction strategy is faster, but might give you threading problems.
  56 +# See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature
  57 +Cucumber::Rails::Database.javascript_strategy = :truncation
  58 +
lib/tasks/cucumber.rake 0 → 100644
@@ -0,0 +1,65 @@ @@ -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 => '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 => '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 => '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 the generic Rails test:prepare hook, append a no-op task that we can depend upon.
  54 + task '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
script/cucumber 0 → 100755
@@ -0,0 +1,10 @@ @@ -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