cucumber-rails 0.3.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. data/.gitignore +1 -0
  2. data/.rspec +1 -0
  3. data/.rvmrc +1 -0
  4. data/Gemfile +2 -0
  5. data/Gemfile.lock +194 -0
  6. data/History.txt +101 -1
  7. data/LICENSE +22 -0
  8. data/README.md +77 -0
  9. data/Rakefile +3 -19
  10. data/config/cucumber.yml +1 -0
  11. data/cucumber-rails.gemspec +37 -101
  12. data/dev_tasks/cucumber.rake +1 -1
  13. data/dev_tasks/rspec.rake +6 -11
  14. data/features/allow_rescue.feature +63 -0
  15. data/features/capybara_javascript_drivers.feature +87 -0
  16. data/features/database_cleaner.feature +44 -0
  17. data/features/emulate_javascript.feature +34 -0
  18. data/features/inspect_query_string.feature +37 -0
  19. data/features/install_cucumber_rails.feature +16 -0
  20. data/features/mongoid.feature +53 -0
  21. data/features/multiple_databases.feature +74 -0
  22. data/features/named_selectors.feature +33 -0
  23. data/features/no_database.feature +70 -0
  24. data/features/pseduo_class_selectors.feature +24 -0
  25. data/features/rerun_profile.feature +38 -0
  26. data/features/rest_api.feature +47 -0
  27. data/features/routing.feature +18 -0
  28. data/features/select_dates.feature +99 -0
  29. data/features/step_definitions/cucumber_rails_steps.rb +80 -6
  30. data/features/support/env.rb +8 -2
  31. data/features/test_unit.feature +43 -0
  32. data/lib/cucumber/rails/capybara/javascript_emulation.rb +83 -0
  33. data/lib/cucumber/rails/capybara/select_dates_and_times.rb +50 -0
  34. data/lib/cucumber/rails/capybara.rb +6 -0
  35. data/lib/cucumber/rails/hooks/active_record.rb +14 -0
  36. data/lib/cucumber/rails/hooks/allow_rescue.rb +8 -0
  37. data/lib/cucumber/rails/hooks/database_cleaner.rb +13 -0
  38. data/lib/cucumber/rails/hooks/mail.rb +5 -0
  39. data/lib/cucumber/rails/hooks.rb +4 -0
  40. data/lib/cucumber/rails/rspec.rb +4 -6
  41. data/lib/cucumber/rails/world.rb +13 -35
  42. data/lib/cucumber/rails.rb +8 -0
  43. data/lib/cucumber/rails3/action_controller.rb +12 -0
  44. data/lib/cucumber/rails3/active_record.rb +8 -0
  45. data/lib/cucumber/rails3/application.rb +17 -0
  46. data/lib/cucumber/rails3.rb +16 -0
  47. data/lib/cucumber/web/tableish.rb +50 -9
  48. data/lib/generators/cucumber/feature/feature_generator.rb +8 -17
  49. data/lib/generators/cucumber/feature/named_arg.rb +2 -0
  50. data/{templates/feature → lib/generators/cucumber/feature/templates}/feature.erb +10 -12
  51. data/{templates/feature → lib/generators/cucumber/feature/templates}/steps.erb +1 -1
  52. data/lib/generators/cucumber/install/USAGE +15 -0
  53. data/lib/generators/cucumber/install/install_generator.rb +88 -0
  54. data/lib/generators/cucumber/install/templates/config/cucumber.yml.erb +8 -0
  55. data/lib/generators/cucumber/install/templates/step_definitions/web_steps.rb.erb +192 -0
  56. data/lib/generators/cucumber/install/templates/step_definitions/web_steps_cs.rb.erb +127 -0
  57. data/lib/generators/cucumber/install/templates/step_definitions/web_steps_da.rb.erb +105 -0
  58. data/lib/generators/cucumber/install/templates/step_definitions/web_steps_de.rb.erb +127 -0
  59. data/lib/generators/cucumber/install/templates/step_definitions/web_steps_es.rb.erb +127 -0
  60. data/lib/generators/cucumber/install/templates/step_definitions/web_steps_ja.rb.erb +140 -0
  61. data/lib/generators/cucumber/install/templates/step_definitions/web_steps_ko.rb.erb +142 -0
  62. data/lib/generators/cucumber/install/templates/step_definitions/web_steps_no.rb.erb +105 -0
  63. data/lib/generators/cucumber/install/templates/step_definitions/web_steps_pt-BR.rb.erb +132 -0
  64. data/lib/generators/cucumber/install/templates/support/_rails_each_run.rb.erb +36 -0
  65. data/lib/generators/cucumber/install/templates/support/_rails_prefork.rb.erb +1 -0
  66. data/{templates/skeleton → lib/generators/cucumber/install/templates}/support/capybara.rb +0 -4
  67. data/{templates/skeleton → lib/generators/cucumber/install/templates}/support/paths.rb +11 -5
  68. data/{templates/skeleton → lib/generators/cucumber/install/templates}/support/rails.rb.erb +2 -2
  69. data/{templates/skeleton → lib/generators/cucumber/install/templates}/support/rails_spork.rb.erb +2 -2
  70. data/lib/generators/cucumber/install/templates/support/selectors.rb +39 -0
  71. data/lib/generators/cucumber/install/templates/support/web_steps_warning.txt +19 -0
  72. data/{templates/skeleton → lib/generators/cucumber/install/templates}/tasks/cucumber.rake.erb +18 -0
  73. data/spec/cucumber/web/tableish_spec.rb +83 -6
  74. data/spec/spec_helper.rb +1 -4
  75. metadata +299 -73
  76. data/HACKING.rdoc +0 -34
  77. data/README.rdoc +0 -64
  78. data/VERSION +0 -1
  79. data/features/rails2.feature +0 -56
  80. data/features/rails3.feature +0 -52
  81. data/features/support/matchers/files.rb +0 -17
  82. data/generators/cucumber/USAGE +0 -14
  83. data/generators/cucumber/cucumber_generator.rb +0 -89
  84. data/generators/cucumber/templates/step_definitions/web_steps_ja.rb.erb +0 -136
  85. data/generators/feature/USAGE +0 -12
  86. data/generators/feature/feature_generator.rb +0 -47
  87. data/lib/cucumber/rails/action_controller.rb +0 -65
  88. data/lib/cucumber/rails/active_record.rb +0 -34
  89. data/lib/cucumber/rails/capybara_javascript_emulation.rb +0 -72
  90. data/lib/cucumber/rails/test_unit.rb +0 -9
  91. data/lib/generators/cucumber/feature/feature_base.rb +0 -29
  92. data/lib/generators/cucumber/skeleton/USAGE +0 -21
  93. data/lib/generators/cucumber/skeleton/skeleton_base.rb +0 -202
  94. data/lib/generators/cucumber/skeleton/skeleton_generator.rb +0 -64
  95. data/rvm.yml +0 -22
  96. data/spec/generators/cucumber/skeleton/skeleton_base_spec.rb +0 -84
  97. data/spec/spec.opts +0 -2
  98. data/templates/skeleton/config/cucumber.yml.erb +0 -7
  99. data/templates/skeleton/environments/cucumber.rb.erb +0 -37
  100. data/templates/skeleton/step_definitions/capybara_steps.rb.erb +0 -197
  101. data/templates/skeleton/step_definitions/web_steps_cs.rb.erb +0 -136
  102. data/templates/skeleton/step_definitions/web_steps_da.rb.erb +0 -114
  103. data/templates/skeleton/step_definitions/web_steps_de.rb.erb +0 -136
  104. data/templates/skeleton/step_definitions/web_steps_es.rb.erb +0 -136
  105. data/templates/skeleton/step_definitions/web_steps_no.rb.erb +0 -114
  106. data/templates/skeleton/step_definitions/web_steps_pt-BR.rb.erb +0 -140
  107. data/templates/skeleton/step_definitions/webrat_steps.rb.erb +0 -268
  108. data/templates/skeleton/support/_rails_each_run.rb +0 -34
  109. data/templates/skeleton/support/_rails_prefork.rb.erb +0 -10
  110. data/templates/skeleton/support/webrat.rb +0 -8
  111. /data/{templates/skeleton → lib/generators/cucumber/install/templates}/script/cucumber +0 -0
  112. /data/{templates/skeleton → lib/generators/cucumber/install/templates}/support/edit_warning.txt +0 -0
@@ -0,0 +1,63 @@
1
+ Feature: Allow Cucumber to rescue exceptions
2
+
3
+ Background: A controller that raises an exception in a Rails app without web_steps.rb
4
+ Given I have created a new Rails 3 app "rails-3-app" with cucumber-rails support
5
+ And I remove the file "features/step_definitions/web_steps.rb"
6
+ And I write to "app/controllers/posts_controller.rb" with:
7
+ """
8
+ class PostsController < ApplicationController
9
+ def index
10
+ raise "There is an error in index"
11
+ end
12
+ end
13
+ """
14
+ And I write to "config/routes.rb" with:
15
+ """
16
+ Rails3App::Application.routes.draw do
17
+ resources :posts
18
+ end
19
+ """
20
+
21
+ Scenario: Allow rescue
22
+ And I write to "features/posts.feature" with:
23
+ """
24
+ Feature: posts
25
+ @allow-rescue
26
+ Scenario: See posts
27
+ When I look at the posts
28
+ """
29
+ And I write to "features/step_definitions/posts_steps.rb" with:
30
+ """
31
+ When /^I look at the posts$/ do
32
+ visit '/posts'
33
+ end
34
+ """
35
+ And I run `bundle exec rake db:migrate`
36
+ And I run `bundle exec cucumber`
37
+ Then it should pass with:
38
+ """
39
+ 1 scenario (1 passed)
40
+ 1 step (1 passed)
41
+ """
42
+
43
+ Scenario: Don't allow rescue
44
+ Given I write to "features/posts.feature" with:
45
+ """
46
+ Feature: posts
47
+ Scenario: See them
48
+ When I look at the posts
49
+ """
50
+ And I write to "features/step_definitions/posts_steps.rb" with:
51
+ """
52
+ When /^I look at the posts$/ do
53
+ visit '/posts'
54
+ end
55
+ """
56
+ And I run `bundle exec rake db:migrate`
57
+ And I run `bundle exec cucumber`
58
+ Then it should fail with:
59
+ """
60
+ 1 scenario (1 failed)
61
+ 1 step (1 failed)
62
+ """
63
+
@@ -0,0 +1,87 @@
1
+ Feature: Capybara Javascript Drivers
2
+
3
+ Background: A simple calendar app
4
+ Given I have created a new Rails 3 app "rails-3-app" with cucumber-rails support
5
+ And I successfully run `bundle exec rails g scaffold appointment name:string when:datetime`
6
+
7
+ Scenario Outline: Use a particular driver
8
+ Given I write to "features/create_appointment.feature" with:
9
+ """
10
+ @javascript
11
+ Feature: Create appointments
12
+ Scenario: Constitution on May 17
13
+ Given I am on the new appointment page
14
+ And I fill in "Norway's constitution" for "Name"
15
+ And I select "2009-02-20 15:10:00 UTC" as the "When" date and time
16
+ And I press "Create Appointment"
17
+ Then I should see "Norway's constitution"
18
+ And I should see "2009-02-20 15:10:00 UTC"
19
+
20
+ """
21
+ And I append to "Gemfile" with:
22
+ """
23
+ <Gemfile extra>
24
+
25
+ """
26
+ And I append to "features/support/env.rb" with:
27
+ """
28
+ <env.rb extra>
29
+
30
+ """
31
+
32
+ When I run `bundle exec rake db:migrate`
33
+ And I run `bundle exec rake cucumber`
34
+ Then it should pass with:
35
+ """
36
+ 1 scenario (1 passed)
37
+ 6 steps (6 passed)
38
+ """
39
+
40
+ Examples:
41
+ | Gemfile extra | env.rb extra |
42
+ | gem "capybara", :group => :test | require 'capybara' |
43
+
44
+ Scenario Outline: Mixed DB access
45
+ Given I write to "features/create_appointment.feature" with:
46
+ """
47
+ @javascript
48
+ Feature: Create appointments
49
+ Scenario: Constitution on May 17
50
+ Given a random appointment
51
+ And I am viewing random appointment
52
+ Then I should see "Random appointment"
53
+
54
+ """
55
+ And I write to "features/step_definitions/custom_steps.rb" with:
56
+ """
57
+ Given /^a random appointment$/ do
58
+ @appointment = Appointment.create!(:name => 'Random appointment', :when => DateTime.now)
59
+ end
60
+
61
+ Given /^I am viewing random appointment$/ do
62
+ visit appointment_path(@appointment)
63
+ end
64
+ """
65
+ And I append to "Gemfile" with:
66
+ """
67
+ <Gemfile extra>
68
+
69
+ """
70
+ And I append to "features/support/env.rb" with:
71
+ """
72
+ <env.rb extra>
73
+
74
+ """
75
+
76
+ When I run `bundle exec rake db:migrate`
77
+ And I run `bundle exec rake cucumber`
78
+ Then it should pass with:
79
+ """
80
+ 1 scenario (1 passed)
81
+ 3 steps (3 passed)
82
+ """
83
+
84
+ Examples:
85
+ | Gemfile extra | env.rb extra |
86
+ | gem "capybara", :group => :test | require 'capybara' |
87
+
@@ -0,0 +1,44 @@
1
+ Feature: DatabaseCleaner
2
+
3
+ Scenario: Create records in background
4
+ Given I have created a new Rails 3 app "rails-3-app" with cucumber-rails support
5
+ And I write to "features/widgets.feature" with:
6
+ """
7
+ Feature: Create widgets
8
+ Background: some widdgets
9
+ Given I have 2 widgets
10
+
11
+ Scenario: Add 3
12
+ When I create 3 more widgets
13
+ Then I should have 5 widgets
14
+
15
+ Scenario: Add 7
16
+ When I create 7 more widgets
17
+ Then I should have 9 widgets
18
+ """
19
+ And I successfully run `rails generate model widget name:string`
20
+ And I write to "features/step_definitions/widget_steps.rb" with:
21
+ """
22
+ Given /^I have (\d+) widgets$/ do |n|
23
+ n.to_i.times do |i|
24
+ Widget.create! :name => "Widget #{Widget.count + i}"
25
+ end
26
+ end
27
+
28
+ When /^I create (\d+) more widgets$/ do |n|
29
+ n.to_i.times do |i|
30
+ Widget.create! :name => "Widget #{Widget.count + i}"
31
+ end
32
+ end
33
+
34
+ Then /^I should have (\d+) widgets$/ do |n|
35
+ Widget.count.should == n.to_i
36
+ end
37
+ """
38
+ And I run `bundle exec rake db:migrate`
39
+ And I run `bundle exec rake cucumber`
40
+ Then it should pass with:
41
+ """
42
+ 2 scenarios (2 passed)
43
+ 6 steps (6 passed)
44
+ """
@@ -0,0 +1,34 @@
1
+ Feature: Emulate Javascript
2
+
3
+ Scenario: See a widget
4
+ Given I have created a new Rails 3 app "widgets" with cucumber-rails support
5
+ And I successfully run `rails generate scaffold widget name:string`
6
+ And I write to "features/f.feature" with:
7
+ """
8
+ @javascript
9
+ Feature: Widget inventory
10
+ Scenario: Delete a widget
11
+ Given there is a widget named "wrench"
12
+ When I go to the widgets page
13
+ Then I should see "wrench"
14
+ """
15
+ And I write to "features/step_definitions/s.rb" with:
16
+ """
17
+ Given /^there is a widget named "([^"]*)"$/ do |name|
18
+ Factory(:widget, :name => name)
19
+ end
20
+ """
21
+ And I write to "features/support/factories.rb" with:
22
+ """
23
+ Factory.define :widget do |f|
24
+ f.name 'testwidget'
25
+ end
26
+ """
27
+ When I run `bundle exec rake db:migrate`
28
+ And I run `bundle exec rake cucumber`
29
+ Then it should pass with:
30
+ """
31
+ 1 scenario (1 passed)
32
+ 3 steps (3 passed)
33
+ """
34
+
@@ -0,0 +1,37 @@
1
+ Feature: Inspect query string
2
+
3
+ Scenario: Inspect query string
4
+ Given I have created a new Rails 3 app "rails-3-app" with cucumber-rails support
5
+ And I successfully run `rails generate cucumber:feature post title:string body:text number:integer published:boolean`
6
+ And I successfully run `rails generate scaffold post title:string body:text number:integer published:boolean`
7
+ And I successfully run `rails generate scaffold cuke name:string`
8
+ And I overwrite "app/controllers/cukes_controller.rb" with:
9
+ """
10
+ class CukesController < ApplicationController
11
+ def index
12
+ redirect_to cuke_path(10, {:name => 'cucumber', :what => 'vegetable'})
13
+ end
14
+
15
+ def show
16
+ render :text => "Cuke #{params[:id]}"
17
+ end
18
+ end
19
+ """
20
+ And I write to "features/tests.feature" with:
21
+ """
22
+ Feature: Tests
23
+ Scenario: Tests
24
+ When I go to the cukes page
25
+ Then I should have the following query string:
26
+ | name | cucumber |
27
+ | what | vegetable |
28
+ And I should see "Cuke 10"
29
+ """
30
+ And I run `bundle exec rake db:migrate`
31
+ And I run `bundle exec rake cucumber`
32
+ Then it should pass with:
33
+ """
34
+ 3 scenarios (3 passed)
35
+ 16 steps (16 passed)
36
+ """
37
+
@@ -0,0 +1,16 @@
1
+ Feature: Rails 3
2
+ In order to take over the world
3
+ Cucumber-Rails should work on major versions
4
+ of Rails 3 and Ruby, with Capybara, Spork and DatabaseCleaner
5
+
6
+ Scenario: Install Cucumber-Rails
7
+ Given I have created a new Rails 3 app "rails-3-app" with cucumber-rails support
8
+ Then the following files should exist:
9
+ | config/cucumber.yml |
10
+ | script/cucumber |
11
+ | features/step_definitions/web_steps.rb |
12
+ | features/support/env.rb |
13
+ | features/support/paths.rb |
14
+ | features/support/selectors.rb |
15
+ | lib/tasks/cucumber.rake |
16
+ And the file "features/support/env.rb" should contain "require 'cucumber/rails'"
@@ -0,0 +1,53 @@
1
+ @announce
2
+ Feature: Mongoid
3
+
4
+ Scenario: Keep Mongoid happy
5
+ Given I successfully run `rails new cuke-app`
6
+ And I cd to "cuke-app"
7
+ And I write to "config/application.rb" with:
8
+ """
9
+ require File.expand_path('../boot', __FILE__)
10
+
11
+ require 'action_controller/railtie'
12
+ require 'action_mailer/railtie'
13
+ require 'active_resource/railtie'
14
+ require 'rails/test_unit/railtie'
15
+
16
+ Bundler.require(:default, Rails.env) if defined?(Bundler)
17
+
18
+ module CukeApp
19
+ class Application < Rails::Application
20
+ config.encoding = "utf-8"
21
+ config.filter_parameters += [:password]
22
+ end
23
+ end
24
+ """
25
+ And I remove the file "config/database.yml"
26
+ And I append to "Gemfile" with:
27
+ """
28
+ gem "cucumber-rails", :group => :test, :path => '../../..'
29
+ gem "capybara", :group => :test
30
+ gem "database_cleaner", :group => :test
31
+ gem "mongoid", :group => :test
32
+ gem "bson_ext", :group => :test
33
+
34
+ """
35
+ And I successfully run `bundle exec rails generate cucumber:install`
36
+ And I successfully run `bundle exec rails generate mongoid:config`
37
+ And I write to "features/tests.feature" with:
38
+ """
39
+ Feature: Tests
40
+ Scenario: Tests
41
+ When I go to the home page
42
+ """
43
+ And I overwrite "features/support/env.rb" with:
44
+ """
45
+ require 'cucumber/rails'
46
+ DatabaseCleaner.strategy = :truncation
47
+ """
48
+ And I run `bundle exec rake cucumber`
49
+ Then it should pass with:
50
+ """
51
+ 1 scenario (1 passed)
52
+ 1 step (1 passed)
53
+ """
@@ -0,0 +1,74 @@
1
+ Feature: Multiple Databases
2
+ In order to use Database Cleaner with multiple database repositories
3
+ As an engineer
4
+ I want to specify explicit strategies for each
5
+
6
+ Background: A Rails 3 app utilizing multiple database repositories exists
7
+ Given I have created a new Rails 3 app "rails-3-app" with cucumber-rails support
8
+ And I remove the file "features/step_definitions/web_steps.rb"
9
+ And I append to "config/database.yml" with:
10
+ """
11
+
12
+ ursidae:
13
+ adapter: sqlite3
14
+ database: db/ursidae.sqlite3
15
+ """
16
+ And I write to "app/models/bear.rb" with:
17
+ """
18
+ class Bear < ActiveRecord::Base
19
+ establish_connection "ursidae"
20
+ end
21
+ """
22
+ And a directory named "db/migrate"
23
+ And I write to "db/migrate/001_create_bears.rb" with:
24
+ """
25
+ class CreateBears < ActiveRecord::Migration
26
+ def self.up
27
+ if Rails.env == 'ursidae'
28
+ create_table :bears do |t|
29
+ t.string :name, :null => false
30
+ end
31
+ add_index :bears, :name, :unique => true
32
+ end
33
+ end
34
+ end
35
+ """
36
+ And I successfully run `bundle exec rake db:migrate`
37
+ And I successfully run `bundle exec rake db:migrate RAILS_ENV=ursidae`
38
+ And I write to "features/support/env.rb" with:
39
+ """
40
+ require 'cucumber/rails'
41
+ DatabaseCleaner.strategy = :transaction
42
+ DatabaseCleaner[:active_record, {:connection => "ursidae"}].strategy = :truncation
43
+ """
44
+ And I write to "features/create_bear.feature" with:
45
+ """
46
+ Feature: Screws up in transactional test and must use truncation
47
+ Scenario: I create a bear
48
+ When I create a bear
49
+ And something transactional happens
50
+ """
51
+ And I write to "features/step_definitions/create_bear_steps.rb" with:
52
+ """
53
+ When /^I create a bear$/ do
54
+ Bear.create!(:name => "yogi")
55
+ end
56
+ When /^something transactional happens$/ do
57
+ Bear.transaction { Bear.find_by_name("yogi").lock! }
58
+ end
59
+ """
60
+
61
+ Scenario: Default transactional strategy is not attempted on second database
62
+ When I run `bundle exec rake cucumber FEATURE=features/create_bear.feature`
63
+ Then it should pass with:
64
+ """
65
+ 1 scenario (1 passed)
66
+ 2 steps (2 passed)
67
+ """
68
+ And the output should not contain "cannot rollback - no transaction is active"
69
+
70
+ Scenario: Truncation strategy is used on the second database
71
+ Given I successfully run `bundle exec rails runner 'Bear.create(:name => "boo boo")'`
72
+ And I successfully run `bundle exec rake cucumber FEATURE=features/create_bear.feature`
73
+ When I run `bundle exec rails runner 'raise "ahh! bears!" if Bear.count > 0'`
74
+ Then the exit status should be 0
@@ -0,0 +1,33 @@
1
+ Feature: Named Selectors
2
+
3
+ Scenario: Look within named selector
4
+ Given a project without ActiveRecord
5
+ And a cukes resource
6
+ And I write to "app/views/cukes/index.html.erb" with:
7
+ """
8
+ <div class="foo">foo</div>
9
+ <div class="bar">bar</div>
10
+ """
11
+ And I write to "features/tests.feature" with:
12
+ """
13
+ Feature: Tests
14
+ Scenario: Tests
15
+ When I go to the cukes page
16
+ Then I should see "foo" within the foo div
17
+ And I should not see "bar" within the foo div
18
+ """
19
+ And I overwrite "features/support/selectors.rb" with:
20
+ """
21
+ module HtmlSelectorsHelpers
22
+ def selector_for(locator)
23
+ return '.foo' if locator == 'the foo div'
24
+ end
25
+ end
26
+ World(HtmlSelectorsHelpers)
27
+ """
28
+ And I run `rake cucumber`
29
+ Then it should pass with:
30
+ """
31
+ 1 scenario (1 passed)
32
+ 3 steps (3 passed)
33
+ """
@@ -0,0 +1,70 @@
1
+ @announce
2
+ Feature: No Database
3
+ Allow Cucumber to work with a Rails app without a database
4
+
5
+ Scenario: No ActiveRecord and DatabaseCleaner
6
+ Given I have created a new Rails 3 app "rails-3-app" with cucumber-rails support
7
+ # Turn off ActiveRecord
8
+ And I write to "config/application.rb" with:
9
+ """
10
+ require File.expand_path('../boot', __FILE__)
11
+
12
+ require 'action_controller/railtie'
13
+ require 'action_mailer/railtie'
14
+ require 'active_resource/railtie'
15
+ require 'rails/test_unit/railtie'
16
+
17
+ Bundler.require(:default, Rails.env) if defined?(Bundler)
18
+
19
+ module Rails3App
20
+ class Application < Rails::Application
21
+ config.encoding = "utf-8"
22
+ config.filter_parameters += [:password]
23
+ end
24
+ end
25
+ """
26
+ And I remove the file "config/database.yml"
27
+ And I overwrite "features/support/env.rb" with:
28
+ """
29
+ require 'cucumber/rails'
30
+ """
31
+ # Remove DatabaseCleaner and SQLite
32
+ And I write to "Gemfile" with:
33
+ """
34
+ source 'http://rubygems.org'
35
+ gem 'rails'
36
+ gem "cucumber-rails", :group => :test, :path => "../../.."
37
+ gem "capybara", :group => :test
38
+ gem "rspec-rails", :group => :test
39
+ """
40
+ And I write to "app/controllers/posts_controller.rb" with:
41
+ """
42
+ class PostsController < ApplicationController
43
+ def index
44
+ raise "There is an error in index"
45
+ end
46
+ end
47
+ """
48
+ And I write to "config/routes.rb" with:
49
+ """
50
+ Rails3App::Application.routes.draw do
51
+ resources :posts
52
+ end
53
+ """
54
+ And I write to "features/posts.feature" with:
55
+ """
56
+ Feature: posts
57
+ Scenario: See them
58
+ When I do it
59
+ """
60
+ And I write to "features/step_definitions/posts_steps.rb" with:
61
+ """
62
+ When /^I do it$/ do
63
+ visit '/posts'
64
+ end
65
+ """
66
+ And I run `bundle exec rake cucumber`
67
+ Then it should fail with:
68
+ """
69
+ There is an error in index
70
+ """
@@ -0,0 +1,24 @@
1
+ Feature: Pseudo-class Selectors
2
+
3
+ Scenario: Look within css pseudo-class selectors
4
+ Given a project without ActiveRecord
5
+ And a cukes resource
6
+ And I write to "app/views/cukes/index.html.erb" with:
7
+ """
8
+ <div>foo</div>
9
+ <div>bar</div>
10
+ """
11
+ And I write to "features/tests.feature" with:
12
+ """
13
+ Feature: Tests
14
+ Scenario: Tests
15
+ When I go to the cukes page
16
+ Then I should see "bar" within "div:nth-child(2)"
17
+ And I should not see "foo" within "div:nth-child(2)"
18
+ """
19
+ And I run `rake cucumber`
20
+ Then it should pass with:
21
+ """
22
+ 1 scenario (1 passed)
23
+ 3 steps (3 passed)
24
+ """
@@ -0,0 +1,38 @@
1
+ Feature: Rerun profile
2
+ In order to concentrate on failing features
3
+ As a Rails developer working with Cucumber
4
+ I want to rerun only failing features
5
+
6
+ Scenario: Rerun
7
+ Given I have created a new Rails 3 app "rails-3-app" with cucumber-rails support
8
+ And a file named "rerun.txt" with:
9
+ """
10
+ features/rerun_test.feature:2
11
+ """
12
+ And a file named "features/rerun_test.feature" with:
13
+ """
14
+ Feature: Rerun test
15
+ Scenario: failing before
16
+ Given fixed now
17
+
18
+ Scenario: always passing
19
+ Given passing
20
+ """
21
+ And a file named "features/step_definitions/rerun_steps.rb" with:
22
+ """
23
+ Given /fixed now/ do
24
+ puts "All fixed now"
25
+ end
26
+
27
+ Given /passing/ do
28
+ puts "I've always been passing"
29
+ end
30
+ """
31
+ When I successfully run `bundle exec cucumber -p rerun`
32
+ Then it should pass with:
33
+ """
34
+ 1 scenario (1 passed)
35
+ 1 step (1 passed)
36
+ """
37
+ And the file "rerun.txt" should not contain "features/rerun_test.feature:2"
38
+
@@ -0,0 +1,47 @@
1
+ Feature: REST API
2
+
3
+ Scenario: Compare JSON
4
+ Given I have created a new Rails 3 app "rails-3-app" with cucumber-rails support
5
+ And I write to "app/controllers/posts_controller.rb" with:
6
+ """
7
+ class PostsController < ApplicationController
8
+ def index
9
+ render :json => {'hello' => 'world'}.to_json
10
+ end
11
+ end
12
+ """
13
+ And I write to "config/routes.rb" with:
14
+ """
15
+ Rails3App::Application.routes.draw do
16
+ resources :posts
17
+ end
18
+ """
19
+ And I write to "features/posts.feature" with:
20
+ """
21
+ Feature: posts
22
+ Scenario: See them
23
+ When the client requests GET /posts
24
+ Then the response should be JSON:
25
+ \"\"\"
26
+ {
27
+ "hello": "world"
28
+ }
29
+ \"\"\"
30
+ """
31
+ And I write to "features/step_definitions/rest_steps.rb" with:
32
+ """
33
+ When /^the client requests GET (.*)$/ do |path|
34
+ get(path)
35
+ end
36
+
37
+ Then /^the response should be JSON:$/ do |json|
38
+ JSON.parse(last_response.body).should == JSON.parse(json)
39
+ end
40
+ """
41
+ And I run `bundle exec rake db:migrate`
42
+ And I run `bundle exec rake cucumber`
43
+ Then it should pass with:
44
+ """
45
+ 1 scenario (1 passed)
46
+ 2 steps (2 passed)
47
+ """
@@ -0,0 +1,18 @@
1
+ Feature: Routing
2
+
3
+ Scenario: Visit undefined route
4
+ Given a project without ActiveRecord
5
+ And I remove the file "public/index.html"
6
+ And I write to "features/tests.feature" with:
7
+ """
8
+ Feature: Tests
9
+ Scenario: Tests
10
+ When I go to the home page
11
+ """
12
+ And I run `rake cucumber`
13
+ Then it should fail with:
14
+ """
15
+ 1 scenario (1 failed)
16
+ 1 step (1 failed)
17
+ """
18
+ And the stdout should contain "ActionController::RoutingError"