cucumber-rails 1.7.0 → 1.8.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 (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
@@ -3,7 +3,7 @@ Feature: Emulate Javascript
3
3
  Scenario: See a widget
4
4
  Given I have created a new Rails app and installed cucumber-rails
5
5
  And I force selenium to run Firefox in headless mode
6
- And I run `rails generate scaffold widget name:string`
6
+ When I run `rails generate scaffold widget name:string`
7
7
  And I write to "features/f.feature" with:
8
8
  """
9
9
  @javascript
@@ -15,7 +15,7 @@ Feature: Emulate Javascript
15
15
  """
16
16
  And I write to "features/step_definitions/s.rb" with:
17
17
  """
18
- Given /^there is a widget named "([^"]*)"$/ do |name|
18
+ Given('there is a widget named {string}') do |name|
19
19
  FactoryBot.create(:widget, name: name)
20
20
  end
21
21
  """
@@ -27,17 +27,17 @@ Feature: Emulate Javascript
27
27
  end
28
28
  end
29
29
  """
30
- When I run `bundle exec rake db:migrate`
30
+ And I run `bundle exec rake db:migrate`
31
31
  And I run `bundle exec rake cucumber`
32
32
  Then the feature run should pass with:
33
- """
34
- 1 scenario (1 passed)
35
- 3 steps (3 passed)
36
- """
33
+ """
34
+ 1 scenario (1 passed)
35
+ 3 steps (3 passed)
36
+ """
37
37
 
38
38
  Scenario: Pass on the CSRF token
39
39
  Given I have created a new Rails app and installed cucumber-rails
40
- And I run `rails generate scaffold widget name:string`
40
+ When I run `rails generate scaffold widget name:string`
41
41
  And I run `sed -i -e 's/forgery_protection *= false/forgery_protection = true/' config/environments/test.rb`
42
42
  And I run `rails generate controller session establish`
43
43
  And I write to "app/controllers/session_controller.rb" with:
@@ -52,8 +52,9 @@ Feature: Emulate Javascript
52
52
  """
53
53
  class ApplicationController < ActionController::Base
54
54
  protect_from_forgery
55
+
55
56
  before_action except: :establish do
56
- render text: "denied", status: :forbidden and return false unless session[:verified]
57
+ render text: 'denied', status: :forbidden and return false unless session[:verified]
57
58
  end
58
59
  end
59
60
  """
@@ -72,7 +73,7 @@ Feature: Emulate Javascript
72
73
  """
73
74
  And I write to "features/step_definitions/s.rb" with:
74
75
  """
75
- Given /^there is a widget named "([^"]*)"$/ do |name|
76
+ Given('there is a widget named {string}') do |name|
76
77
  FactoryBot.create(:widget, name: name)
77
78
  end
78
79
  """
@@ -84,11 +85,10 @@ Feature: Emulate Javascript
84
85
  end
85
86
  end
86
87
  """
87
- When I run `bundle exec rake db:migrate`
88
+ And I run `bundle exec rake db:migrate`
88
89
  And I run `bundle exec rake cucumber`
89
90
  Then the feature run should pass with:
90
- """
91
- 1 scenario (1 passed)
92
- 8 steps (8 passed)
93
- """
94
-
91
+ """
92
+ 1 scenario (1 passed)
93
+ 8 steps (8 passed)
94
+ """
@@ -1,11 +1,10 @@
1
1
  Feature: No Database
2
2
  Allow Cucumber to work with a Rails app without a database
3
3
 
4
- @fails-on-travis
5
4
  Scenario: No ActiveRecord and DatabaseCleaner
6
5
  Given I have created a new Rails app with no database and installed cucumber-rails
7
6
  # Turn off ActiveRecord
8
- And I write to "config/application.rb" with:
7
+ When I write to "config/application.rb" with:
9
8
  """
10
9
  require File.expand_path('../boot', __FILE__)
11
10
 
@@ -17,7 +16,7 @@ Feature: No Database
17
16
 
18
17
  module TestApp
19
18
  class Application < Rails::Application
20
- config.encoding = "utf-8"
19
+ config.encoding = 'utf-8'
21
20
  config.filter_parameters += [:password]
22
21
  end
23
22
  end
@@ -32,7 +31,7 @@ Feature: No Database
32
31
  """
33
32
  class PostsController < ApplicationController
34
33
  def index
35
- raise "There is an error in index"
34
+ raise 'There is an error in index'
36
35
  end
37
36
  end
38
37
  """
@@ -46,11 +45,11 @@ Feature: No Database
46
45
  """
47
46
  Feature: posts
48
47
  Scenario: See them
49
- When I do it
48
+ When I view the posts
50
49
  """
51
50
  And I write to "features/step_definitions/posts_steps.rb" with:
52
51
  """
53
- When /^I do it$/ do
52
+ When('I view the posts') do
54
53
  visit '/posts'
55
54
  end
56
55
  """
@@ -1,8 +1,8 @@
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/tests.feature" with:
6
6
  """
7
7
  Feature: Tests
8
8
  Scenario: Tests
@@ -24,15 +24,15 @@ Feature: Rerun profile
24
24
  """
25
25
  And a file named "features/step_definitions/rerun_steps.rb" with:
26
26
  """
27
- Given /fixed now/ do
28
- puts "All fixed now"
27
+ Given('fixed now') do
28
+ puts 'All fixed now'
29
29
  end
30
30
 
31
- Given /broken/ do
31
+ Given('broken') do
32
32
  raise "I'm broken"
33
33
  end
34
34
 
35
- Given /passing/ do
35
+ Given('passing') do
36
36
  puts "I've always been passing"
37
37
  end
38
38
  """
@@ -1,8 +1,8 @@
1
1
  Feature: REST API
2
2
 
3
3
  Scenario: Compare JSON
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
@@ -12,7 +12,7 @@ Feature: REST API
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
  """
@@ -30,18 +30,18 @@ Feature: REST API
30
30
  """
31
31
  And I write to "features/step_definitions/rest_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
+ """
@@ -1,124 +1,43 @@
1
- module CucumberRailsHelper
2
- def rails_new(options = {})
3
- options[:name] ||= 'test_app'
4
- command = run "bundle exec rails new #{options[:name]} --skip-bundle --skip-test-unit --skip-spring #{options[:args]}"
5
- expect(command).to have_output /README/
6
- expect(last_command_started).to be_successfully_executed
7
- cd options[:name]
8
- delete_environment_variable 'RUBYOPT'
9
- delete_environment_variable 'BUNDLE_BIN_PATH'
10
- delete_environment_variable 'BUNDLE_GEMFILE'
11
- end
12
-
13
- def install_cucumber_rails(*options)
14
- if options.include?(:not_in_test_group)
15
- gem 'cucumber-rails', path: "#{File.expand_path('.')}"
16
- else
17
- gem 'cucumber-rails' , group: :test, require: false, path: "#{File.expand_path('.')}"
18
- end
19
-
20
- gem 'sqlite3', '~> 1.3.13'
21
- if RUBY_VERSION < '2.4.0'
22
- gem 'capybara', '< 3.16.0', group: :test
23
- else
24
- gem 'capybara', group: :test
25
- end
26
- gem 'selenium-webdriver', '~> 3.11', group: :test
27
-
28
- gem 'rspec-expectations', '~> 3.7', group: :test
29
- gem 'database_cleaner', '>= 1.1', group: :test unless options.include?(:no_database_cleaner)
30
- gem 'factory_bot', '>= 3.2', group: :test unless options.include?(:no_factory_bot)
31
- run_simple 'bundle install'
32
-
33
- if `bundle exec rails -v`.split("\n").last.strip =~ /\ARails 6\./
34
- run_simple 'bundle exec rails webpacker:install'
35
- end
36
-
37
- run_simple 'bundle exec rails generate cucumber:install'
38
- end
39
-
40
- def gem(name, *args)
41
- options = args.last.is_a?(Hash) ? args.pop : {}
42
-
43
- parts = ["'#{name}'"]
44
- parts << args.map(&:inspect) if args.any?
45
- parts << options.inspect[1..-2] if options.any?
46
-
47
- line = "gem #{parts.join(', ')}\n"
48
-
49
- gem_regexp = /gem ["']#{name}["'].*$/
50
- gemfile_content = File.read(expand_path('Gemfile'))
51
-
52
- if gemfile_content =~ gem_regexp
53
- gemfile_content.gsub!(gem_regexp, line)
54
- overwrite_file('Gemfile', gemfile_content)
55
- else
56
- append_to_file('Gemfile', line)
57
- end
58
- end
1
+ # frozen_string_literal: true
59
2
 
60
- def prepare_aruba_report
61
- if(ENV['ARUBA_REPORT_DIR'])
62
- @aruba_report_start = Time.new
63
- sleep(1)
64
- end
65
- end
66
-
67
- def fixture(path)
68
- File.expand_path(File.dirname(__FILE__) + "./../support/fixtures/#{path}")
69
- end
70
- end
71
- World(CucumberRailsHelper)
72
-
73
- Given /^I have created a new Rails app and installed cucumber\-rails, accidentally outside of the test group in my Gemfile$/ do
3
+ Given('I have created a new Rails app and installed cucumber-rails, accidentally outside of the test group in my Gemfile') do
74
4
  rails_new
75
5
  install_cucumber_rails :not_in_test_group
76
6
  create_web_steps
77
- prepare_aruba_report
78
- end
79
-
80
- Given /^I have created a new Rails app "([^"]*)" and installed cucumber\-rails$/ do |app_name|
81
- rails_new name: app_name
82
- install_cucumber_rails
83
- create_web_steps
84
- prepare_aruba_report
85
7
  end
86
8
 
87
- Given /^I have created a new Rails app and installed cucumber\-rails$/ do
9
+ Given('I have created a new Rails app and installed cucumber-rails') do
88
10
  rails_new
89
11
  install_cucumber_rails
90
12
  create_web_steps
91
- prepare_aruba_report
92
13
  end
93
14
 
94
- Given /^I have created a new Rails app with no database and installed cucumber-rails$/ do
15
+ Given('I have created a new Rails app with no database and installed cucumber-rails') do
95
16
  rails_new args: '--skip-active-record'
96
17
  install_cucumber_rails :no_database_cleaner, :no_factory_bot
97
18
  overwrite_file('features/support/env.rb', "require 'cucumber/rails'\n")
98
19
  create_web_steps
99
20
  end
100
21
 
101
- Given /^I have created a new Rails app "(.*?)" with no database and installed cucumber\-rails$/ do |app_name|
102
- rails_new name: app_name, args: '--skip-active-record'
103
- install_cucumber_rails :no_database_cleaner, :no_factory_bot
104
- overwrite_file('features/support/env.rb', "require 'cucumber/rails'\n")
105
- create_web_steps
106
- end
107
-
108
- Given /^I have a "([^"]*)" ActiveRecord model object$/ do |name|
109
- run_simple("bundle exec rails g model #{name}")
110
- run_simple('bundle exec rake db:migrate RAILS_ENV=test')
22
+ Given('I have a {string} ActiveRecord model object') do |name|
23
+ run_command_and_stop("bundle exec rails g model #{name}")
24
+ run_command_and_stop('bundle exec rake db:migrate RAILS_ENV=test')
111
25
  end
112
26
 
113
- Given /^I force selenium to run Firefox in headless mode$/ do
27
+ Given('I force selenium to run Firefox in headless mode') do
114
28
  selenium_config = %{
115
29
  Capybara.register_driver :selenium do |app|
116
30
  http_client = Selenium::WebDriver::Remote::Http::Default.new
117
31
  http_client.read_timeout = 180
118
32
 
119
- browser_options = ::Selenium::WebDriver::Firefox::Options.new()
33
+ browser_options = Selenium::WebDriver::Firefox::Options.new
120
34
  browser_options.args << '--headless'
121
- Capybara::Selenium::Driver.new(app, browser: :firefox, options: browser_options, http_client: http_client)
35
+ Capybara::Selenium::Driver.new(
36
+ app,
37
+ browser: :firefox,
38
+ options: browser_options,
39
+ http_client: http_client
40
+ )
122
41
  end
123
42
 
124
43
  Capybara.server = :webrick
@@ -127,25 +46,25 @@ Given /^I force selenium to run Firefox in headless mode$/ do
127
46
  step 'I append to "features/support/env.rb" with:', selenium_config
128
47
  end
129
48
 
130
- When /^I run the cukes$/ do
131
- run_simple('bundle exec cucumber')
49
+ When('I run the cukes') do
50
+ run_command_and_stop('bundle exec cucumber')
132
51
  end
133
52
 
134
53
  # Copied from Aruba
135
- Then /^the feature run should pass with:$/ do |string|
54
+ Then(/^the feature run should pass with:$/) do |string|
136
55
  step 'the output should not contain " failed)"'
137
56
  step 'the output should not contain " undefined)"'
138
57
  step 'the exit status should be 0'
139
58
  step 'the output should contain:', string
140
59
  end
141
60
 
142
- Given("I remove the {string} gem from the Gemfile") do |gem_name|
61
+ Given('I remove the {string} gem from the Gemfile') do |gem_name|
143
62
  content = File.open(expand_path('Gemfile'), 'r').readlines
144
63
  new_content = []
145
64
 
146
65
  content.each do |line|
147
66
  next if line =~ /gem ["|']#{gem_name}["|'].*/
148
-
67
+
149
68
  new_content << line
150
69
  end
151
70
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Aruba.configure do |config|
2
4
  config.exit_timeout = 120
3
5
  end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CucumberRailsHelper
4
+ def rails_new(options = {})
5
+ options[:name] ||= 'test_app'
6
+ command_result =
7
+ run_command "bundle exec rails new #{options[:name]} --skip-bundle --skip-test-unit --skip-spring --skip-bootsnap #{options[:args]}"
8
+ expect(command_result).to have_output(/README/)
9
+ expect(last_command_started).to be_successfully_executed
10
+ cd options[:name]
11
+ delete_environment_variable 'RUBYOPT'
12
+ delete_environment_variable 'BUNDLE_BIN_PATH'
13
+ delete_environment_variable 'BUNDLE_GEMFILE'
14
+ end
15
+
16
+ def install_cucumber_rails(*options)
17
+ add_conditional_gems(options)
18
+
19
+ gem 'selenium-webdriver', '~> 3.11', group: :test
20
+ gem 'rspec-expectations', '~> 3.7', group: :test
21
+ gem 'database_cleaner', '>= 1.1', group: :test unless options.include?(:no_database_cleaner)
22
+ gem 'factory_bot', '>= 3.2', group: :test unless options.include?(:no_factory_bot)
23
+
24
+ run_command_and_stop 'bundle install'
25
+ run_command_and_stop 'bundle exec rails webpacker:install' if rails6?
26
+ run_command_and_stop 'bundle exec rails generate cucumber:install'
27
+ end
28
+
29
+ def gem(name, *args)
30
+ options = args.last.is_a?(Hash) ? args.pop : {}
31
+
32
+ parts = ["'#{name}'"]
33
+ parts << args.map(&:inspect) if args.any?
34
+ parts << options.inspect[1..-2] if options.any?
35
+
36
+ line = "gem #{parts.join(', ')}\n"
37
+
38
+ gem_regexp = /gem ["']#{name}["'].*$/
39
+ gemfile_content = File.read(expand_path('Gemfile'))
40
+
41
+ if gemfile_content =~ gem_regexp
42
+ gemfile_content.gsub!(gem_regexp, line)
43
+ overwrite_file('Gemfile', gemfile_content)
44
+ else
45
+ append_to_file('Gemfile', line)
46
+ end
47
+ end
48
+
49
+ def fixture(path)
50
+ File.expand_path(File.dirname(__FILE__) + "./../support/fixtures/#{path}")
51
+ end
52
+
53
+ private
54
+
55
+ def rails6?
56
+ `bundle exec rails -v`.start_with?('Rails 6')
57
+ end
58
+
59
+ def add_conditional_gems(options)
60
+ if options.include?(:not_in_test_group)
61
+ gem 'cucumber-rails', path: File.expand_path('.').to_s
62
+ else
63
+ gem 'cucumber-rails', group: :test, require: false, path: File.expand_path('.').to_s
64
+ end
65
+
66
+ if rails6?
67
+ gem 'sqlite3', '~> 1.4'
68
+ else
69
+ gem 'sqlite3', '~> 1.3.13'
70
+ end
71
+
72
+ if RUBY_VERSION < '2.4.0'
73
+ gem 'capybara', '< 3.16.0', group: :test
74
+ else
75
+ gem 'capybara', group: :test
76
+ end
77
+ end
78
+ end
79
+
80
+ World(CucumberRailsHelper)