cucumber-rails 1.5.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +5 -5
  2. data/.github/ISSUE_TEMPLATE.md +52 -0
  3. data/.github/PULL_REQUEST_TEMPLATE.md +42 -0
  4. data/.gitignore +3 -1
  5. data/.rspec +4 -1
  6. data/.rubocop.yml +68 -0
  7. data/.travis.yml +43 -33
  8. data/Appraisals +25 -92
  9. data/{History.md → CHANGELOG.md} +242 -40
  10. data/CONTRIBUTING.md +15 -24
  11. data/Gemfile +2 -4
  12. data/LICENSE +1 -1
  13. data/README.md +57 -27
  14. data/Rakefile +18 -14
  15. data/bin/install_geckodriver.sh +19 -0
  16. data/bin/install_webpacker.sh +9 -0
  17. data/config/cucumber.yml +2 -5
  18. data/cucumber-rails.gemspec +35 -28
  19. data/dev_tasks/cucumber.rake +2 -0
  20. data/dev_tasks/rspec.rake +2 -0
  21. data/dev_tasks/yard.rake +7 -14
  22. data/dev_tasks/yard/default/layout/html/setup.rb +6 -1
  23. data/features/allow_rescue.feature +16 -11
  24. data/features/annotations.feature +8 -11
  25. data/features/capybara_javascript_drivers.feature +38 -28
  26. data/features/choose_javascript_database_strategy.feature +37 -57
  27. data/features/configuration.feature +48 -0
  28. data/features/database_cleaner.feature +18 -18
  29. data/features/disable_automatic_database_cleaning.feature +12 -18
  30. data/features/emulate_javascript.feature +64 -47
  31. data/features/install_cucumber_rails.feature +4 -4
  32. data/features/no_database.feature +8 -19
  33. data/features/raising_errors.feature +9 -3
  34. data/features/rerun_profile.feature +17 -7
  35. data/features/rest_api.feature +12 -12
  36. data/features/step_definitions/cucumber_rails_steps.rb +44 -88
  37. data/features/support/aruba.rb +3 -1
  38. data/features/support/cucumber_rails_helper.rb +85 -0
  39. data/features/support/env.rb +4 -30
  40. data/features/support/hooks.rb +8 -0
  41. data/gemfiles/rails_4_2.gemfile +5 -13
  42. data/gemfiles/rails_5_0.gemfile +5 -12
  43. data/gemfiles/rails_5_1.gemfile +4 -9
  44. data/gemfiles/rails_5_2.gemfile +10 -0
  45. data/gemfiles/rails_6_0.gemfile +9 -0
  46. data/lib/cucumber/rails.rb +17 -15
  47. data/lib/cucumber/rails/action_dispatch.rb +21 -0
  48. data/lib/cucumber/rails/application.rb +16 -7
  49. data/lib/cucumber/rails/capybara.rb +2 -0
  50. data/lib/cucumber/rails/capybara/javascript_emulation.rb +45 -37
  51. data/lib/cucumber/rails/capybara/select_dates_and_times.rb +6 -4
  52. data/lib/cucumber/rails/database.rb +30 -8
  53. data/lib/cucumber/rails/hooks.rb +2 -0
  54. data/lib/cucumber/rails/hooks/active_record.rb +14 -12
  55. data/lib/cucumber/rails/hooks/allow_rescue.rb +2 -0
  56. data/lib/cucumber/rails/hooks/database_cleaner.rb +6 -4
  57. data/lib/cucumber/rails/hooks/mail.rb +4 -4
  58. data/lib/cucumber/rails/rspec.rb +3 -1
  59. data/lib/cucumber/rails/world.rb +24 -7
  60. data/lib/generators/cucumber/{install/USAGE → USAGE} +0 -0
  61. data/lib/generators/cucumber/{install/install_generator.rb → install_generator.rb} +23 -10
  62. data/lib/generators/cucumber/{install/templates → templates}/config/cucumber.yml.erb +4 -3
  63. data/lib/generators/cucumber/{install/templates → templates}/script/cucumber +1 -0
  64. data/lib/generators/cucumber/{install/templates → templates}/support/_rails_each_run.rb.erb +2 -2
  65. data/lib/generators/cucumber/{install/templates → templates}/support/_rails_prefork.rb.erb +0 -0
  66. data/lib/generators/cucumber/{install/templates → templates}/support/capybara.rb +2 -0
  67. data/lib/generators/cucumber/{install/templates → templates}/support/edit_warning.txt +0 -0
  68. data/lib/generators/cucumber/{install/templates → templates}/support/rails.rb.erb +0 -0
  69. data/lib/generators/cucumber/{install/templates → templates}/support/rails_spork.rb.erb +0 -0
  70. data/lib/generators/cucumber/{install/templates → templates}/tasks/cucumber.rake.erb +9 -9
  71. data/spec/cucumber/rails/database_spec.rb +46 -33
  72. data/spec/generators/cucumber/{install/install_generator_spec.rb → install_generator_spec.rb} +17 -9
  73. data/spec/spec_helper.rb +13 -4
  74. metadata +105 -139
  75. data/Gemfile.appraisal +0 -3
  76. data/features/support/bundler_pre_support.rb +0 -28
  77. data/features/support/fixtures/bundler-1.0.21.gem +0 -0
  78. data/features/support/fixtures/bundler-1.1.rc.gem +0 -0
  79. data/features/support/legacy_web_steps_support.rb +0 -289
  80. data/gemfiles/lowest_version_bounds.gemfile +0 -26
  81. data/gemfiles/rails_4_0.gemfile +0 -19
  82. data/gemfiles/rails_4_1.gemfile +0 -18
  83. data/lib/cucumber/rails/action_controller.rb +0 -12
@@ -1,44 +1,44 @@
1
- Feature: DatabaseCleaner
1
+ Feature: Database Cleaner
2
2
 
3
3
  Scenario: Create records in background
4
4
  Given I have created a new Rails app and installed cucumber-rails
5
- And I write to "features/widgets.feature" with:
5
+ When I write to "features/widgets.feature" with:
6
6
  """
7
7
  Feature: Create widgets
8
- Background: some widdgets
8
+ Background: 2 initial widgets
9
9
  Given I have 2 widgets
10
10
 
11
- Scenario: Add 3
11
+ Scenario: Add 3 widgets
12
12
  When I create 3 more widgets
13
13
  Then I should have 5 widgets
14
14
 
15
- Scenario: Add 7
15
+ Scenario: Add 7 widgets
16
16
  When I create 7 more widgets
17
17
  Then I should have 9 widgets
18
18
  """
19
- And I successfully run `rails generate model widget name:string`
19
+ And I run `rails generate model widget name:string`
20
20
  And I write to "features/step_definitions/widget_steps.rb" with:
21
21
  """
22
- Given /^I have (\d+) widgets$/ do |n|
23
- n.to_i.times do |i|
24
- Widget.create! :name => "Widget #{Widget.count + i}"
22
+ Given('I have {int} widgets') do |number|
23
+ number.times do |i|
24
+ Widget.create! name: "Widget #{Widget.count + i}"
25
25
  end
26
26
  end
27
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}"
28
+ When('I create {int} more widgets') do |number|
29
+ number.times do |i|
30
+ Widget.create! name: "Widget #{Widget.count + i}"
31
31
  end
32
32
  end
33
33
 
34
- Then /^I should have (\d+) widgets$/ do |n|
35
- Widget.count.should == n.to_i
34
+ Then('I should have {int} widgets') do |number|
35
+ expect(Widget.count).to eq(number)
36
36
  end
37
37
  """
38
38
  And I run `bundle exec rake db:migrate`
39
39
  And I run `bundle exec rake cucumber`
40
40
  Then the feature run should pass with:
41
- """
42
- 2 scenarios (2 passed)
43
- 6 steps (6 passed)
44
- """
41
+ """
42
+ 2 scenarios (2 passed)
43
+ 6 steps (6 passed)
44
+ """
@@ -12,7 +12,7 @@ Feature: Disable automatic database cleaning
12
12
 
13
13
  Scenario: Disabling automatic cleaning
14
14
  Given I have created a new Rails app and installed cucumber-rails
15
- And I append to "features/env.rb" with:
15
+ When I append to "features/env.rb" with:
16
16
  """
17
17
  Cucumber::Rails::Database.autorun_database_cleaner = false
18
18
  """
@@ -27,29 +27,23 @@ Feature: Disable automatic database cleaning
27
27
  When I create 5 widgets
28
28
  Then I should have 8 widgets
29
29
  """
30
- And I successfully run `rails generate model widget name:string`
30
+ And I run `rails generate model widget name:string`
31
31
  And I write to "features/step_definitions/widget_steps.rb" with:
32
32
  """
33
- Given /^I have (\d+) widgets$/ do |n|
34
- n.to_i.times do |i|
35
- Widget.create! :name => "Widget #{Widget.count + i}"
33
+ When('I create {int} widgets') do |number|
34
+ number.times do |i|
35
+ Widget.create! name: "Widget #{Widget.count + i}"
36
36
  end
37
37
  end
38
38
 
39
- When /^I create (\d+) widgets$/ do |n|
40
- n.to_i.times do |i|
41
- Widget.create! :name => "Widget #{Widget.count + i}"
42
- end
43
- end
44
-
45
- Then /^I should have (\d+) widgets$/ do |n|
46
- Widget.count.should == n.to_i
39
+ Then('I should have {int} widgets') do |number|
40
+ expect(Widget.count).to eq(number)
47
41
  end
48
- """
42
+ """
49
43
  And I run `bundle exec rake db:migrate`
50
44
  And I run `bundle exec rake cucumber`
51
45
  Then the feature run should pass with:
52
- """
53
- 2 scenarios (2 passed)
54
- 4 steps (4 passed)
55
- """
46
+ """
47
+ 2 scenarios (2 passed)
48
+ 4 steps (4 passed)
49
+ """
@@ -1,44 +1,53 @@
1
1
  Feature: Emulate Javascript
2
2
 
3
- Scenario: See a widget
3
+ Background:
4
4
  Given I have created a new Rails app and installed cucumber-rails
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
- FactoryGirl.create(:widget, :name => name)
5
+ And I force selenium to run Firefox in headless mode
6
+ When I run `rails generate scaffold widget name:string`
7
+ And I write to "features/step_definitions/widget_steps.rb" with:
8
+ """
9
+ Given('there is a widget named {string}') do |name|
10
+ FactoryBot.create(:widget, name: name)
11
+ end
12
+
13
+ When('I am on the widgets page') do
14
+ visit widgets_path
15
+ end
16
+
17
+ Then('I should see {string}') do |text|
18
+ expect(page).to have_content(text)
19
19
  end
20
20
  """
21
- And I write to "features/support/factories.rb" with:
21
+ And I write to "features/support/factories/widget.rb" with:
22
22
  """
23
- FactoryGirl.define do
23
+ FactoryBot.define do
24
24
  factory :widget do
25
- name 'testwidget'
25
+ name { 'testwidget' }
26
26
  end
27
27
  end
28
28
  """
29
- When I run `bundle exec rake db:migrate`
29
+
30
+ Scenario: See a widget
31
+ When I write to "features/widgets.feature" with:
32
+ """
33
+ @javascript
34
+ Feature: Widget inventory
35
+ Scenario: Delete a widget
36
+ Given there is a widget named "wrench"
37
+ And I am on the widgets page
38
+ Then I should see "wrench"
39
+ """
40
+ And I run `bundle exec rake db:migrate`
30
41
  And I run `bundle exec rake cucumber`
31
42
  Then the feature run should pass with:
32
- """
33
- 1 scenario (1 passed)
34
- 3 steps (3 passed)
35
- """
43
+ """
44
+ 1 scenario (1 passed)
45
+ 3 steps (3 passed)
46
+ """
36
47
 
37
48
  Scenario: Pass on the CSRF token
38
- Given I have created a new Rails app and installed cucumber-rails
39
- And I successfully run `rails generate scaffold widget name:string`
40
- And I successfully run `sed -i -e 's/forgery_protection *= false/forgery_protection = true/' config/environments/test.rb`
41
- And I successfully run `rails generate controller session establish`
49
+ When I run `sed -i -e 's/forgery_protection *= false/forgery_protection = true/' config/environments/test.rb`
50
+ And I run `rails generate controller session establish`
42
51
  And I write to "app/controllers/session_controller.rb" with:
43
52
  """
44
53
  class SessionController < ApplicationController
@@ -51,42 +60,50 @@ Feature: Emulate Javascript
51
60
  """
52
61
  class ApplicationController < ActionController::Base
53
62
  protect_from_forgery
54
- before_action :except => :establish do
55
- render :text => "denied", :status => :forbidden and return false unless session[:verified]
63
+
64
+ before_action except: :establish do
65
+ render text: 'denied', status: :forbidden and return false unless session[:verified]
56
66
  end
57
67
  end
58
68
  """
59
- And I write to "features/f.feature" with:
69
+ And I write to "features/widgets.feature" with:
60
70
  """
61
71
  Feature: Widget inventory
62
72
  Scenario: Delete a widget
63
73
  Given there is a widget named "wrench"
64
- When I go to the session establish page
65
- And I go to the widgets page
74
+ And I am on the session establish page
75
+ And I am on the widgets page
66
76
  Then I should see "wrench"
67
77
  When I follow "Destroy"
68
78
  Then I should not see "denied"
69
79
  And I should be on the widgets page
70
80
  And I should not see "wrench"
71
81
  """
72
- And I write to "features/step_definitions/s.rb" with:
82
+ And I append to "features/step_definitions/widget_steps.rb" with:
83
+ # TODO: Remove the newline below (Required) once bug is fixed: https://github.com/cucumber/aruba/issues/662
73
84
  """
74
- Given /^there is a widget named "([^"]*)"$/ do |name|
75
- FactoryGirl.create(:widget, :name => name)
85
+
86
+ Given('I am on the session establish page') do
87
+ visit session_establish_path
76
88
  end
77
- """
78
- And I write to "features/support/factories.rb" with:
79
- """
80
- FactoryGirl.define do
81
- factory :widget do
82
- name 'testwidget'
83
- end
89
+
90
+ When('I follow {string}') do |link|
91
+ click_link(link)
92
+ end
93
+
94
+ Then('I should not see {string}') do |text|
95
+ expect(page).not_to have_content(text)
96
+ end
97
+
98
+ Then('I should be on the widgets page') do
99
+ current_path = URI.parse(current_url).path
100
+ expect(current_path).to eq(widgets_path)
84
101
  end
85
102
  """
86
- When I run `bundle exec rake db:migrate`
103
+ And I run `bundle exec rake db:migrate`
87
104
  And I run `bundle exec rake cucumber`
88
105
  Then the feature run should pass with:
89
- """
90
- 1 scenario (1 passed)
91
- 8 steps (8 passed)
92
- """
106
+ """
107
+ 1 scenario (1 passed)
108
+ 8 steps (8 passed)
109
+ """
@@ -1,7 +1,7 @@
1
- Feature: Rails
2
- In order to take over the world
3
- Cucumber-Rails should work on major versions
4
- of Rails 3 or 4 and Ruby, with Capybara, Spork and DatabaseCleaner
1
+ Feature: Install Cucumber Rails
2
+
3
+ Cucumber-Rails should work on supported versions
4
+ of Ruby on Rails, with Capybara and DatabaseCleaner
5
5
 
6
6
  Scenario: Install Cucumber-Rails
7
7
  Given I have created a new Rails app and installed cucumber-rails
@@ -1,11 +1,11 @@
1
1
  Feature: No Database
2
+
2
3
  Allow Cucumber to work with a Rails app without a database
3
4
 
4
- @fails-on-travis
5
5
  Scenario: No ActiveRecord and DatabaseCleaner
6
6
  Given I have created a new Rails app with no database and installed cucumber-rails
7
7
  # Turn off ActiveRecord
8
- And I write to "config/application.rb" with:
8
+ When I write to "config/application.rb" with:
9
9
  """
10
10
  require File.expand_path('../boot', __FILE__)
11
11
 
@@ -17,7 +17,7 @@ Feature: No Database
17
17
 
18
18
  module TestApp
19
19
  class Application < Rails::Application
20
- config.encoding = "utf-8"
20
+ config.encoding = 'utf-8'
21
21
  config.filter_parameters += [:password]
22
22
  end
23
23
  end
@@ -26,24 +26,13 @@ Feature: No Database
26
26
  """
27
27
  require 'cucumber/rails'
28
28
  """
29
- # Remove DatabaseCleaner and SQLite
30
- And I write to "Gemfile" with:
31
- """
32
- source 'http://rubygems.org'
33
- gem 'rails'
34
- gem "cucumber-rails", :group => :test, :path => "../../.."
35
- gem "capybara", :group => :test
36
- gem "rspec-rails", :group => :test
37
- if RUBY_VERSION >= '2.0.0'
38
- gem 'sass-rails'
39
- gem 'uglifier'
40
- end
41
- """
29
+ And I remove the 'database_cleaner' gem from the Gemfile
30
+ And I remove the 'sqlite' gem from the Gemfile
42
31
  And I write to "app/controllers/posts_controller.rb" with:
43
32
  """
44
33
  class PostsController < ApplicationController
45
34
  def index
46
- raise "There is an error in index"
35
+ raise 'There is an error in index'
47
36
  end
48
37
  end
49
38
  """
@@ -57,11 +46,11 @@ Feature: No Database
57
46
  """
58
47
  Feature: posts
59
48
  Scenario: See them
60
- When I do it
49
+ When I view the posts
61
50
  """
62
51
  And I write to "features/step_definitions/posts_steps.rb" with:
63
52
  """
64
- When /^I do it$/ do
53
+ When('I view the posts') do
65
54
  visit '/posts'
66
55
  end
67
56
  """
@@ -1,12 +1,18 @@
1
1
  Feature: Raise Errors
2
2
 
3
3
  Scenario: Raise error for undefined route
4
- Given I have created a new Rails app "test-app" with no database and installed cucumber-rails
5
- And I write to "features/tests.feature" with:
4
+ Given I have created a new Rails app with no database and installed cucumber-rails
5
+ When I write to "features/home.feature" with:
6
6
  """
7
7
  Feature: Tests
8
8
  Scenario: Tests
9
- When I go to the products page
9
+ When I go to the home page
10
+ """
11
+ And I write to "features/home_steps.rb" with:
12
+ """
13
+ When('I go to the home page') do
14
+ visit('/')
15
+ end
10
16
  """
11
17
  And I run `bundle exec cucumber`
12
18
  Then it should fail with:
@@ -1,4 +1,5 @@
1
1
  Feature: Rerun profile
2
+
2
3
  In order to concentrate on failing features
3
4
  As a Rails developer working with Cucumber
4
5
  I want to rerun only failing features
@@ -8,6 +9,7 @@ Feature: Rerun profile
8
9
  And a file named "rerun.txt" with:
9
10
  """
10
11
  features/rerun_test.feature:2
12
+ features/rerun_test.feature:5
11
13
  """
12
14
  And a file named "features/rerun_test.feature" with:
13
15
  """
@@ -15,23 +17,31 @@ Feature: Rerun profile
15
17
  Scenario: failing before
16
18
  Given fixed now
17
19
 
20
+ Scenario: still failing
21
+ Given broken
22
+
18
23
  Scenario: always passing
19
24
  Given passing
20
25
  """
21
26
  And a file named "features/step_definitions/rerun_steps.rb" with:
22
27
  """
23
- Given /fixed now/ do
24
- puts "All fixed now"
28
+ Given('fixed now') do
29
+ puts 'All fixed now'
30
+ end
31
+
32
+ Given('broken') do
33
+ raise "I'm broken"
25
34
  end
26
35
 
27
- Given /passing/ do
36
+ Given('passing') do
28
37
  puts "I've always been passing"
29
38
  end
30
39
  """
31
- When I successfully run `bundle exec cucumber -p rerun`
32
- Then the feature run should pass with:
40
+ When I run `bundle exec cucumber -p rerun`
41
+ Then it should fail with:
33
42
  """
34
- 1 scenario (1 passed)
35
- 1 step (1 passed)
43
+ 2 scenarios (1 failed, 1 passed)
44
+ 2 steps (1 failed, 1 passed)
36
45
  """
37
46
  And the file "rerun.txt" should not contain "features/rerun_test.feature:2"
47
+ And the file "rerun.txt" should contain "features/rerun_test.feature:5"
@@ -1,18 +1,18 @@
1
1
  Feature: REST API
2
2
 
3
3
  Scenario: Compare JSON
4
- Given I have created a new Rails app "rails-3-app" and installed cucumber-rails
5
- And I write to "app/controllers/posts_controller.rb" with:
4
+ Given I have created a new Rails app and installed cucumber-rails
5
+ When I write to "app/controllers/posts_controller.rb" with:
6
6
  """
7
7
  class PostsController < ApplicationController
8
8
  def index
9
- render :json => {'hello' => 'world'}.to_json
9
+ render json: {'hello' => 'world'}.to_json
10
10
  end
11
11
  end
12
12
  """
13
13
  And I write to "config/routes.rb" with:
14
14
  """
15
- Rails3App::Application.routes.draw do
15
+ TestApp::Application.routes.draw do
16
16
  resources :posts
17
17
  end
18
18
  """
@@ -28,20 +28,20 @@ Feature: REST API
28
28
  }
29
29
  \"\"\"
30
30
  """
31
- And I write to "features/step_definitions/rest_steps.rb" with:
31
+ And I write to "features/step_definitions/post_steps.rb" with:
32
32
  """
33
- When /^the client requests GET (.*)$/ do |path|
33
+ When('the client requests GET /{word}') do |path|
34
34
  get(path)
35
35
  end
36
36
 
37
- Then /^the response should be JSON:$/ do |json|
38
- JSON.parse(last_response.body).should == JSON.parse(json)
37
+ Then('the response should be JSON:') do |json|
38
+ expect(JSON.parse(last_response.body)).to eq(JSON.parse(json))
39
39
  end
40
40
  """
41
41
  And I run `bundle exec rake db:migrate`
42
42
  And I run `bundle exec rake cucumber`
43
43
  Then the feature run should pass with:
44
- """
45
- 1 scenario (1 passed)
46
- 2 steps (2 passed)
47
- """
44
+ """
45
+ 1 scenario (1 passed)
46
+ 2 steps (2 passed)
47
+ """