rspec-sidekiq_pro 1.0.0 → 1.1.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 +4 -4
- data/README.md +5 -3
- data/lib/rspec/sidekiq_pro/batches.rb +12 -12
- data/lib/rspec/sidekiq_pro/matchers/job_matcher.rb +61 -40
- data/lib/rspec/sidekiq_pro/version.rb +1 -1
- metadata +33 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2cd253da9eb5bb4e1bbb68a9bf9c2453f200e2743120b1730f82bc9c51c346ab
|
4
|
+
data.tar.gz: 63e909c970b1f4d29d1334f14b721a9c12478ca02cfef5d829d5046cea1ba733
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec44fdba876447f815815d3f9bf510876aca1be41fe0324102fff0828285d3a9b214825c9c79966b342e42e4d109c2487052d33aa1cd99c0fff69c34253a5dc0
|
7
|
+
data.tar.gz: c2692d557e4d997d3c17b895b7db57ca841b729bb643bbd2e1b8dfe3af410a80f959aee8db786e81d3787d282ec2f5a04a3f9dc5ac401bacf29fee08b3352d6a
|
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
#
|
1
|
+
# RSpec for Sidekiq Pro
|
2
2
|
|
3
3
|
[](https://rubygems.org/gems/rspec-sidekiq_pro)
|
4
4
|
[](https://github.com/inkstak/rspec-sidekiq_pro/actions/workflows/ci.yml)
|
5
|
-
[](https://github.com/testdouble/standard)
|
6
|
+
[](https://codeclimate.com/github/inkstak/rspec-sidekiq_pro/maintainability)
|
6
7
|
[](https://codeclimate.com/github/inkstak/rspec-sidekiq_pro/test_coverage)
|
7
8
|
|
8
9
|
### Installation
|
@@ -191,9 +192,10 @@ end
|
|
191
192
|
```bash
|
192
193
|
bundle exec rspec
|
193
194
|
bundle exec rubocop
|
195
|
+
bundle exec standardrb
|
194
196
|
```
|
195
197
|
|
196
|
-
|
198
|
+
All of them can be run with:
|
197
199
|
|
198
200
|
```bash
|
199
201
|
bundle exec rake
|
@@ -86,15 +86,15 @@ module Sidekiq
|
|
86
86
|
if Sidekiq::Testing.disabled?
|
87
87
|
super
|
88
88
|
else
|
89
|
-
@bid
|
89
|
+
@bid = bid || SecureRandom.urlsafe_base64(10)
|
90
90
|
props = RSpec::SidekiqPro::Batches::Props.fetch(bid, {})
|
91
91
|
|
92
|
-
@created_at
|
92
|
+
@created_at = props.fetch("created_at", Time.now.utc).to_f
|
93
93
|
@description = props["description"]
|
94
|
-
@parent_bid
|
95
|
-
@callbacks
|
96
|
-
@jids
|
97
|
-
@mutable
|
94
|
+
@parent_bid = props["parent"]
|
95
|
+
@callbacks = props.fetch("callbacks", {})
|
96
|
+
@jids = props.fetch("jids", [])
|
97
|
+
@mutable = props.empty?
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
@@ -179,8 +179,8 @@ module Sidekiq
|
|
179
179
|
callback.each do |target, options|
|
180
180
|
klass_name, method = target.to_s.split("#")
|
181
181
|
klass = klass_name.constantize
|
182
|
-
meth
|
183
|
-
inst
|
182
|
+
meth = method || "on_#{event}"
|
183
|
+
inst = klass.new
|
184
184
|
inst.jid = SecureRandom.hex(12) if inst.respond_to?(:jid)
|
185
185
|
inst.send(meth, status, options)
|
186
186
|
end
|
@@ -192,11 +192,11 @@ module Sidekiq
|
|
192
192
|
if Sidekiq::Testing.disabled?
|
193
193
|
super
|
194
194
|
else
|
195
|
-
@bid
|
196
|
-
@props
|
197
|
-
@pending
|
195
|
+
@bid = bid
|
196
|
+
@props = RSpec::SidekiqPro::Batches::Props.fetch(bid, {})
|
197
|
+
@pending = 0
|
198
198
|
@failures = 0
|
199
|
-
@total
|
199
|
+
@total = @props.fetch("jids", []).size
|
200
200
|
end
|
201
201
|
end
|
202
202
|
end
|
@@ -20,7 +20,6 @@ module RSpec
|
|
20
20
|
if block
|
21
21
|
raise ArgumentError, "setting block to `with` is not supported for this matcher" if supports_value_expectations?
|
22
22
|
raise ArgumentError, "setting arguments and block together in `with` is not supported" if expected_arguments.any?
|
23
|
-
|
24
23
|
@expected_arguments = block
|
25
24
|
else
|
26
25
|
@expected_arguments = normalize_arguments(expected_arguments)
|
@@ -41,7 +40,7 @@ module RSpec
|
|
41
40
|
raise "setting expecations with both `at` and `in` is not supported" if @expected_interval
|
42
41
|
|
43
42
|
@expected_timestamp = timestamp
|
44
|
-
@expected_schedule
|
43
|
+
@expected_schedule = timestamp.to_i
|
45
44
|
self
|
46
45
|
end
|
47
46
|
|
@@ -85,7 +84,7 @@ module RSpec
|
|
85
84
|
end
|
86
85
|
|
87
86
|
def matches?(jobs)
|
88
|
-
@actual_jobs
|
87
|
+
@actual_jobs = jobs
|
89
88
|
filtered_jobs = filter_jobs(actual_jobs)
|
90
89
|
|
91
90
|
if expected_count
|
@@ -96,7 +95,7 @@ module RSpec
|
|
96
95
|
end
|
97
96
|
|
98
97
|
def does_not_match?(jobs)
|
99
|
-
@actual_jobs
|
98
|
+
@actual_jobs = jobs
|
100
99
|
filtered_jobs = filter_jobs(actual_jobs)
|
101
100
|
|
102
101
|
if expected_count
|
@@ -135,45 +134,66 @@ module RSpec
|
|
135
134
|
end
|
136
135
|
|
137
136
|
def failure_message_diff
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
137
|
+
message = []
|
138
|
+
message += expectations_in_failure_message
|
139
|
+
message << "" if message.any?
|
140
|
+
message << actual_jobs_size_in_failure_message
|
141
|
+
|
142
|
+
if expected_arguments || expected_schedule || expected_without_batch || expected_batch
|
143
|
+
message[-1] = "#{message[-1]}:"
|
144
|
+
message += actual_jobs_details_in_failure_message
|
145
|
+
end
|
146
|
+
|
147
|
+
message.join("\n")
|
148
|
+
end
|
146
149
|
|
150
|
+
def actual_jobs_size_in_failure_message
|
147
151
|
if actual_jobs.empty?
|
148
|
-
|
149
|
-
elsif !expected_arguments && !expected_schedule && !expected_without_batch && !expected_batch
|
150
|
-
diff << "found #{actual_jobs.size} #{worker_class}"
|
152
|
+
"no #{worker_class} found"
|
151
153
|
else
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
154
|
+
"found #{actual_jobs.size} #{worker_class}"
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
# rubocop:disable Layout/ExtraSpacing
|
159
|
+
# It becomes unreadable when not allowing alignement
|
160
|
+
def expectations_in_failure_message
|
161
|
+
message = []
|
162
|
+
message << " exactly: #{expected_count} time(s)" if expected_count
|
163
|
+
message << " arguments: #{expected_arguments}" if expected_arguments
|
164
|
+
message << " in: #{expected_interval_output}" if expected_interval
|
165
|
+
message << " at: #{expected_timestamp}" if expected_timestamp
|
166
|
+
message << " batch: #{output_batch(expected_batch)}" if expected_batch
|
167
|
+
message << " batch: no batch" if expected_without_batch
|
168
|
+
message
|
169
|
+
end
|
170
|
+
|
171
|
+
def job_details_in_failure_message(job)
|
172
|
+
message = []
|
173
|
+
message << " arguments: #{job["args"]}" if expected_arguments
|
174
|
+
message << " at: #{output_schedule(job["at"])}" if expected_schedule && job["at"]
|
175
|
+
message << " at: no schedule" if expected_schedule && !job["at"]
|
176
|
+
message << " batch: #{output_batch(job["bid"])}" if (expected_without_batch || expected_batch) && job["bid"]
|
177
|
+
message << " batch: no batch" if (expected_without_batch || expected_batch) && !job["bid"]
|
178
|
+
message
|
179
|
+
end
|
180
|
+
|
181
|
+
def actual_jobs_details_in_failure_message
|
182
|
+
actual_jobs.flat_map do |job|
|
183
|
+
job_details_in_failure_message(job).map.with_index do |line, index|
|
184
|
+
if actual_jobs.size > 1
|
185
|
+
indent = " "
|
186
|
+
indent = " - " if index.zero?
|
187
|
+
line = "#{indent}#{line[2..]}"
|
170
188
|
end
|
189
|
+
|
190
|
+
line
|
171
191
|
end
|
172
192
|
end
|
173
|
-
|
174
|
-
diff.join("\n")
|
175
193
|
end
|
176
194
|
|
195
|
+
# rubocop:enable Layout/ExtraSpacing
|
196
|
+
|
177
197
|
def expected_interval_output
|
178
198
|
"#{expected_interval.inspect} (#{output_schedule(expected_schedule)})"
|
179
199
|
end
|
@@ -184,9 +204,12 @@ module RSpec
|
|
184
204
|
|
185
205
|
def output_batch(value)
|
186
206
|
case value
|
187
|
-
when :__undef__
|
188
|
-
|
189
|
-
when
|
207
|
+
when :__undef__
|
208
|
+
"to be present"
|
209
|
+
when String
|
210
|
+
"<Sidekiq::Batch bid: #{value.inspect}>"
|
211
|
+
when Sidekiq::Batch
|
212
|
+
"<Sidekiq::Batch bid: #{value.bid.inspect}>"
|
190
213
|
else
|
191
214
|
if value.respond_to?(:description)
|
192
215
|
value.description
|
@@ -213,10 +236,8 @@ module RSpec
|
|
213
236
|
!bid.nil?
|
214
237
|
when String
|
215
238
|
expected_batch == bid
|
216
|
-
|
217
239
|
when ::Sidekiq::Batch
|
218
240
|
expected_batch.bid == bid
|
219
|
-
|
220
241
|
else
|
221
242
|
return unless bid
|
222
243
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-sidekiq_pro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Savater Sebastien
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -48,30 +48,56 @@ dependencies:
|
|
48
48
|
name: sidekiq
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- - "
|
51
|
+
- - ">="
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '6.5'
|
54
|
+
- - "<"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '8'
|
54
57
|
type: :runtime
|
55
58
|
prerelease: false
|
56
59
|
version_requirements: !ruby/object:Gem::Requirement
|
57
60
|
requirements:
|
58
|
-
- - "
|
61
|
+
- - ">="
|
59
62
|
- !ruby/object:Gem::Version
|
60
63
|
version: '6.5'
|
64
|
+
- - "<"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '8'
|
61
67
|
- !ruby/object:Gem::Dependency
|
62
68
|
name: sidekiq-pro
|
63
69
|
requirement: !ruby/object:Gem::Requirement
|
64
70
|
requirements:
|
65
|
-
- - "
|
71
|
+
- - ">="
|
66
72
|
- !ruby/object:Gem::Version
|
67
73
|
version: '5.5'
|
74
|
+
- - "<"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '8'
|
68
77
|
type: :runtime
|
69
78
|
prerelease: false
|
70
79
|
version_requirements: !ruby/object:Gem::Requirement
|
71
80
|
requirements:
|
72
|
-
- - "
|
81
|
+
- - ">="
|
73
82
|
- !ruby/object:Gem::Version
|
74
83
|
version: '5.5'
|
84
|
+
- - "<"
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '8'
|
87
|
+
- !ruby/object:Gem::Dependency
|
88
|
+
name: zeitwerk
|
89
|
+
requirement: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - "~>"
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '2.6'
|
94
|
+
type: :runtime
|
95
|
+
prerelease: false
|
96
|
+
version_requirements: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - "~>"
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '2.6'
|
75
101
|
description:
|
76
102
|
email: github.60k5k@simplelogin.co
|
77
103
|
executables: []
|
@@ -106,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
132
|
- !ruby/object:Gem::Version
|
107
133
|
version: '0'
|
108
134
|
requirements: []
|
109
|
-
rubygems_version: 3.
|
135
|
+
rubygems_version: 3.1.6
|
110
136
|
signing_key:
|
111
137
|
specification_version: 4
|
112
138
|
summary: A collection of tools and matchers for Sidekiq Pro
|