cucumber-rails 1.7.0 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +35 -0
  4. data/.rubocop_todo.yml +14 -398
  5. data/.travis.yml +23 -8
  6. data/Appraisals +26 -23
  7. data/CHANGELOG.md +70 -15
  8. data/CONTRIBUTING.md +4 -14
  9. data/Gemfile +2 -4
  10. data/README.md +4 -7
  11. data/Rakefile +17 -13
  12. data/bin/install_geckodriver.sh +1 -1
  13. data/cucumber-rails.gemspec +24 -24
  14. data/dev_tasks/cucumber.rake +2 -0
  15. data/dev_tasks/rspec.rake +2 -0
  16. data/dev_tasks/yard.rake +6 -5
  17. data/dev_tasks/yard/default/layout/html/setup.rb +6 -1
  18. data/features/allow_rescue.feature +11 -11
  19. data/features/annotations.feature +2 -2
  20. data/features/capybara_javascript_drivers.feature +11 -22
  21. data/features/choose_javascript_database_strategy.feature +36 -56
  22. data/features/database_cleaner.feature +12 -12
  23. data/features/disable_automatic_database_cleaning.feature +10 -16
  24. data/features/emulate_javascript.feature +16 -16
  25. data/features/no_database.feature +5 -6
  26. data/features/raising_errors.feature +2 -2
  27. data/features/rerun_profile.feature +4 -4
  28. data/features/rest_api.feature +10 -10
  29. data/features/step_definitions/cucumber_rails_steps.rb +20 -101
  30. data/features/support/aruba.rb +2 -0
  31. data/features/support/cucumber_rails_helper.rb +80 -0
  32. data/features/support/env.rb +4 -30
  33. data/features/support/legacy_web_steps_support.rb +1 -1
  34. data/gemfiles/rails_4_2.gemfile +4 -4
  35. data/gemfiles/rails_5_0.gemfile +4 -4
  36. data/gemfiles/rails_5_1.gemfile +3 -3
  37. data/gemfiles/rails_5_2.gemfile +4 -4
  38. data/gemfiles/rails_6_0.gemfile +3 -2
  39. data/lib/cucumber/rails.rb +14 -6
  40. data/lib/cucumber/rails/action_controller.rb +10 -6
  41. data/lib/cucumber/rails/application.rb +13 -7
  42. data/lib/cucumber/rails/capybara.rb +2 -0
  43. data/lib/cucumber/rails/capybara/javascript_emulation.rb +17 -7
  44. data/lib/cucumber/rails/capybara/select_dates_and_times.rb +3 -1
  45. data/lib/cucumber/rails/database.rb +25 -7
  46. data/lib/cucumber/rails/hooks.rb +2 -0
  47. data/lib/cucumber/rails/hooks/active_record.rb +8 -4
  48. data/lib/cucumber/rails/hooks/allow_rescue.rb +2 -0
  49. data/lib/cucumber/rails/hooks/database_cleaner.rb +4 -2
  50. data/lib/cucumber/rails/hooks/mail.rb +2 -0
  51. data/lib/cucumber/rails/rspec.rb +3 -1
  52. data/lib/cucumber/rails/world.rb +12 -6
  53. data/lib/generators/cucumber/{install/USAGE → USAGE} +0 -0
  54. data/lib/generators/cucumber/{install/install_generator.rb → install_generator.rb} +18 -9
  55. data/lib/generators/cucumber/{install/templates → templates}/config/cucumber.yml.erb +0 -0
  56. data/lib/generators/cucumber/{install/templates → templates}/script/cucumber +1 -0
  57. data/lib/generators/cucumber/{install/templates → templates}/support/_rails_each_run.rb.erb +0 -0
  58. data/lib/generators/cucumber/{install/templates → templates}/support/_rails_prefork.rb.erb +0 -0
  59. data/lib/generators/cucumber/{install/templates → templates}/support/capybara.rb +2 -0
  60. data/lib/generators/cucumber/{install/templates → templates}/support/edit_warning.txt +0 -0
  61. data/lib/generators/cucumber/{install/templates → templates}/support/rails.rb.erb +0 -0
  62. data/lib/generators/cucumber/{install/templates → templates}/support/rails_spork.rb.erb +0 -0
  63. data/lib/generators/cucumber/{install/templates → templates}/tasks/cucumber.rake.erb +0 -0
  64. data/spec/cucumber/rails/database_spec.rb +20 -16
  65. data/spec/generators/cucumber/{install/install_generator_spec.rb → install_generator_spec.rb} +16 -6
  66. data/spec/spec_helper.rb +4 -2
  67. metadata +99 -96
  68. data/features/support/bundler_pre_support.rb +0 -28
  69. data/features/support/fixtures/bundler-1.0.21.gem +0 -0
  70. data/features/support/fixtures/bundler-1.1.rc.gem +0 -0
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cucumber/rake/task'
2
4
 
3
5
  Cucumber::Rake::Task.new
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rspec/core/rake_task'
2
4
 
3
5
  RSpec::Core::RakeTask.new
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yard'
2
4
  require 'yard/rake/yardoc_task'
3
5
 
@@ -6,9 +8,8 @@ API_DIR = File.join(SITE_DIR, 'api', 'cucumber-rails', 'ruby', 'yardoc')
6
8
 
7
9
  namespace :api do
8
10
  file :dir do
9
- unless File.directory?(SITE_DIR)
10
- raise "You need to git clone git@github.com:cucumber/cucumber.github.com.git #{SITE_DIR}"
11
- end
11
+ raise "You need to git clone git@github.com:cucumber/cucumber.github.com.git #{SITE_DIR}" unless File.directory?(SITE_DIR)
12
+
12
13
  sh('git pull origin master')
13
14
  mkdir_p API_DIR
14
15
  end
@@ -18,7 +19,7 @@ namespace :api do
18
19
  YARD::Rake::YardocTask.new(:yard) do |yard|
19
20
  dir = API_DIR
20
21
  mkdir_p dir
21
- yard.options = ["--out", dir]
22
+ yard.options = ['--out', dir]
22
23
  end
23
24
  task yard: :dir
24
25
 
@@ -31,5 +32,5 @@ namespace :api do
31
32
  end
32
33
 
33
34
  desc "Generate YARD docs for Cucumber-Rails' API"
34
- task doc: [:yard, :release]
35
+ task doc: %i[yard release]
35
36
  end
@@ -1,4 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  def init
2
4
  super
3
- options[:serializer].serialize('/images/bubble_32x32.png', IO.read(File.dirname(__FILE__) + '/bubble_32x32.png'))
5
+ options[:serializer].serialize(
6
+ '/images/bubble_32x32.png',
7
+ IO.read(File.dirname(__FILE__) + '/bubble_32x32.png')
8
+ )
4
9
  end
@@ -1,37 +1,37 @@
1
1
  Feature: Allow Cucumber to rescue exceptions
2
2
 
3
3
  Background: A controller that raises an exception
4
- Given I have created a new Rails app "rails-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
- raise "There is an error in index"
9
+ raise 'There is an error in index'
10
10
  end
11
11
  end
12
12
  """
13
13
  And I write to "config/routes.rb" with:
14
14
  """
15
- RailsApp::Application.routes.draw do
15
+ TestApp::Application.routes.draw do
16
16
  resources :posts
17
17
  end
18
18
  """
19
19
 
20
20
  Scenario: Allow rescue
21
- Given I write to "features/posts.feature" with:
21
+ When I write to "features/posts.feature" with:
22
22
  """
23
23
  Feature: posts
24
24
  @allow-rescue
25
25
  Scenario: See posts
26
- When I look at the posts
27
- Then I should see the public error page
26
+ When I look at the posts
27
+ Then I should see the public error page
28
28
  """
29
29
  And I write to "features/step_definitions/posts_steps.rb" with:
30
30
  """
31
- When /^I look at the posts$/ do
31
+ When('I look at the posts') do
32
32
  visit '/posts'
33
33
  end
34
- Then /^I should see the public error page$/ do
34
+ Then('I should see the public error page') do
35
35
  expect(page).to have_content "We're sorry, but something went wrong."
36
36
  end
37
37
  """
@@ -44,7 +44,7 @@ Feature: Allow Cucumber to rescue exceptions
44
44
  """
45
45
 
46
46
  Scenario: Don't allow rescue
47
- Given I write to "features/posts.feature" with:
47
+ When I write to "features/posts.feature" with:
48
48
  """
49
49
  Feature: posts
50
50
  Scenario: See them
@@ -52,7 +52,7 @@ Feature: Allow Cucumber to rescue exceptions
52
52
  """
53
53
  And I write to "features/step_definitions/posts_steps.rb" with:
54
54
  """
55
- When /^I look at the posts$/ do
55
+ When('I look at the posts') do
56
56
  visit '/posts'
57
57
  end
58
58
  """
@@ -5,8 +5,8 @@ Feature: Annotations
5
5
  I should be able to list annotations in my features
6
6
 
7
7
  Background:
8
- Given I have created a new Rails app "test-app" with no database and installed cucumber-rails
9
- And I write to "features/tests.feature" with:
8
+ Given I have created a new Rails app with no database and installed cucumber-rails
9
+ When I write to "features/tests.feature" with:
10
10
  """
11
11
  Feature: Tests
12
12
  Scenario: Tests
@@ -4,37 +4,28 @@ Feature: Capybara Javascript Drivers
4
4
  Background: A simple calendar app
5
5
  Given I have created a new Rails app and installed cucumber-rails
6
6
  And I force selenium to run Firefox in headless mode
7
- And I run `bundle exec rails g scaffold appointment name:string when:datetime`
7
+ When I run `bundle exec rails g scaffold appointment name:string when:datetime`
8
8
  And I write to "features/step_definitions/date_time_steps.rb" with:
9
9
  """
10
- When /^(?:|I )select "([^"]+)" as the "([^"]+)" time$/ do |time, selector|
11
- select_time(time, from: selector)
12
- end
13
-
14
- When /^(?:|I )select "([^"]+)" as the "([^"]+)" date$/ do |date, selector|
15
- select_date(date, from: selector)
16
- end
17
-
18
- When /^(?:|I )select "([^"]+)" as the "([^"]+)" date and time$/ do |datetime, selector|
10
+ When('I select {string} as the {string} date and time') do |datetime, selector|
19
11
  select_datetime(datetime, from: selector)
20
12
  end
21
13
  """
22
14
 
23
15
  Scenario: Use a particular driver
24
- Given I write to "features/create_appointment.feature" with:
16
+ When I write to "features/create_appointment.feature" with:
25
17
  """
26
18
  @javascript
27
19
  Feature: Create appointments
28
- Scenario: Constitution on May 17
20
+ Scenario: Visit the Constitution on May 17
29
21
  Given I am on the new appointment page
30
22
  And I fill in "Norway's constitution" for "Name"
31
23
  And I select "2015-02-20 15:10:00 UTC" as the "When" date and time
32
24
  And I press "Create Appointment"
33
25
  Then I should see "Norway's constitution"
34
26
  And I should see "2015-02-20 15:10:00 UTC"
35
-
36
27
  """
37
- When I run `bundle exec rake db:migrate`
28
+ And I run `bundle exec rake db:migrate`
38
29
  And I run `bundle exec rake cucumber`
39
30
  Then the feature run should pass with:
40
31
  """
@@ -43,28 +34,26 @@ Feature: Capybara Javascript Drivers
43
34
  """
44
35
 
45
36
  Scenario: Mixed DB access
46
- Given I write to "features/create_appointment.feature" with:
37
+ When I write to "features/create_appointment.feature" with:
47
38
  """
48
39
  @javascript
49
40
  Feature: Create appointments
50
- Scenario: Constitution on May 17
41
+ Scenario: Visit the Constitution on May 17
51
42
  Given a random appointment
52
- And I am viewing random appointment
43
+ And I am viewing a random appointment
53
44
  Then I should see "Random appointment"
54
-
55
45
  """
56
46
  And I write to "features/step_definitions/custom_steps.rb" with:
57
47
  """
58
- Given /^a random appointment$/ do
48
+ Given('a random appointment') do
59
49
  @appointment = Appointment.create!(name: 'Random appointment', when: DateTime.now)
60
50
  end
61
51
 
62
- Given /^I am viewing random appointment$/ do
52
+ Given('I am viewing a random appointment') do
63
53
  visit appointment_path(@appointment)
64
54
  end
65
55
  """
66
-
67
- When I run `bundle exec rake db:migrate`
56
+ And I run `bundle exec rake db:migrate`
68
57
  And I run `bundle exec rake cucumber`
69
58
  Then the feature run should pass with:
70
59
  """
@@ -1,6 +1,6 @@
1
1
  Feature: Choose javascript database strategy
2
2
 
3
- When running a scenario with the @javascript tag, Capybara will fire up a web server
3
+ Whilst running a scenario with the @javascript tag, Capybara will fire up a web server
4
4
  in the same process in a separate thread to your cukes. By default, this means ActiveRecord will give it a
5
5
  separate database connection, which in turn means data you put into your database from
6
6
  Cucumber step definitions (e.g. using FactoryBot) won't be visible to the web server
@@ -26,9 +26,23 @@ Feature: Choose javascript database strategy
26
26
  Background:
27
27
  Given I have created a new Rails app and installed cucumber-rails
28
28
  And I have a "Widget" ActiveRecord model object
29
+ When I write to "features/step_definitions/widget_steps.rb" with:
30
+ """
31
+ When('I create {int} widgets') do |number|
32
+ number.times { Widget.create! }
33
+ end
34
+
35
+ Then('I should have {int} widgets') do |number|
36
+ expect(Widget.count).to eq(number)
37
+ end
38
+
39
+ Then('the DatabaseCleaner strategy should be {word}') do |strategy_name|
40
+ expect(DatabaseCleaner.connections.first.strategy.to_s).to match(/#{strategy_name}/i)
41
+ end
42
+ """
29
43
 
30
44
  Scenario: Set the strategy to truncation and run a javascript scenario.
31
- Given I append to "features/env.rb" with:
45
+ When I append to "features/env.rb" with:
32
46
  """
33
47
  DatabaseCleaner.strategy = :transaction
34
48
  Cucumber::Rails::Database.javascript_strategy = :truncation
@@ -37,13 +51,13 @@ Feature: Choose javascript database strategy
37
51
  """
38
52
  Feature:
39
53
  Background:
40
- Given I have created 2 widgets
54
+ When I create 2 widgets
41
55
 
42
56
  @javascript
43
57
  Scenario:
44
- Then the DatabaseCleaner strategy should be truncation
45
58
  When I create 3 widgets
46
- Then I should have 5 widgets
59
+ Then the DatabaseCleaner strategy should be truncation
60
+ And I should have 5 widgets
47
61
 
48
62
  @javascript
49
63
  Scenario:
@@ -54,29 +68,15 @@ Feature: Choose javascript database strategy
54
68
  Then the DatabaseCleaner strategy should be transaction
55
69
  And I should have 2 widgets
56
70
  """
57
- And I write to "features/step_definitions/widget_steps.rb" with:
71
+ And I run the cukes
72
+ Then the feature run should pass with:
58
73
  """
59
- Given /created? (\d) widgets/ do |num|
60
- num.to_i.times { Widget.create! }
61
- end
62
-
63
- Then /should have (\d) widgets/ do |num|
64
- Widget.count.should == num.to_i
65
- end
66
-
67
- Then /^the DatabaseCleaner strategy should be (\w+)$/ do |strategy_name|
68
- DatabaseCleaner.connections.first.strategy.to_s.should =~ /#{strategy_name}/i
69
- end
74
+ 3 scenarios (3 passed)
75
+ 10 steps (10 passed)
70
76
  """
71
- When I run the cukes
72
- Then the feature run should pass with:
73
- """
74
- 3 scenarios (3 passed)
75
- 10 steps (10 passed)
76
- """
77
77
 
78
- Scenario: Set the strategy to deletion and run a javascript scenario.
79
- Given I append to "features/env.rb" with:
78
+ Scenario: Set the strategy to deletion and run a javascript scenario.
79
+ When I append to "features/env.rb" with:
80
80
  """
81
81
  Cucumber::Rails::Database.javascript_strategy = :deletion
82
82
  """
@@ -85,7 +85,7 @@ Feature: Choose javascript database strategy
85
85
  @javascript
86
86
  Feature:
87
87
  Background:
88
- Given I have created 2 widgets
88
+ When I create 2 widgets
89
89
 
90
90
  Scenario:
91
91
  When I create 3 widgets
@@ -94,27 +94,17 @@ Feature: Choose javascript database strategy
94
94
  Scenario:
95
95
  Then I should have 2 widgets
96
96
  """
97
- And I write to "features/step_definitions/widget_steps.rb" with:
97
+ And I run the cukes
98
+ Then the feature run should pass with:
98
99
  """
99
- Given /created? (\d) widgets/ do |num|
100
- num.to_i.times { Widget.create! }
101
- end
102
-
103
- Then /should have (\d) widgets/ do |num|
104
- Widget.count.should == num.to_i
105
- end
100
+ 2 scenarios (2 passed)
101
+ 5 steps (5 passed)
106
102
  """
107
- When I run the cukes
108
- Then the feature run should pass with:
109
- """
110
- 2 scenarios (2 passed)
111
- 5 steps (5 passed)
112
- """
113
103
 
114
104
  Scenario: Set the strategy to truncation with an except option and run a javascript scenario.
115
- Given I append to "features/env.rb" with:
105
+ When I append to "features/env.rb" with:
116
106
  """
117
- Cucumber::Rails::Database.javascript_strategy = :truncation, {:except=>%w[widgets]}
107
+ Cucumber::Rails::Database.javascript_strategy = :truncation, { except: %w[widgets] }
118
108
  """
119
109
  And I write to "features/widgets.feature" with:
120
110
  """
@@ -127,19 +117,9 @@ Feature: Choose javascript database strategy
127
117
  Scenario:
128
118
  Then I should have 3 widgets
129
119
  """
130
- And I write to "features/step_definitions/widget_steps.rb" with:
120
+ And I run the cukes
121
+ Then the feature run should pass with:
131
122
  """
132
- Given /created? (\d) widgets/ do |num|
133
- num.to_i.times { Widget.create! }
134
- end
135
-
136
- Then /should have (\d) widgets/ do |num|
137
- Widget.count.should == num.to_i
138
- end
123
+ 2 scenarios (2 passed)
124
+ 3 steps (3 passed)
139
125
  """
140
- When I run the cukes
141
- Then the feature run should pass with:
142
- """
143
- 2 scenarios (2 passed)
144
- 3 steps (3 passed)
145
- """
@@ -2,10 +2,10 @@ Feature: DatabaseCleaner
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: some widgets
9
9
  Given I have 2 widgets
10
10
 
11
11
  Scenario: Add 3
@@ -19,26 +19,26 @@ Feature: DatabaseCleaner
19
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|
22
+ Given('I have {int} widgets') do |number|
23
+ number.times do |i|
24
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|
28
+ When('I create {int} more widgets') do |number|
29
+ number.times do |i|
30
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
  """
@@ -30,26 +30,20 @@ Feature: Disable automatic database cleaning
30
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|
33
+ When('I create {int} widgets') do |number|
34
+ number.times do |i|
35
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
+ """