rspec-sidekiq 4.0.0 → 4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb94abca8e805aa88d9c84deb0ddb22746542845b48cde790c4da9ae58f48ca0
4
- data.tar.gz: 646f1ee2cc023cd988f29b50250c6794cb7563a78c35a397f1f3290cbf9df97b
3
+ metadata.gz: a4f0ece401056914cf478dc4657d19aad569156ebf40ee29ee85c36fc430cfc3
4
+ data.tar.gz: 858c2c49ae54497a5201eab4cb3d9179fbe21a1684b11663719dfd17dd198cb2
5
5
  SHA512:
6
- metadata.gz: 0d0b4a026d3e28f55e03076023b83eb11334cd2759514837f0fd37ce74d01279bf0aa53236e84185eb89e949ad429f21c40e09d1858c5a0beb622f5001617311
7
- data.tar.gz: 42c83b796648b68262a689f6fabe441719347e9464505ca4ade74ebab9cad748e51896af223b441adda74fe9b6300cb9ecb1f1974843fa45cf225dcbefc996ca
6
+ metadata.gz: 831dfa10d07623e001f2253072b6d8e5311a0d887661421ba3eb914fce8f5020b73e5c7bda02264ebf4be6b6f23c2b02f8082a149d7ff5836895525ae61d697c
7
+ data.tar.gz: fda99d4e3bd9b43fb55ed60e96f77fd0ca54156bc6dcc42df3f1d2fb9323fff9fc63f5495a595766e937d0214fff10736ef18b9b468fccf4b97b91b2aae5e296
data/CHANGES.md CHANGED
@@ -1,3 +1,18 @@
1
+ 4.1.0
2
+ ---
3
+ * Add Composable support to `enqueue_sidekiq_job` and
4
+ `have_enqueued_sidekiq_job` (#211)
5
+ * Add `immediately` to specify that a job should be enqueued without any delay (#210)
6
+
7
+ 4.0.2
8
+ ---
9
+ * Explicitly require forwardable (#204)
10
+
11
+ 4.0.1
12
+ ---
13
+ * Restore the old normalizing expected args behavior with symbols (#205)
14
+ * fixes an unintentional breaking change in 4.0.0
15
+
1
16
  4.0.0
2
17
  ---
3
18
  * [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)`.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  **Welcome @wspurgin as new maintainer for `rspec-sidekiq`!**
2
2
 
3
- [![RubyGems][gem_version_badge]][ruby_gems]
3
+ [![Gem Version](https://badge.fury.io/rb/rspec-sidekiq.svg)](https://badge.fury.io/rb/rspec-sidekiq)
4
4
  [![Github Actions CI][github_actions_badge]][github_actions]
5
5
 
6
6
  Simple testing of Sidekiq jobs via a collection of matchers and helpers.
@@ -75,11 +75,17 @@ expect { AwesomeJob.perform_at(specific_time, "Awesome!") }.to(
75
75
  .on("default")
76
76
  .at(specific_time)
77
77
  )
78
+
79
+ # Also composable
80
+ expect do
81
+ AwesomeJob.perform_async
82
+ OtherJob.perform_async
83
+ end.to enqueue_sidekiq_job(AwesomeJob).and enqueue_sidekiq_job(OtherJob)
78
84
  ```
79
85
 
80
86
  ### have_enqueued_sidekiq_job
81
- *Describes that there should be an enqueued job with the **specified
82
- arguments***
87
+
88
+ Describes that there should be an enqueued job with the **specified arguments**
83
89
 
84
90
  ```ruby
85
91
  AwesomeJob.perform_async 'Awesome', true
@@ -95,11 +101,14 @@ AwesomeJob.perform_async({"something" => "Awesome", "extra" => "stuff"})
95
101
  expect(AwesomeJob).to have_enqueued_sidekiq_job(hash_including("something" => "Awesome"))
96
102
  expect(AwesomeJob).to have_enqueued_sidekiq_job(any_args)
97
103
  expect(AwesomeJob).to have_enqueued_sidekiq_job(hash_excluding("bad_stuff" => anything))
104
+
105
+ # composable as well
106
+ expect(AwesomeJob).to have_enqueued_sidekiq_job(any_args).and have_enqueued_sidekiq_job(hash_including("something" => "Awesome"))
98
107
  ```
99
108
 
100
109
  #### Testing scheduled jobs
101
110
 
102
- *Use chainable matchers `#at` and `#in`*
111
+ *Use chainable matchers `#at`, `#in` and `#immediately`*
103
112
 
104
113
  ```ruby
105
114
  time = 5.minutes.from_now
@@ -113,6 +122,13 @@ AwesomeJob.perform_in 5.minutes, 'Awesome', true
113
122
  expect(AwesomeJob).to have_enqueued_sidekiq_job('Awesome', true).in(5.minutes)
114
123
  ```
115
124
 
125
+ ```ruby
126
+ # Job scheduled for a date in the past are enqueued immediately.
127
+ AwesomeJob.perform_later 5.minutes.ago, 'Awesome', true # equivalent to: AwesomeJob.perform_async 'Awesome', true
128
+ # test with...
129
+ expect(AwesomeJob).to have_enqueued_sidekiq_job('Awesome', true).immediately
130
+ ```
131
+
116
132
  #### Testing queue set for job
117
133
 
118
134
  Use the chainable `#on` matcher
@@ -341,11 +357,7 @@ Please do! If there's a feature missing that you'd love to see then get in on th
341
357
 
342
358
  Issues/Pull Requests/Comments all welcome...
343
359
 
344
- [gem_version_badge]: https://badge.fury.io/rb/rspec-sidekiq.svg
345
360
  [github]: http://github.com/wspurgin/rspec-sidekiq
346
- [ruby_doc]: http://rubydoc.info/gems/rspec-sidekiq/frames
347
- [ruby_gems]: http://rubygems.org/gems/rspec-sidekiq
348
- [ruby_toolbox]: http://www.ruby-toolbox.com/projects/rspec-sidekiq
349
361
  [github_actions]: https://github.com/wspurgin/rspec-sidekiq/actions
350
362
  [github_actions_badge]: https://github.com/wspurgin/rspec-sidekiq/actions/workflows/main.yml/badge.svg
351
363
 
@@ -16,7 +16,7 @@ module RSpec
16
16
  private
17
17
 
18
18
  def at_evaluator(value)
19
- return false if job["at"].to_s.empty?
19
+ return value.nil? if job["at"].to_s.empty?
20
20
  value == Time.at(job["at"]).to_i
21
21
  end
22
22
 
@@ -162,6 +162,7 @@ module RSpec
162
162
  # @api private
163
163
  class Base
164
164
  include RSpec::Mocks::ArgumentMatchers
165
+ include RSpec::Matchers::Composable
165
166
 
166
167
  attr_reader :expected_arguments, :expected_options, :klass, :actual_jobs
167
168
 
@@ -171,7 +172,7 @@ module RSpec
171
172
  end
172
173
 
173
174
  def with(*expected_arguments)
174
- @expected_arguments = expected_arguments
175
+ @expected_arguments = normalize_arguments(expected_arguments)
175
176
  self
176
177
  end
177
178
 
@@ -185,6 +186,11 @@ module RSpec
185
186
  self
186
187
  end
187
188
 
189
+ def immediately
190
+ @expected_options["at"] = nil
191
+ self
192
+ end
193
+
188
194
  def on(queue)
189
195
  @expected_options["queue"] = queue
190
196
  self
@@ -237,18 +243,17 @@ module RSpec
237
243
  RSpec::Support::ObjectFormatter.format(thing)
238
244
  end
239
245
 
240
- def jsonified_expected_arguments
241
- # We would just cast-to-parse-json, but we need to support
242
- # RSpec matcher args like #kind_of
243
- @jsonified_expected_arguments ||= begin
244
- expected_arguments.map do |arg|
245
- case arg.class
246
- when Symbol then arg.to_s
247
- when Hash then JSON.parse(arg.to_json)
248
- else
249
- arg
250
- end
246
+ def normalize_arguments(args)
247
+ if args.is_a?(Array)
248
+ args.map{ |x| normalize_arguments(x) }
249
+ elsif args.is_a?(Hash)
250
+ args.each_with_object({}) do |(key, value), hash|
251
+ hash[key.to_s] = normalize_arguments(value)
251
252
  end
253
+ elsif args.is_a?(Symbol)
254
+ args.to_s
255
+ else
256
+ args
252
257
  end
253
258
  end
254
259
  end
@@ -56,7 +56,8 @@ module RSpec
56
56
  #
57
57
  # Passes if a Job is enqueued as the result of a block. Chainable `with`
58
58
  # for arguments, `on` for queue, `at` for queued for a specific time, and
59
- # `in` for a specific interval delay to being queued
59
+ # `in` for a specific interval delay to being queued, `immediately` for
60
+ # queued without delay.
60
61
  #
61
62
  # @example
62
63
  #
@@ -79,6 +80,17 @@ module RSpec
79
80
  # freeze_time do
80
81
  # expect { AwesomeJob.perform_in(1.hour) }.to enqueue_sidekiq_job.in(1.hour)
81
82
  # end
83
+ #
84
+ # # Without any delay
85
+ # expect { AwesomeJob.perform_async }.to enqueue_sidekiq_job.immediately
86
+ # expect { AwesomeJob.perform_at(1.hour.ago) }.to enqueue_sidekiq_job.immediately
87
+ #
88
+ # ## Composable
89
+ #
90
+ # expect do
91
+ # AwesomeJob.perform_async
92
+ # OtherJob.perform_async
93
+ # end.to enqueue_sidekiq_job(AwesomeJob).and enqueue_sidekiq_job(OtherJob)
82
94
  def enqueue_sidekiq_job(job_class = nil)
83
95
  EnqueueSidekiqJob.new(job_class)
84
96
  end
@@ -9,7 +9,7 @@ module RSpec
9
9
  class HaveEnqueuedSidekiqJob < Base
10
10
  def initialize(expected_arguments)
11
11
  super()
12
- @expected_arguments = expected_arguments
12
+ @expected_arguments = normalize_arguments(expected_arguments)
13
13
  end
14
14
 
15
15
  def matches?(job_class)
@@ -17,7 +17,7 @@ module RSpec
17
17
 
18
18
  @actual_jobs = EnqueuedJobs.new(klass)
19
19
 
20
- actual_jobs.includes?(jsonified_expected_arguments, expected_options)
20
+ actual_jobs.includes?(expected_arguments, expected_options)
21
21
  end
22
22
  end
23
23
  end
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module Sidekiq
3
- VERSION = "4.0.0"
3
+ VERSION = "4.1.0"
4
4
  end
5
5
  end
data/lib/rspec-sidekiq.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'forwardable'
2
+
1
3
  require 'sidekiq'
2
4
  require 'sidekiq/testing'
3
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-sidekiq
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aidan Coyle
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-08-15 00:00:00.000000000 Z
13
+ date: 2023-10-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec-core
@@ -266,7 +266,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
266
266
  requirements:
267
267
  - - ">="
268
268
  - !ruby/object:Gem::Version
269
- version: '0'
269
+ version: '2.7'
270
270
  required_rubygems_version: !ruby/object:Gem::Requirement
271
271
  requirements:
272
272
  - - ">="