integration-tests-rails 1.1.5 → 1.1.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 53944743e03bea5bc70d05907ebaf666e5da367c41844a9df967427c41c42860
4
- data.tar.gz: d144aef9b18271dbb7921bce4e2718072aa9f685b727ebb7907aa13d75c29694
3
+ metadata.gz: 1668370843b5697395c5716bfd2442188ab3dc44381b65d9442b3df2d8a77db7
4
+ data.tar.gz: c55dbc2cc27128a3858e72a16ba1ea14b09069a84f0d154993c6c6423a752a9b
5
5
  SHA512:
6
- metadata.gz: 0fc048144a72cbef17015e994d933efdedec5f7ccbc573470514eb722fac65a1df6166bde2b87a24cdacd3cb8d11bfee6aa8cc36ecd5143ff5da72219b14da06
7
- data.tar.gz: ee70f5ac6184b97c2c8e637313fe6fc1d6ecd6ee6c4219e9e9bacc1712d5c2b3a2b108bcb33792d29ba4d7413e9a6e3ec0d5c2fe42ac3b6b64f768a7c29c0b8d
6
+ metadata.gz: 5c8b64492f395681aa22d9e64a3c3a23adca9a9088a48c5e9ec427d36e1ef326efd549f6a96890087aee5be6d03fac63b2d4321ddedade93027876d340977bee
7
+ data.tar.gz: 6f836c2525fa07283f1270c98ddbc9a52815a26b2c5452f2d50408cdbdcc10c2547b1ca2834064b9e5dc53cb17c61cf78cbadc6194c973c942c8fd26b2d28410
@@ -15,7 +15,7 @@ module IntegrationTestsRails
15
15
  yield
16
16
  rescue *capture_exceptions => e
17
17
  counter += 1
18
- Util.log("Attempt #{counter} for #{RSpec.current_example.full_description} failed!")
18
+ Util.log("Inline Retry Attempt #{counter} for #{RSpec.current_example.full_description} failed!")
19
19
  raise e if counter > attempts
20
20
 
21
21
  sleep(sleep_duration) if sleep_duration.positive?
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IntegrationTestsRails
4
+ module Capybara
5
+ # Handles auto-retry logic for RSpec feature examples.
6
+ module Retry
7
+ class << self
8
+ def run(example, context)
9
+ description = example.full_description
10
+ attempts, sleep_duration, capture_exceptions = retry_config(example)
11
+
12
+ (attempts + 1).times do |attempt_number|
13
+ reset_example_state(context)
14
+ example.run
15
+ ex = RSpec.current_example.exception
16
+ break unless ex
17
+ break unless capture_exceptions.any? { |klass| ex.is_a?(klass) }
18
+
19
+ Util.log "Auto Retry Attempt #{attempt_number + 1} failed for: #{description}"
20
+ sleep(sleep_duration) if attempt_number < attempts && sleep_duration.positive?
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def retry_config(example)
27
+ kwargs = example.metadata.fetch(:auto_retry, {})
28
+ config_obj = IntegrationTestsRails.configuration
29
+ attempts = kwargs.fetch(:attempts, config_obj.retry_attempts)
30
+ sleep_duration = kwargs.fetch(:sleep_duration, config_obj.retry_sleep_duration)
31
+ capture_exceptions = constantize_exceptions(config_obj)
32
+ [attempts, sleep_duration, capture_exceptions]
33
+ end
34
+
35
+ def constantize_exceptions(config)
36
+ config.retry_capture_exceptions.filter_map { |e| e.constantize if e.is_a?(String) }
37
+ end
38
+
39
+ def reset_example_state(context)
40
+ RSpec.current_example.instance_variable_set(:@exception, nil)
41
+ memoized_class = begin
42
+ RSpec::Core::MemoizedHelpers::ThreadsafeMemoized
43
+ rescue StandardError
44
+ RSpec::Core::MemoizedHelpers::NonThreadSafeMemoized
45
+ end
46
+ context.instance_variable_set(:@__memoized, memoized_class.new)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative 'helpers'
4
4
  require_relative 'dsl'
5
+ require_relative 'retry'
5
6
  require_relative 'tests_controller'
6
7
 
7
8
  module IntegrationTestsRails
@@ -14,6 +15,28 @@ module IntegrationTestsRails
14
15
  log 'WebMock configured to allow localhost connections'
15
16
  end
16
17
 
18
+ def configure_routes
19
+ return unless IntegrationTestsRails.configuration.experimental_features
20
+
21
+ app = Rails.application
22
+ routes = app.routes
23
+ # Use append and let Rails handle finalization automatically
24
+ routes.append do
25
+ get '/tests', to: 'tests#index', as: :tests
26
+ end
27
+ routes.instance_variable_set(:@finalized, false)
28
+ routes.finalize!
29
+ log 'Routes appended.'
30
+ end
31
+
32
+ def verbose?
33
+ IntegrationTestsRails.configuration.verbose
34
+ end
35
+
36
+ def log(message)
37
+ puts "[CAPYBARA] #{message}" if verbose?
38
+ end
39
+
17
40
  def ensure_server_ready(context)
18
41
  return if @server_ready
19
42
 
@@ -38,46 +61,32 @@ module IntegrationTestsRails
38
61
  def configure_rspec
39
62
  RSpec.configure do |config|
40
63
  config.include Dsl, type: :feature
41
- config.before(:each, type: :feature) do
42
- ::Capybara.current_driver = ::Capybara.javascript_driver
43
- IntegrationTestsRails::Capybara::Util.ensure_server_ready(self)
44
- end
45
-
46
- config.around(:each, type: :feature) do |example|
47
- if IntegrationTestsRails.configuration.auto_retry
48
- kwargs = example.metadata.fetch(:auto_retry, {})
49
- retry_on_fail(**kwargs) { example.run }
50
- else
51
- example.run
52
- end
53
- end
54
-
64
+ configure_before_hook(config)
65
+ configure_around_hook(config)
55
66
  if IntegrationTestsRails.configuration.experimental_features
56
- config.include(Helper, type: :feature, unit: true)
67
+ config.include(Helper, type: :feature,
68
+ unit: true)
57
69
  end
58
70
  end
59
71
  end
60
72
 
61
- def configure_routes
62
- return unless IntegrationTestsRails.configuration.experimental_features
73
+ private
63
74
 
64
- app = Rails.application
65
- routes = app.routes
66
- # Use append and let Rails handle finalization automatically
67
- routes.append do
68
- get '/tests', to: 'tests#index', as: :tests
75
+ def configure_before_hook(config)
76
+ config.before(:each, type: :feature) do
77
+ ::Capybara.current_driver = ::Capybara.javascript_driver
78
+ IntegrationTestsRails::Capybara::Util.ensure_server_ready(self)
69
79
  end
70
- routes.instance_variable_set(:@finalized, false)
71
- routes.finalize!
72
- log 'Routes appended.'
73
- end
74
-
75
- def verbose?
76
- IntegrationTestsRails.configuration.verbose
77
80
  end
78
81
 
79
- def log(message)
80
- puts "[CAPYBARA] #{message}" if verbose?
82
+ def configure_around_hook(config)
83
+ config.around(:each, type: :feature) do |example|
84
+ if IntegrationTestsRails.configuration.auto_retry
85
+ Retry.run(example, self)
86
+ else
87
+ example.run
88
+ end
89
+ end
81
90
  end
82
91
  end
83
92
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IntegrationTestsRails
4
- VERSION = '1.1.5'
4
+ VERSION = '1.1.7'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: integration-tests-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tien
@@ -94,6 +94,7 @@ files:
94
94
  - lib/integration_tests_rails/capybara/helpers.rb
95
95
  - lib/integration_tests_rails/capybara/local.rb
96
96
  - lib/integration_tests_rails/capybara/remote.rb
97
+ - lib/integration_tests_rails/capybara/retry.rb
97
98
  - lib/integration_tests_rails/capybara/tests_controller.rb
98
99
  - lib/integration_tests_rails/capybara/util.rb
99
100
  - lib/integration_tests_rails/configuration.rb