minitest-retry 0.2.4 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a31833391dfea9565ad1373bbf959f8e910fd618160a54be9ca641aebb68eda
4
- data.tar.gz: 247aa4a9466e5f60484f68d865c34b7e61d2ba9a05cbea098e4a6be1eb6a772e
3
+ metadata.gz: e8d4d665c0afb4fe2ae9548c66ef1a7beb4158615b0d0f8e9ae193124b6c3c50
4
+ data.tar.gz: b475f7d149b3d6365ae8718884ea830cdf561a0c09e1e4b01eee5e82bb23c71d
5
5
  SHA512:
6
- metadata.gz: 93abe11a1cdf89faf10f95f1cd1c1412696f77c5210d96b7ff2c160f6abc56d067e5324e7623216a28a32df649b11276c4a4f376126d21ab420ccac1a86a382c
7
- data.tar.gz: 18487273718ca12691ecfd2cf791ecf9a5fa0366b0689a82b9eb9bc5213c0775fb365bbee06c8aa110bd09895d2028838987341d10e5b1de73e04251f6653429
6
+ metadata.gz: 282ba68c650f2062afcd0acf9ac0fffab2c2fc5eed52744e24f87495edc8ea8624825e3bbb8e6d3869512481ed1932874af1ddb1cb5c0b7c0458393965014ebf
7
+ data.tar.gz: 87a04ad51d02b17181ca6c40b38c25c604de260222358a6ffcfba9d2757e4d3843939d140179e8825c28a4c1f4809cbceec381e8f5d4d8449d5fe48ef3cf9a0a
@@ -0,0 +1,33 @@
1
+ name: Push Gem
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - v*
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ push:
13
+ if: github.repository == 'y-yagi/minitest-retry'
14
+ runs-on: ubuntu-latest
15
+
16
+ permissions:
17
+ contents: write
18
+ id-token: write
19
+
20
+ steps:
21
+ - name: Harden Runner
22
+ uses: step-security/harden-runner@4d991eb9b905ef189e4c376166672c3f2f230481 # v2.11.0
23
+ with:
24
+ egress-policy: audit
25
+
26
+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
27
+ - name: Set up Ruby
28
+ uses: ruby/setup-ruby@2e007403fc1ec238429ecaa57af6f22f019cc135 # v1.234.0
29
+ with:
30
+ bundler-cache: true
31
+ ruby-version: ruby
32
+
33
+ - uses: rubygems/release-gem@9e85cb11501bebc2ae661c1500176316d3987059 # v1.1.0
@@ -18,7 +18,7 @@ jobs:
18
18
  pull-requests: write
19
19
 
20
20
  steps:
21
- - uses: actions/stale@v9
21
+ - uses: actions/stale@5bef64f19d7facfb25b37b414482c7164d639639 # v9.1.0
22
22
  with:
23
23
  repo-token: ${{ secrets.GITHUB_TOKEN }}
24
24
  stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.'
@@ -3,18 +3,36 @@ name: CI
3
3
  on: [push]
4
4
 
5
5
  jobs:
6
- build:
6
+ minitest-5:
7
7
  runs-on: ubuntu-latest
8
8
  strategy:
9
9
  matrix:
10
10
  ruby: [ '3.4', '3.3', '3.2', '3.1', '3.0', '2.7', '2.6', '2.5', '2.4', '2.3' ]
11
+ env:
12
+ BUNDLE_GEMFILE: gemfiles/minitest_5.gemfile
11
13
  steps:
12
- - uses: actions/checkout@v4
13
- - uses: ruby/setup-ruby@v1
14
+ - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
15
+ - uses: ruby/setup-ruby@a25f1e45f0e65a92fcb1e95e8847f78fb0a7197a # v1.273.0
14
16
  with:
15
17
  ruby-version: ${{ matrix.ruby }}
16
18
  - name: Install dependencies
17
- run: |
18
- bundle install
19
+ run: bundle install
20
+ - name: Run test
21
+ run: bundle exec rake
22
+
23
+ minitest-6:
24
+ runs-on: ubuntu-latest
25
+ strategy:
26
+ matrix:
27
+ ruby: [ '3.4', '3.3', '3.2' ]
28
+ env:
29
+ BUNDLE_GEMFILE: gemfiles/minitest_6.gemfile
30
+ steps:
31
+ - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
32
+ - uses: ruby/setup-ruby@a25f1e45f0e65a92fcb1e95e8847f78fb0a7197a # v1.273.0
33
+ with:
34
+ ruby-version: ${{ matrix.ruby }}
35
+ - name: Install dependencies
36
+ run: bundle install
19
37
  - name: Run test
20
38
  run: bundle exec rake
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /gemfiles/*.lock
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.3.0
2
+
3
+ * Support minitest 6 [y-yagi]
4
+
5
+ ## 0.2.5
6
+
7
+ * Add `exceptions_to_skip` option #48 [y-yagi]
8
+
1
9
  ## 0.2.4
2
10
 
3
11
  * Add `methods_to_skip` option #44 [y-yagi]
data/README.md CHANGED
@@ -40,7 +40,8 @@ Minitest::Retry.use!(
40
40
  exceptions_to_retry: [], # List of exceptions that will trigger a retry (when empty, all exceptions will).
41
41
  methods_to_retry: [], # List of methods that will trigger a retry (when empty, all methods will).
42
42
  classes_to_retry: [], # List of classes that will trigger a retry (when empty, all classes will).
43
- methods_to_skip: [] # List of methods that will skip a retry (when empty, all methods will retry).
43
+ methods_to_skip: [], # List of methods that will skip a retry (when empty, all methods will retry).
44
+ exceptions_to_skip: [] # List of exceptions that will skip a retry (when empty, all exceptions will retry).
44
45
  )
45
46
  ```
46
47
 
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ eval_gemfile File.expand_path("../Gemfile", __dir__)
4
+
5
+ gem "minitest", "< 6"
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ eval_gemfile File.expand_path("../Gemfile", __dir__)
4
+
5
+ gem "minitest", ">= 6", "< 7"
@@ -1,5 +1,5 @@
1
1
  module Minitest
2
2
  module Retry
3
- VERSION = "0.2.4"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -3,8 +3,8 @@ require "minitest/retry/version"
3
3
  module Minitest
4
4
  module Retry
5
5
  class << self
6
- def use!(retry_count: 3, io: $stdout, verbose: true, exceptions_to_retry: [], methods_to_retry: [], classes_to_retry: [], methods_to_skip: [])
7
- @retry_count, @io, @verbose, @exceptions_to_retry, @methods_to_retry, @classes_to_retry, @methods_to_skip = retry_count, io, verbose, exceptions_to_retry, methods_to_retry, classes_to_retry, methods_to_skip
6
+ def use!(retry_count: 3, io: $stdout, verbose: true, exceptions_to_retry: [], methods_to_retry: [], classes_to_retry: [], methods_to_skip: [], exceptions_to_skip: [])
7
+ @retry_count, @io, @verbose, @exceptions_to_retry, @methods_to_retry, @classes_to_retry, @methods_to_skip, @exceptions_to_skip = retry_count, io, verbose, exceptions_to_retry, methods_to_retry, classes_to_retry, methods_to_skip, exceptions_to_skip
8
8
  @failure_callback, @consistent_failure_callback, @retry_callback = nil, nil, nil
9
9
  Minitest.prepend(self)
10
10
  end
@@ -64,6 +64,10 @@ module Minitest
64
64
  @methods_to_skip
65
65
  end
66
66
 
67
+ def exceptions_to_skip
68
+ @exceptions_to_skip
69
+ end
70
+
67
71
  def failure_to_retry?(failures = [], klass_method_name, klass)
68
72
  return false if failures.empty?
69
73
 
@@ -80,43 +84,73 @@ module Minitest
80
84
  return !methods_to_skip.include?(klass_method_name)
81
85
  end
82
86
 
87
+ if exceptions_to_skip.any?
88
+ errors = failures.map(&:error).map(&:class)
89
+ return !(errors & exceptions_to_skip).any?
90
+ end
91
+
83
92
  return true if classes_to_retry.empty?
84
93
  ancestors = klass.ancestors.map(&:to_s)
85
94
  return classes_to_retry.any? { |class_to_retry| ancestors.include?(class_to_retry) }
86
95
  end
87
- end
88
-
89
- module ClassMethods
90
- def run_one_method(klass, method_name)
91
- result = super(klass, method_name)
92
96
 
97
+ def run_with_retry(klass, method_name)
93
98
  klass_method_name = "#{klass.name}##{method_name}"
94
- return result unless Minitest::Retry.failure_to_retry?(result.failures, klass_method_name, klass)
95
- if !result.skipped?
96
- Minitest::Retry.failure_callback.call(klass, method_name, result) if Minitest::Retry.failure_callback
97
- Minitest::Retry.retry_count.times do |count|
98
- Minitest::Retry.retry_callback.call(klass, method_name, count + 1, result) if Minitest::Retry.retry_callback
99
- if Minitest::Retry.verbose && Minitest::Retry.io
100
- msg = "[MinitestRetry] retry '%s' count: %s, msg: %s\n" %
101
- [method_name, count + 1, result.failures.map(&:message).join(",")]
102
- Minitest::Retry.io.puts(msg)
103
- end
104
-
105
- result = super(klass, method_name)
106
- break if result.failures.empty?
107
- end
99
+ result = yield
100
+
101
+ return result unless failure_to_retry?(result.failures, klass_method_name, klass)
102
+ return result if result.skipped?
103
+
104
+ failure_callback&.call(klass, method_name, result)
108
105
 
109
- if Minitest::Retry.consistent_failure_callback && !result.failures.empty?
110
- Minitest::Retry.consistent_failure_callback.call(klass, method_name, result)
106
+ retry_count.times do |count|
107
+ retry_callback&.call(klass, method_name, count + 1, result)
108
+
109
+ if verbose && io
110
+ msg = "[MinitestRetry] retry '%s' count: %s, msg: %s\n" %
111
+ [method_name, count + 1, result.failures.map(&:message).join(",")]
112
+ io.puts(msg)
111
113
  end
114
+
115
+ result = yield
116
+ break if result.failures.empty?
112
117
  end
118
+
119
+ if consistent_failure_callback && !result.failures.empty?
120
+ consistent_failure_callback.call(klass, method_name, result)
121
+ end
122
+
113
123
  result
114
124
  end
115
125
  end
116
126
 
127
+ module ClassMethods
128
+ def run_one_method(klass, method_name)
129
+ Minitest::Retry.run_with_retry(klass, method_name) do
130
+ super(klass, method_name)
131
+ end
132
+ end
133
+ end
134
+
135
+ module RunnableMethods
136
+ def run(klass, method_name, reporter)
137
+ reporter.prerecord klass, method_name
138
+ result = Minitest::Retry.run_with_retry(klass, method_name) do
139
+ klass.new(method_name).run
140
+ end
141
+ reporter.record result
142
+ end
143
+ end
144
+
117
145
  def self.prepended(base)
118
- class << base
119
- prepend ClassMethods
146
+ if Minitest::VERSION > "6"
147
+ class << Minitest::Runnable
148
+ prepend RunnableMethods
149
+ end
150
+ else
151
+ class << base
152
+ prepend ClassMethods
153
+ end
120
154
  end
121
155
  end
122
156
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest-retry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuji Yaginuma
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-01-26 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: minitest
@@ -58,6 +58,7 @@ executables: []
58
58
  extensions: []
59
59
  extra_rdoc_files: []
60
60
  files:
61
+ - ".github/workflows/push_gem.yml"
61
62
  - ".github/workflows/stale.yml"
62
63
  - ".github/workflows/ubuntu.yml"
63
64
  - ".gitignore"
@@ -68,6 +69,8 @@ files:
68
69
  - Rakefile
69
70
  - bin/console
70
71
  - bin/setup
72
+ - gemfiles/minitest_5.gemfile
73
+ - gemfiles/minitest_6.gemfile
71
74
  - lib/minitest/retry.rb
72
75
  - lib/minitest/retry/version.rb
73
76
  - minitest-retry.gemspec
@@ -91,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
94
  - !ruby/object:Gem::Version
92
95
  version: '0'
93
96
  requirements: []
94
- rubygems_version: 3.6.2
97
+ rubygems_version: 3.6.7
95
98
  specification_version: 4
96
99
  summary: re-run the test when the test fails
97
100
  test_files: []