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
@@ -1,40 +1,14 @@
1
- $:.unshift(File.dirname(__FILE__) + '/../../lib')
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
4
  require 'rubygems'
3
5
  require 'bundler/setup'
4
6
  require 'rspec/expectations'
5
7
  require 'aruba/cucumber'
6
8
 
7
- if(ENV['ARUBA_REPORT_DIR'])
8
- # Override reporting behaviour so we don't document all files, only the ones
9
- # that have been created after @aruba_report_start (a Time object). This is
10
- # given a value after the Rails app is generated (see cucumber_rails_steps.rb)
11
- module Aruba
12
- module Reporting
13
- def children(dir)
14
- children = Dir["#{dir}/*"].sort
15
-
16
- # include
17
- children = children.select do |child|
18
- File.directory?(child) ||
19
- (@aruba_report_start && File.stat(child).mtime > @aruba_report_start)
20
- end
21
-
22
- # exclude
23
- children = children.reject do |child|
24
- child =~ /Gemfile/ ||
25
- child =~ /\.log$/
26
- end
27
-
28
- children
29
- end
30
- end
31
- end
32
- end
33
-
34
9
  After do |scenario|
35
10
  if scenario.failed?
36
11
  puts last_command_stopped.stdout
37
12
  puts last_command_stopped.stderr
38
13
  end
39
- end
40
-
14
+ end
@@ -283,7 +283,7 @@ module NavigationHelpers
283
283
  end
284
284
 
285
285
  World(NavigationHelpers)
286
- EOF
286
+ EOF
287
287
  end
288
288
  end
289
289
  World(WebSteps)
@@ -2,9 +2,9 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "railties", "~> 4.2.1"
6
- gem "i18n", "< 1.5.1", platform: :mri_22
7
- gem "capybara", "< 3.16.0", platform: [:mri_23, :mri_22]
8
- gem "nokogiri", "< 1.9.1", platform: [:mri_23, :mri_22]
5
+ gem "capybara", "< 3.16.0", platform: :mri_23
6
+ gem "nokogiri", "< 1.9.1", platform: :mri_23
7
+ gem "railties", "~> 4.2.11"
8
+ gem "sqlite3", "~> 1.3.13"
9
9
 
10
10
  gemspec path: "../"
@@ -2,9 +2,9 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "railties", "~> 5.0.0"
6
- gem "i18n", "< 1.5.1", platform: :mri_22
7
- gem "capybara", "< 3.16.0", platform: [:mri_23, :mri_22]
8
- gem "nokogiri", "< 1.9.1", platform: [:mri_23, :mri_22]
5
+ gem "capybara", "< 3.16.0", platform: :mri_23
6
+ gem "nokogiri", "< 1.9.1", platform: :mri_23
7
+ gem "railties", "~> 5.0.7"
8
+ gem "sqlite3", "~> 1.3.13"
9
9
 
10
10
  gemspec path: "../"
@@ -2,9 +2,9 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
+ gem "capybara", "< 3.16.0", platform: :mri_23
6
+ gem "nokogiri", "< 1.9.1", platform: :mri_23
5
7
  gem "railties", "~> 5.1.0"
6
- gem "i18n", "< 1.5.1", platform: :mri_22
7
- gem "capybara", "< 3.16.0", platform: [:mri_23, :mri_22]
8
- gem "nokogiri", "< 1.9.1", platform: [:mri_23, :mri_22]
8
+ gem "sqlite3", "~> 1.3.13"
9
9
 
10
10
  gemspec path: "../"
@@ -2,9 +2,9 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "railties", "~> 5.2"
6
- gem "i18n", "< 1.5.1", platform: :mri_22
7
- gem "capybara", "< 3.16.0", platform: [:mri_23, :mri_22]
8
- gem "nokogiri", "< 1.9.1", platform: [:mri_23, :mri_22]
5
+ gem "capybara", "< 3.16.0", platform: :mri_23
6
+ gem "nokogiri", "< 1.9.1", platform: :mri_23
7
+ gem "railties", "~> 5.2.3"
8
+ gem "sqlite3", "~> 1.3.13"
9
9
 
10
10
  gemspec path: "../"
@@ -2,7 +2,8 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "railties", "~> 6.0.0.beta1"
6
- gem "rails", "~> 6.0.0.beta1"
5
+ gem "railties", "~> 6.0.0.rc2"
6
+ gem "rails", "~> 6.0.0.rc2"
7
+ gem "sqlite3", "~> 1.4"
7
8
 
8
9
  gemspec path: "../"
@@ -1,5 +1,10 @@
1
- env_caller = File.dirname(caller.detect{ |f| f =~ /\/env\.rb:/ }) if caller.detect{ |f| f =~ /\/env\.rb:/ }
2
- if env_caller
1
+ # frozen_string_literal: true
2
+
3
+ called_from_env_rb = caller.detect { |f| f =~ /\/env\.rb:/ }
4
+
5
+ if called_from_env_rb
6
+ env_caller = File.dirname(called_from_env_rb)
7
+
3
8
  require 'rails'
4
9
  require 'cucumber/rails/application'
5
10
  ENV['RAILS_ENV'] ||= 'test'
@@ -15,7 +20,9 @@ if env_caller
15
20
  end
16
21
 
17
22
  unless Rails.application.config.cache_classes
18
- warn "WARNING: You have set Rails' config.cache_classes to false (most likely in config/environments/cucumber.rb). This setting is known to cause problems with database transactions. Set config.cache_classes to true if you want to use transactions."
23
+ warn "WARNING: You have set Rails' config.cache_classes to false
24
+ (most likely in config/environments/cucumber.rb). This setting is known to cause problems
25
+ with database transactions. Set config.cache_classes to true if you want to use transactions."
19
26
  end
20
27
 
21
28
  require 'cucumber/rails/world'
@@ -25,7 +32,8 @@ if env_caller
25
32
 
26
33
  MultiTest.disable_autorun
27
34
  else
28
- warn "WARNING: Cucumber-rails required outside of env.rb. The rest of loading is being deferred until env.rb is called.
29
- To avoid this warning, move 'gem \'cucumber-rails\', require: false' under only group :test in your Gemfile.
30
- If already in the :test group, be sure you are specifying 'require: false'."
35
+ warn "WARNING: Cucumber-rails required outside of env.rb. The rest of loading is being deferred
36
+ until env.rb is called. To avoid this warning, move 'gem \'cucumber-rails\', require: false'
37
+ under only group :test in your Gemfile. If already in the :test group, be sure you are
38
+ specifying 'require: false'."
31
39
  end
@@ -1,13 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ActionController::Base.class_eval do
2
4
  cattr_accessor :allow_rescue
3
5
  end
4
6
 
5
- class ActionDispatch::ShowExceptions
6
- alias __cucumber_orig_call__ call
7
+ module ActionDispatch
8
+ class ShowExceptions
9
+ alias __cucumber_orig_call__ call
7
10
 
8
- def call(env)
9
- env['action_dispatch.show_exceptions'] = !!ActionController::Base.allow_rescue
10
- env['action_dispatch.show_detailed_exceptions'] = !ActionController::Base.allow_rescue
11
- __cucumber_orig_call__(env)
11
+ def call(env)
12
+ env['action_dispatch.show_exceptions'] = !!ActionController::Base.allow_rescue
13
+ env['action_dispatch.show_detailed_exceptions'] = !ActionController::Base.allow_rescue
14
+ __cucumber_orig_call__(env)
15
+ end
12
16
  end
13
17
  end
@@ -1,17 +1,23 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails/application'
2
4
 
3
5
  # Make sure the ActionDispatch::ShowExceptions middleware is always enabled,
4
6
  # regardless of what is in config/environments/test.rb
5
7
  # Instead we are overriding ActionDispatch::ShowExceptions to be able to
6
8
  # toggle whether or not exceptions are raised.
7
- class Rails::Application
8
- alias __cucumber_orig_initialize__ initialize!
9
9
 
10
- def initialize!
11
- ad = config.action_dispatch
12
- def ad.show_exceptions
13
- true
10
+ module Rails
11
+ class Application
12
+ alias __cucumber_orig_initialize__ initialize!
13
+
14
+ def initialize!
15
+ ad = config.action_dispatch
16
+
17
+ def ad.show_exceptions
18
+ true
19
+ end
20
+ __cucumber_orig_initialize__
14
21
  end
15
- __cucumber_orig_initialize__
16
22
  end
17
23
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'capybara'
2
4
  require 'capybara/rails'
3
5
  require 'capybara/cucumber'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Cucumber
2
4
  module Rails
3
5
  module Capybara
@@ -11,7 +13,9 @@ module Cucumber
11
13
 
12
14
  def click_with_javascript_emulation(*)
13
15
  if link_with_non_get_http_method?
14
- ::Capybara::RackTest::Form.new(driver, js_form(element_node.document, self[:href], emulated_method)).submit(self)
16
+ ::Capybara::RackTest::Form.new(
17
+ driver, js_form(element_node.document, self[:href], emulated_method)
18
+ ).submit(self)
15
19
  else
16
20
  click_without_javascript_emulation
17
21
  end
@@ -44,7 +48,7 @@ module Cucumber
44
48
  js_form['action'] = action
45
49
  js_form['method'] = method
46
50
 
47
- if emulated_method and emulated_method.downcase != method.downcase
51
+ if emulated_method && !emulated_method.casecmp(method).zero?
48
52
  input = document.create_element('input')
49
53
  input['type'] = 'hidden'
50
54
  input['name'] = '_method'
@@ -54,7 +58,7 @@ module Cucumber
54
58
 
55
59
  # rails will wipe the session if the CSRF token is not sent
56
60
  # with non-GET requests
57
- if csrf? && emulated_method.downcase != 'get'
61
+ if csrf? && !emulated_method.casecmp('get').zero?
58
62
  input = document.create_element('input')
59
63
  input['type'] = 'hidden'
60
64
  input['name'] = csrf_param
@@ -66,7 +70,9 @@ module Cucumber
66
70
  end
67
71
 
68
72
  def link_with_non_get_http_method?
69
- tag_name == 'a' && element_node['data-method'] && element_node['data-method'] =~ /(?:delete|put|post)/
73
+ tag_name == 'a' &&
74
+ element_node['data-method'] &&
75
+ element_node['data-method'] =~ /(?:delete|put|post)/
70
76
  end
71
77
 
72
78
  def emulated_method
@@ -74,15 +80,19 @@ module Cucumber
74
80
  end
75
81
 
76
82
  def element_node
77
- self.native
83
+ native
78
84
  end
79
85
  end
80
86
  end
81
87
  end
82
88
  end
83
89
 
84
- class Capybara::RackTest::Node
85
- include ::Cucumber::Rails::Capybara::JavascriptEmulation
90
+ module Capybara
91
+ module RackTest
92
+ class Node
93
+ include ::Cucumber::Rails::Capybara::JavascriptEmulation
94
+ end
95
+ end
86
96
  end
87
97
 
88
98
  Before('not @no-js-emulation') do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Cucumber
2
4
  module Rails
3
5
  module Capybara
@@ -9,7 +11,7 @@ module Cucumber
9
11
  base_dom_id = get_base_dom_id_from_label_tag(options[:from])
10
12
 
11
13
  find(:xpath, ".//select[@id='#{base_dom_id}_1i']").select(date.year.to_s)
12
- find(:xpath, ".//select[@id='#{base_dom_id}_2i']").select(I18n.l date, format: '%B')
14
+ find(:xpath, ".//select[@id='#{base_dom_id}_2i']").select(I18n.l(date, format: '%B'))
13
15
  find(:xpath, ".//select[@id='#{base_dom_id}_3i']").select(date.day.to_s)
14
16
  end
15
17
 
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Cucumber
2
4
  module Rails
3
5
  module Database
4
- CUSTOM_STRATEGY_INTERFACE = %w{ before_js before_non_js }
6
+ CUSTOM_STRATEGY_INTERFACE = %w[before_js before_non_js].freeze
5
7
 
6
8
  class InvalidStrategy < ArgumentError; end
7
9
 
@@ -13,12 +15,12 @@ module Cucumber
13
15
  strategy_type =
14
16
  case strategy
15
17
  when Symbol
16
- map[strategy] || raise(InvalidStrategy, "The strategy '#{strategy}' is not understood. Please use one of #{map.keys.join(',')}")
18
+ map[strategy] || throw_invalid_strategy_error(strategy)
17
19
  when Class
18
20
  strategy
19
21
  end
20
22
 
21
- @strategy = strategy_type.new(*strategy_opts)
23
+ @strategy = strategy_type.new(*strategy_opts)
22
24
 
23
25
  validate_interface!
24
26
  end
@@ -35,7 +37,7 @@ module Cucumber
35
37
  @strategy.after
36
38
  end
37
39
 
38
- private
40
+ private
39
41
 
40
42
  def map
41
43
  {
@@ -46,10 +48,25 @@ module Cucumber
46
48
  }
47
49
  end
48
50
 
51
+ def throw_invalid_strategy_error(strategy)
52
+ raise(InvalidStrategy, "The strategy '#{strategy}' is not understood. Please use one of #{mapped_keys}")
53
+ end
54
+
55
+ def mapped_keys
56
+ map.keys.join(',')
57
+ end
58
+
49
59
  def validate_interface!
50
- unless CUSTOM_STRATEGY_INTERFACE.all? { |m| @strategy.respond_to?(m) }
51
- raise(ArgumentError, "Strategy must respond to all of: #{CUSTOM_STRATEGY_INTERFACE.map{ |method| "##{method}" } * ' ' } !")
52
- end
60
+ return if CUSTOM_STRATEGY_INTERFACE.all? { |m| @strategy.respond_to?(m) }
61
+
62
+ throw_invalid_strategy_interface_error
63
+ end
64
+
65
+ def throw_invalid_strategy_interface_error
66
+ raise(
67
+ ArgumentError,
68
+ "Strategy must respond to all of: #{CUSTOM_STRATEGY_INTERFACE.map { |method| "##{method}" } * ' '} !"
69
+ )
53
70
  end
54
71
  end
55
72
 
@@ -69,6 +86,7 @@ module Cucumber
69
86
 
70
87
  def after
71
88
  return unless @original_strategy
89
+
72
90
  DatabaseCleaner.strategy = @original_strategy
73
91
  @original_strategy = nil
74
92
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cucumber/rails/hooks/active_record'
2
4
  require 'cucumber/rails/hooks/database_cleaner'
3
5
  require 'cucumber/rails/hooks/allow_rescue'
@@ -1,9 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  if defined?(ActiveRecord::Base)
2
- class ActiveRecord::Base
3
- class_attribute :shared_connection
4
+ module ActiveRecord
5
+ class Base
6
+ class_attribute :shared_connection
4
7
 
5
- def self.connection
6
- self.shared_connection || retrieve_connection
8
+ def self.connection
9
+ shared_connection || retrieve_connection
10
+ end
7
11
  end
8
12
  end
9
13
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Before('@allow-rescue') do
2
4
  @__orig_allow_rescue = ActionController::Base.allow_rescue
3
5
  ActionController::Base.allow_rescue = true
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
4
  require 'database_cleaner'
3
5
 
@@ -8,6 +10,6 @@ begin
8
10
  After('not @no-database-cleaner') do
9
11
  DatabaseCleaner.clean if Cucumber::Rails::Database.autorun_database_cleaner
10
12
  end
11
-
12
- rescue LoadError => ignore_if_database_cleaner_not_present
13
+ rescue LoadError
14
+ # database_cleaner gem not present
13
15
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  if defined?(ActionMailer::Base)
2
4
  Before do
3
5
  ActionMailer::Base.deliveries = []
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cucumber/rails/world'
2
4
 
3
5
  begin
@@ -8,7 +10,7 @@ begin
8
10
  include RSpec::Matchers
9
11
  end
10
12
  end
11
- rescue LoadError => try_rspec_1
13
+ rescue LoadError
12
14
  require 'spec/expectations'
13
15
  require 'spec/rails'
14
16
 
@@ -1,21 +1,27 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
4
  # Try to load it so we can assign @_result below if needed.
3
5
  require 'test/unit/testresult'
4
- rescue LoadError => ignore
6
+ rescue LoadError
7
+ # Test Unit not found
5
8
  end
6
9
 
7
- module Cucumber #:nodoc:
8
- module Rails #:nodoc:
9
- class World < ActionDispatch::IntegrationTest #:nodoc:
10
+ module Cucumber
11
+ module Rails
12
+ class World < ActionDispatch::IntegrationTest
10
13
  include Rack::Test::Methods
11
14
  include ActiveSupport::Testing::SetupAndTeardown if ActiveSupport::Testing.const_defined?('SetupAndTeardown')
12
15
 
13
- def initialize #:nodoc:
16
+ def initialize
14
17
  @_result = Test::Unit::TestResult.new if defined?(Test::Unit::TestResult)
15
18
  end
16
19
 
17
20
  unless defined?(ActiveRecord::Base)
18
- def self.fixture_table_names; []; end # Workaround for projects that don't use ActiveRecord
21
+ # Workaround for projects that don't use ActiveRecord
22
+ def self.fixture_table_names
23
+ []
24
+ end
19
25
  end
20
26
  end
21
27
  end