cucumber-rails 1.8.0 → 2.5.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 (74) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +165 -16
  3. data/CONTRIBUTING.md +14 -2
  4. data/LICENSE +1 -1
  5. data/README.md +28 -28
  6. data/lib/cucumber/rails/action_dispatch.rb +21 -0
  7. data/lib/cucumber/rails/application.rb +11 -8
  8. data/lib/cucumber/rails/capybara/javascript_emulation.rb +27 -16
  9. data/lib/cucumber/rails/capybara/select_dates_and_times.rb +28 -13
  10. data/lib/cucumber/rails/database/deletion_strategy.rb +13 -0
  11. data/lib/cucumber/rails/database/null_strategy.rb +15 -0
  12. data/lib/cucumber/rails/database/shared_connection_strategy.rb +27 -0
  13. data/lib/cucumber/rails/database/strategy.rb +35 -0
  14. data/lib/cucumber/rails/database/truncation_strategy.rb +13 -0
  15. data/lib/cucumber/rails/database.rb +9 -58
  16. data/lib/cucumber/rails/hooks/database_cleaner.rb +9 -3
  17. data/lib/cucumber/rails/hooks/mail.rb +1 -1
  18. data/lib/cucumber/rails/world.rb +14 -3
  19. data/lib/cucumber/rails.rb +12 -13
  20. data/lib/generators/cucumber/install_generator.rb +13 -16
  21. data/lib/generators/cucumber/templates/config/cucumber.yml.erb +3 -3
  22. data/lib/generators/cucumber/templates/tasks/cucumber.rake.erb +5 -0
  23. metadata +94 -118
  24. data/.github/ISSUE_TEMPLATE.md +0 -52
  25. data/.github/PULL_REQUEST_TEMPLATE.md +0 -42
  26. data/.gitignore +0 -14
  27. data/.rspec +0 -1
  28. data/.rubocop.yml +0 -36
  29. data/.rubocop_todo.yml +0 -59
  30. data/.travis.yml +0 -60
  31. data/Appraisals +0 -35
  32. data/Gemfile +0 -5
  33. data/Rakefile +0 -53
  34. data/bin/install_geckodriver.sh +0 -19
  35. data/bin/install_webpacker.sh +0 -9
  36. data/config/.gitignore +0 -1
  37. data/config/cucumber.yml +0 -17
  38. data/cucumber-rails.gemspec +0 -44
  39. data/dev_tasks/cucumber.rake +0 -5
  40. data/dev_tasks/rspec.rake +0 -5
  41. data/dev_tasks/yard/default/layout/html/bubble_32x32.png +0 -0
  42. data/dev_tasks/yard/default/layout/html/footer.erb +0 -5
  43. data/dev_tasks/yard/default/layout/html/index.erb +0 -1
  44. data/dev_tasks/yard/default/layout/html/layout.erb +0 -25
  45. data/dev_tasks/yard/default/layout/html/logo.erb +0 -1
  46. data/dev_tasks/yard/default/layout/html/setup.rb +0 -9
  47. data/dev_tasks/yard.rake +0 -36
  48. data/features/allow_rescue.feature +0 -65
  49. data/features/annotations.feature +0 -22
  50. data/features/capybara_javascript_drivers.feature +0 -62
  51. data/features/choose_javascript_database_strategy.feature +0 -125
  52. data/features/database_cleaner.feature +0 -44
  53. data/features/disable_automatic_database_cleaning.feature +0 -49
  54. data/features/emulate_javascript.feature +0 -94
  55. data/features/install_cucumber_rails.feature +0 -14
  56. data/features/no_database.feature +0 -60
  57. data/features/raising_errors.feature +0 -16
  58. data/features/rerun_profile.feature +0 -46
  59. data/features/rest_api.feature +0 -47
  60. data/features/step_definitions/cucumber_rails_steps.rb +0 -72
  61. data/features/support/aruba.rb +0 -5
  62. data/features/support/cucumber_rails_helper.rb +0 -80
  63. data/features/support/env.rb +0 -14
  64. data/features/support/legacy_web_steps_support.rb +0 -289
  65. data/gemfiles/rails_4_2.gemfile +0 -10
  66. data/gemfiles/rails_5_0.gemfile +0 -10
  67. data/gemfiles/rails_5_1.gemfile +0 -10
  68. data/gemfiles/rails_5_2.gemfile +0 -10
  69. data/gemfiles/rails_6_0.gemfile +0 -9
  70. data/lib/cucumber/rails/action_controller.rb +0 -17
  71. data/lib/generators/cucumber/templates/support/rails_spork.rb.erb +0 -13
  72. data/spec/cucumber/rails/database_spec.rb +0 -61
  73. data/spec/generators/cucumber/install_generator_spec.rb +0 -57
  74. data/spec/spec_helper.rb +0 -16
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cucumber
4
+ module Rails
5
+ module Database
6
+ class Strategy
7
+ def initialize(options = {})
8
+ @options = options
9
+ end
10
+
11
+ def before_js(strategy)
12
+ @original_strategy = if defined?(DatabaseCleaner::VERSION) && Gem::Version.new(DatabaseCleaner::VERSION) >= Gem::Version.new('1.8.0.beta')
13
+ raise "No DatabaseCleaner strategies found. Make sure you have required one of DatabaseCleaner's adapters" if DatabaseCleaner.cleaners.empty?
14
+
15
+ DatabaseCleaner.cleaners.values.first.strategy # that feels like a nasty hack
16
+ else
17
+ DatabaseCleaner.connections.first.strategy # that feels like a nasty hack
18
+ end
19
+ DatabaseCleaner.strategy = strategy, @options
20
+ end
21
+
22
+ def before_non_js
23
+ # no-op
24
+ end
25
+
26
+ def after
27
+ return unless @original_strategy
28
+
29
+ DatabaseCleaner.strategy = @original_strategy
30
+ @original_strategy = nil
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cucumber
4
+ module Rails
5
+ module Database
6
+ class TruncationStrategy < Strategy
7
+ def before_js
8
+ super :truncation
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -25,6 +25,11 @@ module Cucumber
25
25
  validate_interface!
26
26
  end
27
27
 
28
+ def default_strategy!
29
+ self.javascript_strategy = :truncation
30
+ self.autorun_database_cleaner = true
31
+ end
32
+
28
33
  def before_js
29
34
  @strategy.before_js
30
35
  end
@@ -44,7 +49,8 @@ module Cucumber
44
49
  truncation: TruncationStrategy,
45
50
  shared_connection: SharedConnectionStrategy,
46
51
  transaction: SharedConnectionStrategy,
47
- deletion: DeletionStrategy
52
+ deletion: DeletionStrategy,
53
+ none: NullStrategy
48
54
  }
49
55
  end
50
56
 
@@ -53,7 +59,7 @@ module Cucumber
53
59
  end
54
60
 
55
61
  def mapped_keys
56
- map.keys.join(',')
62
+ map.keys.join(', ')
57
63
  end
58
64
 
59
65
  def validate_interface!
@@ -70,62 +76,7 @@ module Cucumber
70
76
  end
71
77
  end
72
78
 
73
- class Strategy
74
- def initialize(options = {})
75
- @options = options
76
- end
77
-
78
- def before_js(strategy)
79
- @original_strategy = DatabaseCleaner.connections.first.strategy # that feels like a nasty hack
80
- DatabaseCleaner.strategy = strategy, @options
81
- end
82
-
83
- def before_non_js
84
- # no-op
85
- end
86
-
87
- def after
88
- return unless @original_strategy
89
-
90
- DatabaseCleaner.strategy = @original_strategy
91
- @original_strategy = nil
92
- end
93
- end
94
-
95
- class TruncationStrategy < Strategy
96
- def before_js
97
- super :truncation
98
- end
99
- end
100
-
101
- class DeletionStrategy < Strategy
102
- def before_js
103
- super :deletion
104
- end
105
- end
106
-
107
- class SharedConnectionStrategy < Strategy
108
- def before_js
109
- # Forces all threads to share a connection on a per-model basis,
110
- # as connections may vary per model as per establish_connection. This works
111
- # on Capybara because it starts the web server in a thread.
112
- ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
113
- ActiveRecord::Base.descendants.each do |model|
114
- model.shared_connection = model.connection
115
- end
116
- end
117
-
118
- def before_non_js
119
- # Do not use a shared connection unless we're in a @javascript scenario
120
- ActiveRecord::Base.shared_connection = nil
121
- ActiveRecord::Base.descendants.each do |model|
122
- model.shared_connection = nil
123
- end
124
- end
125
- end
126
-
127
- Database.javascript_strategy = :truncation
128
- Database.autorun_database_cleaner = true
79
+ default_strategy!
129
80
  end
130
81
  end
131
82
  end
@@ -1,8 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  begin
4
- require 'database_cleaner'
4
+ require 'database_cleaner/core'
5
+ rescue LoadError
6
+ begin
7
+ require 'database_cleaner'
8
+ rescue LoadError
9
+ Cucumber.logger.debug('neither database_cleaner v1 or v2 present')
10
+ end
11
+ end
5
12
 
13
+ if defined?(DatabaseCleaner)
6
14
  Before('not @no-database-cleaner') do
7
15
  DatabaseCleaner.start if Cucumber::Rails::Database.autorun_database_cleaner
8
16
  end
@@ -10,6 +18,4 @@ begin
10
18
  After('not @no-database-cleaner') do
11
19
  DatabaseCleaner.clean if Cucumber::Rails::Database.autorun_database_cleaner
12
20
  end
13
- rescue LoadError
14
- # database_cleaner gem not present
15
21
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- if defined?(ActionMailer::Base)
3
+ if defined?(::ActionMailer)
4
4
  Before do
5
5
  ActionMailer::Base.deliveries = []
6
6
  end
@@ -4,13 +4,24 @@ begin
4
4
  # Try to load it so we can assign @_result below if needed.
5
5
  require 'test/unit/testresult'
6
6
  rescue LoadError
7
- # Test Unit not found
7
+ Cucumber.logger.debug('Minitest not found.')
8
8
  end
9
9
 
10
10
  module Cucumber
11
11
  module Rails
12
- class World < ActionDispatch::IntegrationTest
13
- include Rack::Test::Methods
12
+ class << self
13
+ def include_rack_test_helpers?
14
+ # Using ActiveModel Boolean casting here will give false positives more often than not!
15
+ !ENV['CR_REMOVE_RACK_TEST_HELPERS']&.casecmp('true')&.zero?
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ module Cucumber
22
+ module Rails
23
+ class World < ::ActionDispatch::IntegrationTest
24
+ include Rack::Test::Methods if Cucumber::Rails.include_rack_test_helpers?
14
25
  include ActiveSupport::Testing::SetupAndTeardown if ActiveSupport::Testing.const_defined?('SetupAndTeardown')
15
26
 
16
27
  def initialize
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- called_from_env_rb = caller.detect { |f| f =~ /\/env\.rb:/ }
3
+ called_from_env_rb = caller.detect { |f| f.include? '/env.rb:' }
4
4
 
5
5
  if called_from_env_rb
6
6
  env_caller = File.dirname(called_from_env_rb)
@@ -8,26 +8,25 @@ if called_from_env_rb
8
8
  require 'rails'
9
9
  require 'cucumber/rails/application'
10
10
  ENV['RAILS_ENV'] ||= 'test'
11
- ENV['RAILS_ROOT'] ||= File.expand_path(env_caller + '/../..')
12
- require File.expand_path(ENV['RAILS_ROOT'] + '/config/environment')
13
- require 'cucumber/rails/action_controller'
11
+ ENV['RAILS_ROOT'] ||= File.expand_path("#{env_caller}/../..")
12
+ require File.expand_path("#{ENV['RAILS_ROOT']}/config/environment")
13
+ require 'cucumber/rails/action_dispatch'
14
+ require 'rails/test_help'
14
15
 
15
- if defined?(ActiveRecord::Base)
16
- require 'rails/test_help'
17
- else
18
- require 'action_dispatch/testing/test_process'
19
- require 'action_dispatch/testing/integration'
20
- end
21
-
22
- unless Rails.application.config.cache_classes
16
+ unless Rails.application.config.cache_classes || defined?(Spring)
23
17
  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
18
+ (Spring needs cache_classes set to false). This is known to cause problems
25
19
  with database transactions. Set config.cache_classes to true if you want to use transactions."
26
20
  end
27
21
 
28
22
  require 'cucumber/rails/world'
29
23
  require 'cucumber/rails/hooks'
30
24
  require 'cucumber/rails/capybara'
25
+ require 'cucumber/rails/database/strategy'
26
+ require 'cucumber/rails/database/deletion_strategy'
27
+ require 'cucumber/rails/database/null_strategy'
28
+ require 'cucumber/rails/database/shared_connection_strategy'
29
+ require 'cucumber/rails/database/truncation_strategy'
31
30
  require 'cucumber/rails/database'
32
31
 
33
32
  MultiTest.disable_autorun
@@ -8,10 +8,6 @@ module Cucumber
8
8
 
9
9
  DEFAULT_SHEBANG = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
10
10
 
11
- class_option :spork,
12
- type: :boolean,
13
- desc: 'Use Spork'
14
-
15
11
  class_option :skip_database,
16
12
  type: :boolean,
17
13
  desc: 'Skip modification of database.yml',
@@ -34,11 +30,16 @@ module Cucumber
34
30
 
35
31
  def create_feature_support
36
32
  empty_directory 'features/support'
37
- if spork?
38
- template 'support/rails_spork.rb.erb', 'features/support/env.rb'
39
- else
40
- template 'support/rails.rb.erb', 'features/support/env.rb'
41
- end
33
+ template 'support/rails.rb.erb', 'features/support/env.rb'
34
+ end
35
+
36
+ def configure_environment
37
+ environment(<<~CONFIG, env: %w[development test]) if ::Rails::VERSION::MAJOR >= 6
38
+ # Configure 'rails notes' to inspect Cucumber files
39
+ config.annotations.register_directories('features')
40
+ config.annotations.register_extensions('feature') { |tag| /#\\s*(\#{tag}):?\\s*(.*)$/ }
41
+
42
+ CONFIG
42
43
  end
43
44
 
44
45
  def create_tasks
@@ -59,20 +60,16 @@ module Cucumber
59
60
 
60
61
  protected
61
62
 
62
- def spork?
63
- options[:spork]
64
- end
65
-
66
63
  def embed_file(source, indent = '')
67
- IO.read(File.join(self.class.source_root, source)).gsub(/^/, indent)
64
+ File.read(File.join(self.class.source_root, source)).gsub(/^/, indent)
68
65
  end
69
66
 
70
67
  def embed_template(source, indent = '')
71
68
  template = File.join(self.class.source_root, source)
72
69
  if RUBY_VERSION >= '2.6'
73
- ERB.new(IO.read(template), trim_mode: '-').result(binding).gsub(/^/, indent)
70
+ ERB.new(File.read(template), trim_mode: '-').result(binding).gsub(/^/, indent)
74
71
  else
75
- ERB.new(IO.read(template), nil, '-').result(binding).gsub(/^/, indent)
72
+ ERB.new(File.read(template), nil, '-').result(binding).gsub(/^/, indent)
76
73
  end
77
74
  end
78
75
  end
@@ -4,6 +4,6 @@ rerun = rerun.strip.gsub /\s/, ' '
4
4
  rerun_opts = rerun.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
5
5
  std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags 'not @wip'"
6
6
  %>
7
- default: <%= spork? ? '--drb ' : '' %><%%= std_opts %> features
8
- wip: <%= spork? ? '--drb ' : '' %>--tags @wip:3 --wip features
9
- rerun: <%= spork? ? '--drb ' : '' %><%%= rerun_opts %> --format rerun --out rerun.txt --strict --tags 'not @wip'
7
+ default: <%%= std_opts %> features
8
+ wip: --tags @wip:3 --wip features
9
+ rerun: <%%= rerun_opts %> --format rerun --out rerun.txt --strict --tags 'not @wip'
@@ -35,6 +35,7 @@ begin
35
35
  ::STATS_DIRECTORIES << %w(Cucumber\ features features) if File.exist?('features')
36
36
  ::CodeStatistics::TEST_TYPES << "Cucumber features" if File.exist?('features')
37
37
  end
38
+ <% if ::Rails::VERSION::MAJOR < 6 %>
38
39
 
39
40
  task :annotations_setup do
40
41
  Rails.application.configure do
@@ -44,7 +45,9 @@ begin
44
45
  end
45
46
  end
46
47
  end
48
+ <% end %>
47
49
  end
50
+
48
51
  desc 'Alias for cucumber:ok'
49
52
  task cucumber: 'cucumber:ok'
50
53
 
@@ -60,7 +63,9 @@ begin
60
63
 
61
64
  task stats: 'cucumber:statsetup'
62
65
 
66
+ <% if ::Rails::VERSION::MAJOR < 6 %>
63
67
  task notes: 'cucumber:annotations_setup'
68
+ <% end %>
64
69
  rescue LoadError
65
70
  desc 'cucumber rake task not available (cucumber not installed)'
66
71
  task :cucumber do