rspec-sidekiq 3.0.3 → 4.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGES.md +27 -0
  3. data/LICENSE +12 -0
  4. data/README.md +200 -79
  5. data/lib/rspec/sidekiq/batch.rb +30 -3
  6. data/lib/rspec/sidekiq/configuration.rb +13 -2
  7. data/lib/rspec/sidekiq/matchers/base.rb +257 -0
  8. data/lib/rspec/sidekiq/matchers/be_delayed.rb +17 -3
  9. data/lib/rspec/sidekiq/matchers/enqueue_sidekiq_job.rb +87 -0
  10. data/lib/rspec/sidekiq/matchers/have_enqueued_sidekiq_job.rb +25 -0
  11. data/lib/rspec/sidekiq/matchers.rb +13 -8
  12. data/lib/rspec/sidekiq/sidekiq.rb +1 -1
  13. data/lib/rspec/sidekiq/version.rb +1 -1
  14. metadata +131 -84
  15. data/.gitattributes +0 -22
  16. data/.gitignore +0 -2
  17. data/.rspec +0 -4
  18. data/.simplecov +0 -5
  19. data/Gemfile +0 -9
  20. data/lib/rspec/sidekiq/matchers/have_enqueued_job.rb +0 -183
  21. data/rspec-sidekiq.gemspec +0 -37
  22. data/spec/rspec/sidekiq/batch_spec.rb +0 -77
  23. data/spec/rspec/sidekiq/helpers/retries_exhausted_spec.rb +0 -40
  24. data/spec/rspec/sidekiq/matchers/be_delayed_spec.rb +0 -238
  25. data/spec/rspec/sidekiq/matchers/be_expired_in_spec.rb +0 -57
  26. data/spec/rspec/sidekiq/matchers/be_processed_in_spec.rb +0 -114
  27. data/spec/rspec/sidekiq/matchers/be_retryable_spec.rb +0 -129
  28. data/spec/rspec/sidekiq/matchers/be_unique_spec.rb +0 -115
  29. data/spec/rspec/sidekiq/matchers/have_enqueued_job_spec.rb +0 -228
  30. data/spec/rspec/sidekiq/matchers/save_backtrace_spec.rb +0 -136
  31. data/spec/rspec/sidekiq/sidekiq_spec.rb +0 -15
  32. data/spec/spec_helper.rb +0 -29
  33. data/spec/support/factories.rb +0 -33
  34. data/spec/support/init.rb +0 -6
  35. data/spec/support/test_action_mailer.rb +0 -6
  36. data/spec/support/test_job.rb +0 -6
  37. data/spec/support/test_resource.rb +0 -16
  38. data/spec/support/test_worker.rb +0 -8
  39. data/spec/support/test_worker_alternative.rb +0 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: dd244416f99c35639675efb4b3473dd9741d512c
4
- data.tar.gz: 6fa5eb3e029086fe4d316a6a9896b7acddb834de
2
+ SHA256:
3
+ metadata.gz: 3320d82a82c0cbb318c7d563be5a7d4482178b8e4d4b6936e710bc88d8ce7531
4
+ data.tar.gz: d34d50e7d90f8e5ece3aceca122f89b51f77afb10c7c76ee19496a562151ff42
5
5
  SHA512:
6
- metadata.gz: fe360471b5c79f74e4af320881d97d0d26ec0cf837a8309e8b898221d71c63bce2d2a750d32b9427dfb931dc4a83837e4c2e3e6b1ddd6a5ed17050205f7e4aa3
7
- data.tar.gz: 1d0913303fbdd4c72aea0248e815d4842a5c8fe9d0a338c6cad7cf0dbd59fc7145899718d51185444c72023772605e30099326c8481345927f083c9db91df7e6
6
+ metadata.gz: b3c1a1b22cd93d5d18729365df70fcb3b8d98f5c83b5f6d2cde618eb03a425ee5164a66abf92b139c62629ab95a55b35a89a06e202699effd6e472654281d59a
7
+ data.tar.gz: 5c6a68c4890e8de3de64e52b7d3c6cc603c743f8980e7e7d6cebbd4ff819e7d183a617c3677bd9a924eba405c655d8e35c8a52f3e02f259a081806e5d810dfbf
data/CHANGES.md CHANGED
@@ -1,3 +1,30 @@
1
+ Unreleased - 4.0.0
2
+ ---
3
+ * [BREAKING] Dropped support for matching jobs on ActiveJob's private API args, (e.g. `_aj_globalid` and `_aj_ruby2_keywords`). `_aj_globalid` can be replaced with the object itself, e.g. `have_enqueued_sidekiq_job(user)`.
4
+ * [BREAKING] Dropped support for Ruby 2.6
5
+ * [BREAKING] Mocking Sidekiq::Batch is now _opt in_ (was opt-out) by default
6
+ * [BREAKING] Dropped the `have_enqueued_job` matcher (deprecated since v3)
7
+ * [BREAKING] Dropped support for Sidekiq <5
8
+ * [BREAKING] Dropped support for Rails 5
9
+ * Add support for Sidekiq 7 (#192)
10
+ * Add support for builtin argument matchers from rspec mocks for
11
+ `have_enqueued_sidekiq_job` (#200)
12
+ * Add `#on` to `have_enqueued_sidekiq_job` to support testing queue at enqueue time (#197)
13
+ * Clarified `have_enqueued_sidekiq_job` error message to make it clear that the "actual arguments" list is an array of argument-lists across all enqueued jobs. (#195)
14
+ * Fix `in` and `at` evaluation to match Sidekiq (#194)
15
+ * Fix `be_delayed` argument matcher (#196)
16
+ * Fix argument matching ignoring order (#200)
17
+ * Fix `be_delayed` time math when using `delay_for` (#198)
18
+
19
+ 3.1.0
20
+ ---
21
+ * Add support for latest ruby and Rails 5 (coding-bunny #156)
22
+ * Support `Class#method` notation in batch callback (caalberts #155)
23
+ * Fix bug with time comparison in delayed jobs (geeosh #153 with help from col)
24
+ * remove usage of `Integer#blank?` (lanej #152)
25
+ * Add `NullBatch#description` (dsantosmerino #139)
26
+ * README updates (BenMusch #142, akihikodaki #141, wpolicarpo #160)
27
+
1
28
  3.0.3
2
29
  ---
3
30
  * Re-splat arguments for the have_enqueued_job alias (aprescott #136)
data/LICENSE CHANGED
@@ -1,5 +1,17 @@
1
1
  The MIT License (MIT)
2
2
 
3
+ Copyright (c) 2023 Will Spurgin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10
+
11
+ Elements of this software and associated documentation files are covered by the following license:
12
+
13
+ The MIT License (MIT)
14
+
3
15
  Copyright (c) 2014, 2015 Phil Ostler
4
16
 
5
17
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
data/README.md CHANGED
@@ -1,23 +1,9 @@
1
- **Welcome @wpolicarpo and @packrat386 as new maintainers for `rspec-sidekiq`!**
2
-
3
- # RSpec for Sidekiq
1
+ **Welcome @wspurgin as new maintainer for `rspec-sidekiq`!**
4
2
 
5
3
  [![RubyGems][gem_version_badge]][ruby_gems]
6
- [![Code Climate][code_climate_badge]][code_climate]
7
- [![Travis CI][travis_ci_badge]][travis_ci]
8
- [![Coveralls][coveralls_badge]][coveralls]
9
- [![Gemnasium][gemnasium_badge]][gemnasium]
10
-
11
- ***Simple testing of Sidekiq jobs via a collection of matchers and helpers***
12
-
13
- [RubyGems][ruby_gems] |
14
- [Code Climate][code_climate] |
15
- [GitHub][github] |
16
- [Travis CI][travis_ci] |
17
- [Coveralls][coveralls] |
18
- [Gemnasium][gemnasium] |
19
- [RubyDoc][ruby_doc] |
20
- [Ruby Toolbox][ruby_toolbox]
4
+ [![Github Actions CI][github_actions_badge]][github_actions]
5
+
6
+ Simple testing of Sidekiq jobs via a collection of matchers and helpers.
21
7
 
22
8
  [Jump to Matchers &raquo;](#matchers) | [Jump to Helpers &raquo;](#helpers)
23
9
 
@@ -48,33 +34,143 @@ end
48
34
  ```
49
35
 
50
36
  ## Matchers
51
- * [be_delayed](#be_delayed)
37
+ * [enqueue_sidekiq_job](#enqueue_sidekiq_job)
38
+ * [have_enqueued_sidekiq_job](#have_enqueued_sidekiq_job)
52
39
  * [be_processed_in](#be_processed_in)
53
40
  * [be_retryable](#be_retryable)
54
41
  * [be_unique](#be_unique)
55
- * [have_enqueued_sidekiq_job](#have_enqueued_sidekiq_job)
42
+ * [be_delayed (_deprecated_)](#be_delayed)
43
+
44
+ ### enqueue_sidekiq_job
45
+
46
+ *Describes that the block should enqueue a job*. Optionally specify the
47
+ specific job class, arguments, timing, and other context
56
48
 
57
- ### be_delayed
58
- *Describes a method that should be invoked asynchronously (See [Sidekiq Delayed Extensions][sidekiq_wiki_delayed_extensions])*
59
49
  ```ruby
60
- Object.delay.is_nil? # delay
61
- expect(Object.method :is_nil?).to be_delayed
62
- Object.delay.is_a? Object # delay with argument
63
- expect(Object.method :is_a?).to be_delayed(Object)
50
+ # Basic
51
+ expect { AwesomeJob.perform_async }.to enqueue_sidekiq_job
64
52
 
65
- Object.delay_for(1.hour).is_nil? # delay for
66
- expect(Object.method :is_nil?).to be_delayed.for 1.hour
67
- Object.delay_for(1.hour).is_a? Object # delay for with argument
68
- expect(Object.method :is_a?).to be_delayed(Object).for 1.hour
53
+ # A specific job class
54
+ expect { AwesomeJob.perform_async }.to enqueue_sidekiq_job(AwesomeJob)
69
55
 
70
- Object.delay_until(1.hour.from_now).is_nil? # delay until
71
- expect(Object.method :is_nil?).to be_delayed.until 1.hour.from_now
72
- Object.delay_until(1.hour.from_now).is_a? Object # delay until with argument
73
- expect(Object.method :is_a?).to be_delayed(Object).until 1.hour.from_now
56
+ # with specific arguments
57
+ expect { AwesomeJob.perform_async "Awesome!" }.to enqueue_sidekiq_job.with("Awesome!")
74
58
 
75
- #Rails Mailer
76
- MyMailer.delay.some_mail
77
- expect(MyMailer.instance_method :some_mail).to be_delayed
59
+ # On a specific queue
60
+ expect { AwesomeJob.set(queue: "high").perform_async }.to enqueue_sidekiq_job.on("high")
61
+
62
+ # At a specific datetime
63
+ specific_time = 1.hour.from_now
64
+ expect { AwesomeJob.perform_at(specific_time) }.to enqueue_sidekiq_job.at(specific_time)
65
+
66
+ # In a specific interval (be mindful of freezing or managing time here)
67
+ freeze_time do
68
+ expect { AwesomeJob.perform_in(1.hour) }.to enqueue_sidekiq_job.in(1.hour)
69
+ end
70
+
71
+ # Combine and chain them as desired
72
+ expect { AwesomeJob.perform_at(specific_time, "Awesome!") }.to(
73
+ enqueue_sidekiq_job(AwesomeJob)
74
+ .with("Awesome!")
75
+ .on("default")
76
+ .at(specific_time)
77
+ )
78
+ ```
79
+
80
+ ### have_enqueued_sidekiq_job
81
+ *Describes that there should be an enqueued job with the **specified
82
+ arguments***
83
+
84
+ ```ruby
85
+ AwesomeJob.perform_async 'Awesome', true
86
+ # test with...
87
+ expect(AwesomeJob).to have_enqueued_sidekiq_job('Awesome', true)
88
+ ```
89
+
90
+ You can use the built-in RSpec args matchers too:
91
+ ```ruby
92
+ AwesomeJob.perform_async({"something" => "Awesome", "extra" => "stuff"})
93
+
94
+ # using built-in matchers from rspec-mocks:
95
+ expect(AwesomeJob).to have_enqueued_sidekiq_job(hash_including("something" => "Awesome"))
96
+ expect(AwesomeJob).to have_enqueued_sidekiq_job(any_args)
97
+ expect(AwesomeJob).to have_enqueued_sidekiq_job(hash_excluding("bad_stuff" => anything))
98
+ ```
99
+
100
+ #### Testing scheduled jobs
101
+
102
+ *Use chainable matchers `#at` and `#in`*
103
+
104
+ ```ruby
105
+ time = 5.minutes.from_now
106
+ AwesomeJob.perform_at time, 'Awesome', true
107
+ # test with...
108
+ expect(AwesomeJob).to have_enqueued_sidekiq_job('Awesome', true).at(time)
109
+ ```
110
+ ```ruby
111
+ AwesomeJob.perform_in 5.minutes, 'Awesome', true
112
+ # test with...
113
+ expect(AwesomeJob).to have_enqueued_sidekiq_job('Awesome', true).in(5.minutes)
114
+ ```
115
+
116
+ #### Testing queue set for job
117
+
118
+ Use the chainable `#on` matcher
119
+
120
+ ```ruby
121
+ class AwesomeJob
122
+ include Sidekiq::Job
123
+
124
+ sidekiq_options queue: :low
125
+ end
126
+
127
+ AwesomeJob.perform_async("a little awesome")
128
+
129
+ # test with..
130
+ expect(AwesomeJob).to have_enqueued_sidekiq_job("a little awesome").on("low")
131
+
132
+ # Setting the queue when enqueuing
133
+ AwesomeJob.set(queue: "high").perform_async("Very Awesome!")
134
+
135
+ expect(AwesomeJob).to have_enqueued_sidekiq_job("Very Awesome!").on("high")
136
+ ```
137
+
138
+ #### Testing ActiveMailer jobs
139
+
140
+ ```ruby
141
+ user = User.first
142
+ AwesomeActionMailer.invite(user, true).deliver_later
143
+
144
+ expect(Sidekiq::Worker).to have_enqueued_sidekiq_job(
145
+ "AwesomeActionMailer",
146
+ "invite",
147
+ "deliver_now",
148
+ user,
149
+ true
150
+ )
151
+ ```
152
+
153
+ #### Testing a job is _not_ enqueued
154
+
155
+ The negative case for `have_enqueued_sidekiq_job` is provided, but it's
156
+ important to remember that `have_enqueued_sidekiq_job` is an expectation that a
157
+ job is enqueued _with specific arguments_. In other words, passing no arguments
158
+ to `have_enqueued_sidekiq_job` is implicitly telling the matcher to look for
159
+ jobs _without_ arguments.
160
+
161
+ In short, unless you tell the matcher that _no_ jobs with _any_ arguments should be enqueued, you'll get the wrong result:
162
+
163
+ ```ruby
164
+ # example this is a test that we'd expect to fail
165
+ AwesomeJob.perform_async "Actually not awesome"
166
+
167
+ ### BAD - saying there shouldn't be a job enqueued _without_ args
168
+ expect(AwesomeJob).not_to have_enqueued_sidekiq_job
169
+ # => passes! 😱 Our job was enqueued _with_ args so no job exists without args.
170
+
171
+ ### Good
172
+ expect(AwesomeJob).not_to have_enqueued_sidekiq_job(any_args)
173
+ # => fails
78
174
  ```
79
175
 
80
176
  ### be_processed_in
@@ -87,7 +183,7 @@ it { is_expected.to be_processed_in :download }
87
183
  ```
88
184
 
89
185
  ### be_retryable
90
- *Describes if a job should retry when there is a failure in it's execution*
186
+ *Describes if a job should retry when there is a failure in its execution*
91
187
  ```ruby
92
188
  sidekiq_options retry: 5
93
189
  # test with...
@@ -102,13 +198,13 @@ it { is_expected.to be_retryable false }
102
198
  ```
103
199
 
104
200
  ### save_backtrace
105
- *Describes if a job should save the error backtrace when there is a failure in it's execution*
201
+ *Describes if a job should save the error backtrace when there is a failure in its execution*
106
202
  ```ruby
107
203
  sidekiq_options backtrace: 5
108
204
  # test with...
109
205
  expect(AwesomeJob).to save_backtrace # or
110
206
  it { is_expected.to save_backtrace }
111
- # ...or alternatively specifiy the number of lines that should be saved
207
+ # ...or alternatively specify the number of lines that should be saved
112
208
  expect(AwesomeJob).to save_backtrace 5 # or
113
209
  it { is_expected.to save_backtrace 5 }
114
210
  # ...or when it should not save the backtrace
@@ -119,7 +215,7 @@ it { is_expected.to save_backtrace false }
119
215
  ```
120
216
 
121
217
  ### be_unique
122
- *Describes when a job should be unique within it's queue*
218
+ *Describes when a job should be unique within its queue*
123
219
  ```ruby
124
220
  sidekiq_options unique: true
125
221
  # test with...
@@ -136,33 +232,32 @@ it { is_expected.to be_expired_in 1.hour }
136
232
  it { is_expected.to_not be_expired_in 2.hours }
137
233
  ```
138
234
 
139
- ### have_enqueued__sidekiq_job
140
- *Describes that there should be an enqueued job with the specified arguments*
235
+ ### be_delayed
141
236
 
142
- **Note:** When using rspec-rails >= 3.4, use `have_enqueued_sidekiq_job` instead to
143
- prevent a name clash with rspec-rails' ActiveJob matcher.
237
+ **This matcher is deprecated**. Use of it with Sidekiq 7+ will raise an error.
238
+ Sidekiq 7 [dropped Delayed
239
+ Extensions](https://github.com/sidekiq/sidekiq/issues/5076).
144
240
 
241
+ *Describes a method that should be invoked asynchronously (See [Sidekiq Delayed Extensions][sidekiq_wiki_delayed_extensions])*
145
242
  ```ruby
146
- AwesomeJob.perform_async 'Awesome', true
147
- # test with...
148
- expect(AwesomeJob).to have_enqueued_sidekiq_job('Awesome', true)
243
+ Object.delay.is_nil? # delay
244
+ expect(Object.method :is_nil?).to be_delayed
245
+ Object.delay.is_a? Object # delay with argument
246
+ expect(Object.method :is_a?).to be_delayed(Object)
149
247
 
150
- # Code written with older versions of the gem may use the deprecated
151
- # have_enqueued_job matcher.
152
- expect(AwesomeJob).to have_enqueued_job('Awesome', true)
153
- ```
248
+ Object.delay_for(1.hour).is_nil? # delay for
249
+ expect(Object.method :is_nil?).to be_delayed.for 1.hour
250
+ Object.delay_for(1.hour).is_a? Object # delay for with argument
251
+ expect(Object.method :is_a?).to be_delayed(Object).for 1.hour
154
252
 
155
- #### Testing scheduled jobs
156
- *Use chainable matchers `#at` and `#in`*
157
- ```ruby
158
- Awesomejob.perform_at 5.minutes.from_now, 'Awesome', true
159
- # test with...
160
- expect(AwesomeJob).to have_enqueued_sidekiq_job('Awesome', true).at(5.minutes.from_now)
161
- ```
162
- ```ruby
163
- Awesomejob.perform_in 5.minutes, 'Awesome', true
164
- # test with...
165
- expect(AwesomeJob).to have_enqueued_sidekiq_job('Awesome', true).in(5.minutes)
253
+ Object.delay_until(1.hour.from_now).is_nil? # delay until
254
+ expect(Object.method :is_nil?).to be_delayed.until 1.hour.from_now
255
+ Object.delay_until(1.hour.from_now).is_a? Object # delay until with argument
256
+ expect(Object.method :is_a?).to be_delayed(Object).until 1.hour.from_now
257
+
258
+ #Rails Mailer
259
+ MyMailer.delay.some_mail
260
+ expect(MyMailer.instance_method :some_mail).to be_delayed
166
261
  ```
167
262
 
168
263
  ## Example matcher usage
@@ -184,11 +279,38 @@ end
184
279
  ```
185
280
 
186
281
  ## Helpers
187
- * [Batches (Sidekiq Pro)](#batches)
282
+ * [Batches (Sidekiq Pro) _experimental_](#batches)
188
283
  * [`within_sidekiq_retries_exhausted_block`](#within_sidekiq_retries_exhausted_block)
189
284
 
190
285
  ### Batches
191
- If you are using Sidekiq Batches ([Sidekiq Pro feature][sidekiq_wiki_batches]), rspec-sidekiq replaces the implementation (using the NullObject pattern) enabling testing without a Redis instance. Mocha and RSpec stubbing is supported here.
286
+
287
+ If you are using Sidekiq Batches ([Sidekiq Pro feature][sidekiq_wiki_batches]),
288
+ You can *opt-in* with `stub_batches` to make `rspec-sidekiq` mock the
289
+ implementation (using a NullObject pattern). This enables testing without a
290
+ Redis instance. Mocha and RSpec stubbing is supported here.
291
+
292
+ :warning: **Caution**: Opting-in to this feature, while allowing you to test without
293
+ having Redis, _does not_ provide the exact API that `Sidekiq::Batch` does. As
294
+ such it can cause surprises.
295
+
296
+
297
+ ```ruby
298
+ RSpec.describe "Using mocked batches", stub_batches: true do
299
+ it "uses mocked batches" do
300
+ batch = Sidekiq::Batch.new
301
+ batch.jobs do
302
+ SomeJob.perform_async 123
303
+ end
304
+
305
+ expect(SomeJob).to have_enqueued_sidekiq_job
306
+
307
+ # Caution, the NullObject pattern means that the mocked Batch implementation
308
+ # responds to anything... even if it's not on the true `Sidekiq::Batch` API
309
+ # For example, the following fails
310
+ expect { batch.foobar! }.to raise_error(NoMethodError)
311
+ end
312
+ end
313
+ ```
192
314
 
193
315
  ### within_sidekiq_retries_exhausted_block
194
316
  ```ruby
@@ -202,10 +324,15 @@ FooClass.within_sidekiq_retries_exhausted_block {
202
324
  ```
203
325
 
204
326
  ## Testing
205
- ```bundle exec rspec spec```
327
+ ```
328
+ bundle exec rspec spec
329
+ ```
206
330
 
207
331
  ## Maintainers
208
- * @wpolicarpo
332
+ * @wspurgin
333
+
334
+ ### Alumni
335
+
209
336
  * @packrat386
210
337
  * @philostler
211
338
 
@@ -214,20 +341,14 @@ Please do! If there's a feature missing that you'd love to see then get in on th
214
341
 
215
342
  Issues/Pull Requests/Comments all welcome...
216
343
 
217
- [code_climate]: https://codeclimate.com/github/philostler/rspec-sidekiq
218
- [code_climate_badge]: https://codeclimate.com/github/philostler/rspec-sidekiq.svg
219
- [coveralls]: https://coveralls.io/r/philostler/rspec-sidekiq
220
- [coveralls_badge]: https://img.shields.io/coveralls/philostler/rspec-sidekiq.svg?branch=develop
221
344
  [gem_version_badge]: https://badge.fury.io/rb/rspec-sidekiq.svg
222
- [gemnasium]: https://gemnasium.com/philostler/rspec-sidekiq
223
- [gemnasium_badge]: https://gemnasium.com/philostler/rspec-sidekiq.svg
224
- [github]: http://github.com/philostler/rspec-sidekiq
345
+ [github]: http://github.com/wspurgin/rspec-sidekiq
225
346
  [ruby_doc]: http://rubydoc.info/gems/rspec-sidekiq/frames
226
347
  [ruby_gems]: http://rubygems.org/gems/rspec-sidekiq
227
348
  [ruby_toolbox]: http://www.ruby-toolbox.com/projects/rspec-sidekiq
228
- [travis_ci]: http://travis-ci.org/philostler/rspec-sidekiq
229
- [travis_ci_badge]: https://travis-ci.org/philostler/rspec-sidekiq.svg?branch=develop
349
+ [github_actions]: https://github.com/wspurgin/rspec-sidekiq/actions
350
+ [github_actions_badge]: https://github.com/wspurgin/rspec-sidekiq/actions/workflows/main.yml/badge.svg
230
351
 
231
- [rspec_sidekiq_wiki_faq_&_troubleshooting]: https://github.com/philostler/rspec-sidekiq/wiki/FAQ-&-Troubleshooting
232
- [sidekiq_wiki_batches]: https://github.com/mperham/sidekiq/wiki/Batches
233
- [sidekiq_wiki_delayed_extensions]: https://github.com/mperham/sidekiq/wiki/Delayed-Extensions
352
+ [rspec_sidekiq_wiki_faq_&_troubleshooting]: https://github.com/wspurgin/rspec-sidekiq/wiki/FAQ-&-Troubleshooting
353
+ [sidekiq_wiki_batches]: https://github.com/sidekiq/sidekiq/wiki/Batches
354
+ [sidekiq_wiki_delayed_extensions]: https://github.com/sidekiq/sidekiq/wiki/Delayed-Extensions
@@ -9,7 +9,26 @@ if defined? Sidekiq::Batch
9
9
  end
10
10
  end
11
11
 
12
+ ##
13
+ # Sidekiq::Batch is a Sidekiq::Pro feature. However the general consensus is
14
+ # that, by defeault, you can't test without redis. RSpec::Sidekiq includes
15
+ # a "null object" pattern implementation to mock Batches. This will mock
16
+ # Sidekiq::Batch and prevent it from using Redis.
17
+ #
18
+ # This is _opt-in_ only feature.
19
+ #
20
+ # RSpec.describe "Using mocked batches", stub_batches: true do
21
+ # it "uses mocked batches" do
22
+ # batch = Sidekiq::Batch.new
23
+ # batch.jobs do
24
+ # SomeJob.perform_async 123
25
+ # end
26
+ #
27
+ # expect(SomeJob).to have_enqueued_sidekiq_job
28
+ # end
29
+ # end
12
30
  class NullBatch < NullObject
31
+ attr_accessor :description
13
32
  attr_reader :bid
14
33
 
15
34
  def initialize(bid = nil)
@@ -45,9 +64,17 @@ if defined? Sidekiq::Batch
45
64
  def join
46
65
  ::Sidekiq::Worker.drain_all
47
66
 
48
- @callbacks.each do |event, callback_class, options|
67
+ @callbacks.each do |event, callback, options|
49
68
  if event != :success || failures == 0
50
- callback_class.new.send("on_#{event}", self, options)
69
+ case callback
70
+ when Class
71
+ callback.new.send("on_#{event}", self, options)
72
+ when String
73
+ klass, meth = callback.split('#')
74
+ klass.constantize.new.send(meth, self, options)
75
+ else
76
+ raise ArgumentError, 'Unsupported callback notation'
77
+ end
51
78
  end
52
79
  end
53
80
  end
@@ -62,7 +89,7 @@ if defined? Sidekiq::Batch
62
89
  # :nocov:
63
90
  RSpec.configure do |config|
64
91
  config.before(:each) do |example|
65
- next if example.metadata[:stub_batches] == false
92
+ next unless example.metadata[:stub_batches] == true
66
93
 
67
94
  if mocked_with_mocha?
68
95
  Sidekiq::Batch.stubs(:new) { RSpec::Sidekiq::NullBatch.new }
@@ -1,13 +1,24 @@
1
+ require "rubygems"
2
+
1
3
  module RSpec
2
4
  module Sidekiq
3
5
  class Configuration
4
- attr_accessor :clear_all_enqueued_jobs, :enable_terminal_colours, :warn_when_jobs_not_processed_by_sidekiq
6
+ attr_accessor :clear_all_enqueued_jobs,
7
+ :enable_terminal_colours,
8
+ :warn_when_jobs_not_processed_by_sidekiq
5
9
 
6
10
  def initialize
7
- @clear_all_enqueued_jobs = true
11
+ # Display settings defaults
8
12
  @enable_terminal_colours = true
13
+
14
+ # Functional settings defaults
15
+ @clear_all_enqueued_jobs = true
9
16
  @warn_when_jobs_not_processed_by_sidekiq = true
10
17
  end
18
+
19
+ def sidekiq_gte_7?
20
+ Gem::Version.new(::Sidekiq::VERSION) >= Gem::Version.new("7.0.0")
21
+ end
11
22
  end
12
23
  end
13
24
  end