Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Setup cucumber

  • Loading branch information...
commit ef4e83787546d9c0495266460310af90c50e500e 1 parent 7da2795
Matthew Mongeau authored April 03, 2012
2  Gemfile
@@ -11,6 +11,8 @@ gem 'sqlite3'
11 11
 group :test do
12 12
   gem 'rspec-rails'
13 13
   gem 'factory_girl_rails'
  14
+  gem 'cucumber-rails'
  15
+  gem 'database_cleaner'
14 16
 end
15 17
 
16 18
 
36  Gemfile.lock
@@ -30,6 +30,15 @@ GEM
30 30
       multi_json (~> 1.0)
31 31
     arel (3.0.2)
32 32
     builder (3.0.0)
  33
+    capybara (1.1.2)
  34
+      mime-types (>= 1.16)
  35
+      nokogiri (>= 1.3.3)
  36
+      rack (>= 1.0.0)
  37
+      rack-test (>= 0.5.4)
  38
+      selenium-webdriver (~> 2.0)
  39
+      xpath (~> 0.1.4)
  40
+    childprocess (0.3.1)
  41
+      ffi (~> 1.0.6)
33 42
     clearance (0.12.0)
34 43
       diesel (~> 0.1.4)
35 44
       rails (>= 3.0)
@@ -40,6 +49,17 @@ GEM
40 49
       coffee-script-source
41 50
       execjs
42 51
     coffee-script-source (1.2.0)
  52
+    cucumber (1.1.4)
  53
+      builder (>= 2.1.2)
  54
+      diff-lcs (>= 1.1.2)
  55
+      gherkin (~> 2.7.1)
  56
+      json (>= 1.4.6)
  57
+      term-ansicolor (>= 1.0.6)
  58
+    cucumber-rails (1.2.1)
  59
+      capybara (>= 1.1.2)
  60
+      cucumber (>= 1.1.3)
  61
+      nokogiri (>= 1.5.0)
  62
+    database_cleaner (0.7.1)
43 63
     diesel (0.1.5)
44 64
       railties
45 65
     diff-lcs (1.1.3)
@@ -51,6 +71,9 @@ GEM
51 71
     factory_girl_rails (3.0.0)
52 72
       factory_girl (~> 3.0.0)
53 73
       railties (>= 3.0.0)
  74
+    ffi (1.0.11)
  75
+    gherkin (2.7.6)
  76
+      json (>= 1.4.6)
54 77
     hike (1.2.1)
55 78
     i18n (0.6.0)
56 79
     journey (1.0.3)
@@ -58,12 +81,14 @@ GEM
58 81
       railties (>= 3.2.0, < 5.0)
59 82
       thor (~> 0.14)
60 83
     json (1.6.6)
  84
+    json_pure (1.6.5)
61 85
     mail (2.4.4)
62 86
       i18n (>= 0.4.0)
63 87
       mime-types (~> 1.16)
64 88
       treetop (~> 1.4.8)
65 89
     mime-types (1.18)
66 90
     multi_json (1.2.0)
  91
+    nokogiri (1.5.0)
67 92
     polyglot (0.3.3)
68 93
     rack (1.4.1)
69 94
     rack-cache (1.2)
@@ -103,16 +128,23 @@ GEM
103 128
       activesupport (>= 3.0)
104 129
       railties (>= 3.0)
105 130
       rspec (~> 2.8.0)
  131
+    rubyzip (0.9.6.1)
106 132
     sass (3.1.15)
107 133
     sass-rails (3.2.5)
108 134
       railties (~> 3.2.0)
109 135
       sass (>= 3.1.10)
110 136
       tilt (~> 1.3)
  137
+    selenium-webdriver (2.13.0)
  138
+      childprocess (>= 0.2.1)
  139
+      ffi (~> 1.0.9)
  140
+      json_pure
  141
+      rubyzip
111 142
     sprockets (2.1.2)
112 143
       hike (~> 1.2)
113 144
       rack (~> 1.0)
114 145
       tilt (~> 1.1, != 1.3.0)
115 146
     sqlite3 (1.3.5)
  147
+    term-ansicolor (1.0.7)
116 148
     thor (0.14.6)
117 149
     tilt (1.3.3)
118 150
     treetop (1.4.10)
@@ -122,6 +154,8 @@ GEM
122 154
     uglifier (1.2.4)
123 155
       execjs (>= 0.3.0)
124 156
       multi_json (>= 1.0.2)
  157
+    xpath (0.1.4)
  158
+      nokogiri (~> 1.3)
125 159
 
126 160
 PLATFORMS
127 161
   ruby
@@ -129,6 +163,8 @@ PLATFORMS
129 163
 DEPENDENCIES
130 164
   clearance
131 165
   coffee-rails (~> 3.2.1)
  166
+  cucumber-rails
  167
+  database_cleaner
132 168
   factory_girl_rails
133 169
   jquery-rails
134 170
   rails (= 3.2.2)
8  config/cucumber.yml
... ...
@@ -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
5  config/database.yml
@@ -12,7 +12,7 @@ development:
12 12
 # Warning: The database defined as "test" will be erased and
13 13
 # re-generated from your development database when you run "rake".
14 14
 # Do not set this db to the same as development or production.
15  
-test:
  15
+test: &test
16 16
   adapter: sqlite3
17 17
   database: db/test.sqlite3
18 18
   pool: 5
@@ -23,3 +23,6 @@ production:
23 23
   database: db/production.sqlite3
24 24
   pool: 5
25 25
   timeout: 5000
  26
+
  27
+cucumber:
  28
+  <<: *test
56  features/support/env.rb
... ...
@@ -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
+
1  features/support/factory_girl_support.rb
... ...
@@ -0,0 +1 @@
  1
+require 'factory_girl/step_definitions'
22  features/user_views_dashboard.feature
... ...
@@ -0,0 +1,22 @@
  1
+Feature: User views dashboard
  2
+  As a user
  3
+  In order to get updates from followed users
  4
+  I want to see shouts on my dashboard
  5
+
  6
+  Scenario: User can see followed user shouts on dashboard
  7
+    Given the following users exist:
  8
+      | email                     |
  9
+      | follower@example.com      |
  10
+      | followed_user@example.com |
  11
+    And the following shouts exist:
  12
+      | body            | user                             | created at |
  13
+      | Hello Wombat    | email: followed_user@example.com | 2011-5-3   |
  14
+      | Hello Wallaby   | email: follower@example.com      | 2011-1-3   |
  15
+      | Hello Wobbegong | email: follower@example.com      | 2011-10-3  |
  16
+    And "follower@example.com" is following "followed_user@example.com"
  17
+    And I am signed in as "follower@example.com"
  18
+    When I am on the dashboard
  19
+    Then I can see the following timeline:
  20
+      | Hello Wobbegong |
  21
+      | Hello Wombat    |
  22
+      | Hello Wallaby   |
65  lib/tasks/cucumber.rake
... ...
@@ -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
10  script/cucumber
... ...
@@ -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 notes on commit ef4e837

Please sign in to comment.
Something went wrong with that request. Please try again.