rspec-enqueue_sidekiq_job 1.0.0 → 1.2.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 +1 -1
- data/lib/rspec/enqueue_sidekiq_job.rb +28 -8
- data/lib/rspec/enqueue_sidekiq_job/version.rb +2 -2
- data/rspec-enqueue_sidekiq_job.gemspec +4 -4
- metadata +19 -21
- data/spec/rspec/enqueue_sidekiq_job_spec.rb +0 -203
- data/spec/spec_helper.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b97b2ee706f603920828b8ee122a3b47b2beb5099dd7ae95e3d5f007508c7948
|
4
|
+
data.tar.gz: 69e34ea50e0cdd337c5aadd9d7cc87742946d950b3fcc69045ca4b5c130e3538
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f689afe37fa8ae98e30081f0873bc735b9a4a91793597651818efb1c18378e05ceb7fa1d361663bcc9307117037067e0ec6fc7ee04036dfa5701c902c9d28c9
|
7
|
+
data.tar.gz: 185e782c55203982ee913571d2dfacfd645129402b602b5e6af939bd95ce7a6268606f8e15a06e7c076a1198828daba90552dfc7c9d4170693c8b5771310b7c1
|
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
require 'rspec'
|
2
1
|
require 'sidekiq/testing'
|
2
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
3
3
|
|
4
4
|
module RSpec
|
5
5
|
# An includable module that provides `enqueue_sidekiq_job` matcher
|
6
|
-
module
|
6
|
+
module EnqueueSidekiqJob
|
7
7
|
# Checks if a certain job was enqueued in a block.
|
8
8
|
#
|
9
9
|
# expect { AwesomeWorker.perform_async }
|
@@ -31,11 +31,14 @@ module RSpec
|
|
31
31
|
|
32
32
|
def initialize(worker_class)
|
33
33
|
@worker_class = worker_class
|
34
|
+
@expected_count = nil
|
34
35
|
end
|
35
36
|
|
36
|
-
def with(*expected_arguments
|
37
|
-
|
38
|
-
|
37
|
+
def with(*expected_arguments)
|
38
|
+
if expected_arguments.last.is_a?(Hash)
|
39
|
+
options = expected_arguments.pop
|
40
|
+
expected_arguments.push(options.with_indifferent_access)
|
41
|
+
end
|
39
42
|
@expected_arguments = expected_arguments
|
40
43
|
self
|
41
44
|
end
|
@@ -54,11 +57,26 @@ module RSpec
|
|
54
57
|
self
|
55
58
|
end
|
56
59
|
|
60
|
+
def times
|
61
|
+
self
|
62
|
+
end
|
63
|
+
|
64
|
+
def exactly(times)
|
65
|
+
@expected_count = times
|
66
|
+
self
|
67
|
+
end
|
68
|
+
|
69
|
+
def twice
|
70
|
+
exactly(2).times
|
71
|
+
end
|
72
|
+
|
57
73
|
def matches?(block)
|
58
|
-
filter(enqueued_in_block(block)).
|
74
|
+
filter(enqueued_in_block(block)).count == (expected_count || 1)
|
59
75
|
end
|
60
76
|
|
61
77
|
def does_not_match?(block)
|
78
|
+
raise 'counts are not supported with negation' if expected_count
|
79
|
+
|
62
80
|
filter(enqueued_in_block(block)).none?
|
63
81
|
end
|
64
82
|
|
@@ -67,6 +85,7 @@ module RSpec
|
|
67
85
|
message << " arguments: #{expected_arguments}" if expected_arguments
|
68
86
|
message << " in: #{expected_in.inspect}" if expected_in
|
69
87
|
message << " at: #{expected_at}" if expected_at
|
88
|
+
message << " exactly #{expected_count} times" if expected_count
|
70
89
|
message.join("\n")
|
71
90
|
end
|
72
91
|
|
@@ -75,6 +94,7 @@ module RSpec
|
|
75
94
|
message << " arguments: #{expected_arguments}" if expected_arguments
|
76
95
|
message << " in: #{expected_in.inspect}" if expected_in
|
77
96
|
message << " at: #{expected_at}" if expected_at
|
97
|
+
message << " exactly #{expected_count} times" if expected_count
|
78
98
|
message.join("\n")
|
79
99
|
end
|
80
100
|
|
@@ -120,7 +140,7 @@ module RSpec
|
|
120
140
|
expected_in.from_now.to_i == actual_time.to_i
|
121
141
|
end
|
122
142
|
|
123
|
-
attr_reader :worker_class, :expected_arguments, :expected_at, :expected_in
|
143
|
+
attr_reader :worker_class, :expected_arguments, :expected_at, :expected_in, :expected_count
|
124
144
|
end
|
125
145
|
|
126
146
|
private_constant :Matcher
|
@@ -128,5 +148,5 @@ module RSpec
|
|
128
148
|
end
|
129
149
|
|
130
150
|
RSpec.configure do |config|
|
131
|
-
config.include RSpec::
|
151
|
+
config.include RSpec::EnqueueSidekiqJob
|
132
152
|
end
|
@@ -2,7 +2,7 @@ require File.expand_path('lib/rspec/enqueue_sidekiq_job/version', __dir__)
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'rspec-enqueue_sidekiq_job'
|
5
|
-
s.version = RSpec::
|
5
|
+
s.version = RSpec::EnqueueSidekiqJob::VERSION
|
6
6
|
s.platform = Gem::Platform::RUBY
|
7
7
|
s.author = 'Phil Pirozhkov'
|
8
8
|
s.email = 'hello@fili.pp.ru'
|
@@ -13,15 +13,15 @@ Gem::Specification.new do |s|
|
|
13
13
|
|
14
14
|
s.required_ruby_version = '>= 2.4.0'
|
15
15
|
|
16
|
+
s.add_dependency 'activesupport', '> 5.2'
|
16
17
|
s.add_dependency 'rspec-core', '~> 3'
|
17
18
|
s.add_dependency 'rspec-expectations', '~> 3'
|
18
|
-
s.add_dependency 'sidekiq', '
|
19
|
+
s.add_dependency 'sidekiq', '> 3'
|
19
20
|
|
20
|
-
s.add_development_dependency 'activesupport'
|
21
21
|
s.add_development_dependency 'rspec'
|
22
22
|
s.add_development_dependency 'rubocop'
|
23
23
|
s.add_development_dependency 'rubocop-rspec'
|
24
24
|
|
25
|
-
s.files = %w[LICENSE README.md rspec-enqueue_sidekiq_job.gemspec] + Dir['
|
25
|
+
s.files = %w[LICENSE README.md rspec-enqueue_sidekiq_job.gemspec] + Dir['lib/**/*.rb']
|
26
26
|
s.require_paths = ['lib']
|
27
27
|
end
|
metadata
CHANGED
@@ -1,31 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-enqueue_sidekiq_job
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Phil Pirozhkov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '5.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: rspec-
|
28
|
+
name: rspec-core
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
@@ -39,33 +39,33 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rspec-expectations
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: '3'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: '3'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: sidekiq
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
62
|
-
type: :
|
61
|
+
version: '3'
|
62
|
+
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '3'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -119,8 +119,6 @@ files:
|
|
119
119
|
- lib/rspec/enqueue_sidekiq_job.rb
|
120
120
|
- lib/rspec/enqueue_sidekiq_job/version.rb
|
121
121
|
- rspec-enqueue_sidekiq_job.gemspec
|
122
|
-
- spec/rspec/enqueue_sidekiq_job_spec.rb
|
123
|
-
- spec/spec_helper.rb
|
124
122
|
homepage: http://github.com/pirj/rspec-enqueue_sidekiq_job
|
125
123
|
licenses:
|
126
124
|
- MIT
|
@@ -1,203 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe RSpec::EnqueuedSidekiqJob do
|
4
|
-
let(:worker) do
|
5
|
-
Class.new do
|
6
|
-
include ::Sidekiq::Worker
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
let(:another_worker) do
|
11
|
-
Class.new do
|
12
|
-
include ::Sidekiq::Worker
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'raises ArgumentError when used in value expectation', pending: 'only fails with ArgumentError on RSpec 4' do
|
17
|
-
expect {
|
18
|
-
expect(worker.perform_async).to enqueue_sidekiq_job(worker)
|
19
|
-
}.to raise_error(ArgumentError)
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'fails when no worker class is specified' do
|
23
|
-
expect {
|
24
|
-
expect { worker.perform_async }.to enqueue_sidekiq_job
|
25
|
-
}.to raise_error(ArgumentError)
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'passes' do
|
29
|
-
expect { worker.perform_async }
|
30
|
-
.to enqueue_sidekiq_job(worker)
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'fails when negated and job is enqueued' do
|
34
|
-
expect {
|
35
|
-
expect { worker.perform_async }.not_to enqueue_sidekiq_job(worker)
|
36
|
-
}.to raise_error(/expected not to enqueue/)
|
37
|
-
end
|
38
|
-
|
39
|
-
context 'when no jobs were enqueued' do
|
40
|
-
it 'fails' do
|
41
|
-
expect {
|
42
|
-
expect {} # nop
|
43
|
-
.to enqueue_sidekiq_job(worker)
|
44
|
-
}.to raise_error(/expected to enqueue/)
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'passes with negation' do
|
48
|
-
expect {} # nop
|
49
|
-
.not_to enqueue_sidekiq_job(worker)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
context 'with another worker' do
|
54
|
-
it 'fails' do
|
55
|
-
expect {
|
56
|
-
expect { worker.perform_async }
|
57
|
-
.to enqueue_sidekiq_job(another_worker)
|
58
|
-
}.to raise_error(/expected to enqueue/)
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'passes with negation' do
|
62
|
-
expect { worker.perform_async }
|
63
|
-
.not_to enqueue_sidekiq_job(another_worker)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'counts only jobs enqueued in block' do
|
68
|
-
worker.perform_async
|
69
|
-
expect {}.not_to enqueue_sidekiq_job(worker)
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'counts jobs enqueued in block' do
|
73
|
-
worker.perform_async
|
74
|
-
expect { worker.perform_async }.to enqueue_sidekiq_job(worker)
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'fails when too many jobs enqueued' do
|
78
|
-
expect {
|
79
|
-
expect {
|
80
|
-
worker.perform_async
|
81
|
-
worker.perform_async
|
82
|
-
}.to enqueue_sidekiq_job(worker)
|
83
|
-
}.to raise_error(/expected to enqueue/)
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'fails when negated and several jobs enqueued' do
|
87
|
-
expect {
|
88
|
-
expect {
|
89
|
-
worker.perform_async
|
90
|
-
worker.perform_async
|
91
|
-
}.not_to enqueue_sidekiq_job(worker)
|
92
|
-
}.to raise_error(/expected not to enqueue/)
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'passes with multiple jobs' do
|
96
|
-
expect {
|
97
|
-
another_worker.perform_async
|
98
|
-
worker.perform_async
|
99
|
-
}
|
100
|
-
.to enqueue_sidekiq_job(worker)
|
101
|
-
.and enqueue_sidekiq_job(another_worker)
|
102
|
-
end
|
103
|
-
|
104
|
-
context 'when enqueued with perform_at' do
|
105
|
-
it 'passes' do
|
106
|
-
future = 1.minute.from_now
|
107
|
-
expect { worker.perform_at(future) }
|
108
|
-
.to enqueue_sidekiq_job(worker).at(future)
|
109
|
-
end
|
110
|
-
|
111
|
-
it 'fails when timestamps do not match' do
|
112
|
-
future = 1.minute.from_now
|
113
|
-
expect {
|
114
|
-
expect { worker.perform_at(future) }
|
115
|
-
.to enqueue_sidekiq_job(worker).at(2.minutes.from_now)
|
116
|
-
}.to raise_error(/expected to enqueue.+at:/m)
|
117
|
-
end
|
118
|
-
|
119
|
-
it 'matches timestamps with nanosecond precision' do
|
120
|
-
100.times do
|
121
|
-
future = 1.minute.from_now
|
122
|
-
future = future.change(nsec: future.nsec.round(-3) + rand(999))
|
123
|
-
expect { worker.perform_at(future) }
|
124
|
-
.to enqueue_sidekiq_job(worker).at(future)
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
it 'accepts composable matchers' do
|
129
|
-
future = 1.minute.from_now
|
130
|
-
slightly_earlier = 58.seconds.from_now
|
131
|
-
expect { worker.perform_at(slightly_earlier) }
|
132
|
-
.to enqueue_sidekiq_job(worker).at(a_value_within(5.seconds).of(future))
|
133
|
-
end
|
134
|
-
|
135
|
-
it 'fails when the job was enuqued for now' do
|
136
|
-
expect {
|
137
|
-
expect { worker.perform_async }
|
138
|
-
.to enqueue_sidekiq_job(worker).at(1.minute.from_now)
|
139
|
-
}.to raise_error(/expected to enqueue.+at:/m)
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
context 'when enqueued with perform_in' do
|
144
|
-
it 'passes' do
|
145
|
-
interval = 1.minute
|
146
|
-
expect { worker.perform_in(interval) }
|
147
|
-
.to enqueue_sidekiq_job(worker).in(interval)
|
148
|
-
end
|
149
|
-
|
150
|
-
it 'fails when timestamps do not match' do
|
151
|
-
interval = 1.minute
|
152
|
-
expect {
|
153
|
-
expect { worker.perform_in(interval) }
|
154
|
-
.to enqueue_sidekiq_job(worker).in(2.minutes)
|
155
|
-
}.to raise_error(/expected to enqueue.+in:/m)
|
156
|
-
end
|
157
|
-
|
158
|
-
it 'fails when the job was enuqued for now' do
|
159
|
-
expect {
|
160
|
-
expect { worker.perform_async }
|
161
|
-
.to enqueue_sidekiq_job(worker).in(1.minute)
|
162
|
-
}.to raise_error(/expected to enqueue.+in:/m)
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
it 'matches when not specified at and scheduled for the future' do
|
167
|
-
expect { worker.perform_in(1.day) }
|
168
|
-
.to enqueue_sidekiq_job(worker)
|
169
|
-
expect { worker.perform_at(1.day.from_now) }
|
170
|
-
.to enqueue_sidekiq_job(worker)
|
171
|
-
end
|
172
|
-
|
173
|
-
context 'with arguments' do
|
174
|
-
it 'fails with kwargs' do
|
175
|
-
expect {
|
176
|
-
expect { worker.perform_async }
|
177
|
-
.to enqueue_sidekiq_job(worker).with(42, name: 'David')
|
178
|
-
}.to raise_error(/keyword arguments serialization is not supported by Sidekiq/)
|
179
|
-
end
|
180
|
-
|
181
|
-
it 'passes with provided arguments' do
|
182
|
-
expect { worker.perform_async(42, 'David') }
|
183
|
-
.to enqueue_sidekiq_job(worker).with(42, 'David')
|
184
|
-
end
|
185
|
-
|
186
|
-
it 'supports provided argument matchers' do
|
187
|
-
expect { worker.perform_async(42, 'David') }
|
188
|
-
.to enqueue_sidekiq_job(worker).with(be > 41, a_string_including('Dav'))
|
189
|
-
end
|
190
|
-
|
191
|
-
it 'passes when negated and arguments do not match' do
|
192
|
-
expect { worker.perform_async(42, 'David') }
|
193
|
-
.not_to enqueue_sidekiq_job(worker).with(11, 'Phil')
|
194
|
-
end
|
195
|
-
|
196
|
-
it 'fails when arguments do not match' do
|
197
|
-
expect {
|
198
|
-
expect { worker.perform_async(42, 'David') }
|
199
|
-
.to enqueue_sidekiq_job(worker).with(11, 'Phil')
|
200
|
-
}.to raise_error(/expected to enqueue.+arguments:/m)
|
201
|
-
end
|
202
|
-
end
|
203
|
-
end
|
data/spec/spec_helper.rb
DELETED