rspec-sidekiq 3.0.3 → 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 +5 -5
- data/CHANGES.md +43 -0
- data/LICENSE +12 -0
- data/README.md +217 -84
- data/lib/rspec/sidekiq/batch.rb +30 -3
- data/lib/rspec/sidekiq/configuration.rb +13 -2
- data/lib/rspec/sidekiq/matchers/base.rb +262 -0
- data/lib/rspec/sidekiq/matchers/be_delayed.rb +17 -3
- data/lib/rspec/sidekiq/matchers/enqueue_sidekiq_job.rb +99 -0
- data/lib/rspec/sidekiq/matchers/have_enqueued_sidekiq_job.rb +25 -0
- data/lib/rspec/sidekiq/matchers.rb +13 -8
- data/lib/rspec/sidekiq/sidekiq.rb +1 -1
- data/lib/rspec/sidekiq/version.rb +1 -1
- data/lib/rspec-sidekiq.rb +2 -0
- metadata +130 -83
- data/.gitattributes +0 -22
- data/.gitignore +0 -2
- data/.rspec +0 -4
- data/.simplecov +0 -5
- data/Gemfile +0 -9
- data/lib/rspec/sidekiq/matchers/have_enqueued_job.rb +0 -183
- data/rspec-sidekiq.gemspec +0 -37
- data/spec/rspec/sidekiq/batch_spec.rb +0 -77
- data/spec/rspec/sidekiq/helpers/retries_exhausted_spec.rb +0 -40
- data/spec/rspec/sidekiq/matchers/be_delayed_spec.rb +0 -238
- data/spec/rspec/sidekiq/matchers/be_expired_in_spec.rb +0 -57
- data/spec/rspec/sidekiq/matchers/be_processed_in_spec.rb +0 -114
- data/spec/rspec/sidekiq/matchers/be_retryable_spec.rb +0 -129
- data/spec/rspec/sidekiq/matchers/be_unique_spec.rb +0 -115
- data/spec/rspec/sidekiq/matchers/have_enqueued_job_spec.rb +0 -228
- data/spec/rspec/sidekiq/matchers/save_backtrace_spec.rb +0 -136
- data/spec/rspec/sidekiq/sidekiq_spec.rb +0 -15
- data/spec/spec_helper.rb +0 -29
- data/spec/support/factories.rb +0 -33
- data/spec/support/init.rb +0 -6
- data/spec/support/test_action_mailer.rb +0 -6
- data/spec/support/test_job.rb +0 -6
- data/spec/support/test_resource.rb +0 -16
- data/spec/support/test_worker.rb +0 -8
- data/spec/support/test_worker_alternative.rb +0 -8
@@ -1,77 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe 'Batch' do
|
4
|
-
module Sidekiq
|
5
|
-
module Batch
|
6
|
-
class Status
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
load File.expand_path(File.join(File.dirname(__FILE__), '../../../lib/rspec/sidekiq/batch.rb'))
|
12
|
-
|
13
|
-
describe 'NullObject' do
|
14
|
-
describe '#method_missing' do
|
15
|
-
it 'returns itself' do
|
16
|
-
batch = Sidekiq::Batch.new
|
17
|
-
expect(batch.non_existent_method).to eq(batch)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe 'NullBatch' do
|
23
|
-
end
|
24
|
-
|
25
|
-
describe 'NullStatus' do
|
26
|
-
let(:batch) { Sidekiq::Batch.new }
|
27
|
-
|
28
|
-
subject { batch.status }
|
29
|
-
|
30
|
-
describe '#total' do
|
31
|
-
it 'returns 0 when no jobs' do
|
32
|
-
expect(subject.total).to eq(0)
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'returns 1 when 1 job' do
|
36
|
-
batch.jobs do
|
37
|
-
TestWorker.perform_async('5')
|
38
|
-
end
|
39
|
-
|
40
|
-
expect(subject.total).to eq(1)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe '#failures' do
|
45
|
-
it 'returns 0' do
|
46
|
-
expect(subject.failures).to eq(0)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe '#bid' do
|
51
|
-
it 'returns a bid' do
|
52
|
-
expect(subject.bid).to_not be_nil
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe '#join' do
|
57
|
-
class MyCallback
|
58
|
-
def on_event(status, options); end
|
59
|
-
end
|
60
|
-
|
61
|
-
before(:each) do
|
62
|
-
batch.on(:event, MyCallback, my_arg: 42)
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'executes callbacks' do
|
66
|
-
expect_any_instance_of(MyCallback).to receive(:on_event).with(subject, { my_arg: 42 })
|
67
|
-
subject.join
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe '#initialize' do
|
72
|
-
it 'uses default argument values when none are provided' do
|
73
|
-
expect { Sidekiq::Batch::Status.new }.to_not raise_error
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe 'Retries Exhausted block' do
|
4
|
-
class FooClass < TestWorkerAlternative
|
5
|
-
sidekiq_retries_exhausted do |msg, exception|
|
6
|
-
bar('hello')
|
7
|
-
foo(msg)
|
8
|
-
baz(exception)
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.bar(input)
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.foo(msg)
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.baz(exception)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'executes whatever is within the block' do
|
22
|
-
FooClass.within_sidekiq_retries_exhausted_block { expect(FooClass).to receive(:bar).with('hello') }
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'passes message and exception to the block' do
|
26
|
-
args = { 'args' => ['a', 'b']}
|
27
|
-
exception = StandardError.new('something went wrong')
|
28
|
-
FooClass.within_sidekiq_retries_exhausted_block(args, exception) do
|
29
|
-
expect(FooClass).to receive(:foo).with(FooClass.default_retries_exhausted_message.merge(args))
|
30
|
-
expect(FooClass).to receive(:baz).with(exception)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'sets a default value for the message and exception' do
|
35
|
-
FooClass.within_sidekiq_retries_exhausted_block do
|
36
|
-
expect(FooClass).to receive(:foo).with(FooClass.default_retries_exhausted_message)
|
37
|
-
expect(FooClass).to receive(:baz).with(FooClass.default_retries_exhausted_exception)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,238 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe RSpec::Sidekiq::Matchers::BeDelayed do
|
4
|
-
let(:delay_subject) { RSpec::Sidekiq::Matchers::BeDelayed.new }
|
5
|
-
let(:delay_with_arguments_subject) { RSpec::Sidekiq::Matchers::BeDelayed.new Object }
|
6
|
-
let(:delay_for_subject) { RSpec::Sidekiq::Matchers::BeDelayed.new.for 3600 }
|
7
|
-
let(:delay_for_with_arguments_subject) { RSpec::Sidekiq::Matchers::BeDelayed.new(Object).for 3600 }
|
8
|
-
let(:delay_until_subject) { RSpec::Sidekiq::Matchers::BeDelayed.new.until Time.now + 3600 }
|
9
|
-
let(:delay_until_with_arguments_subject) { RSpec::Sidekiq::Matchers::BeDelayed.new(Object).until Time.now + 3600 }
|
10
|
-
before(:each) do
|
11
|
-
delay_subject.matches? Object.method :nil?
|
12
|
-
delay_with_arguments_subject.matches? Object.method :is_a?
|
13
|
-
|
14
|
-
delay_for_subject.matches? Object.method :nil?
|
15
|
-
delay_for_with_arguments_subject.matches? Object.method :is_a?
|
16
|
-
|
17
|
-
delay_until_subject.matches? Object.method :nil?
|
18
|
-
delay_until_with_arguments_subject.matches? Object.method :is_a?
|
19
|
-
end
|
20
|
-
|
21
|
-
describe 'expected usage' do
|
22
|
-
it 'matches' do
|
23
|
-
Object.delay_for(3600).is_a? Object
|
24
|
-
|
25
|
-
expect(Object.method :is_a?).to be_delayed(Object).for 3600
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe '#be_delayed_job' do
|
30
|
-
it 'returns instance' do
|
31
|
-
expect(be_delayed).to be_a RSpec::Sidekiq::Matchers::BeDelayed
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe '#description' do
|
36
|
-
context 'when expected is a delay' do
|
37
|
-
it 'returns description' do
|
38
|
-
expect(delay_subject.description).to eq 'be delayed'
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context 'when expected is a delay with arguments' do
|
43
|
-
it 'returns description' do
|
44
|
-
expect(delay_with_arguments_subject.description).to eq 'be delayed with arguments [Object]'
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context 'when expected is a delay for' do
|
49
|
-
it 'returns description' do
|
50
|
-
expect(delay_for_subject.description).to eq 'be delayed for 3600 seconds'
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
context 'when expected is a delay for with arguments' do
|
55
|
-
it 'returns description' do
|
56
|
-
expect(delay_for_with_arguments_subject.description).to eq 'be delayed for 3600 seconds with arguments [Object]'
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'when expected is a delay until' do
|
61
|
-
it 'returns description' do
|
62
|
-
expect(delay_until_subject.description).to eq "be delayed until #{Time.now + 3600}"
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
context 'when expected is a delay until with arguments' do
|
67
|
-
it 'returns description' do
|
68
|
-
expect(delay_until_with_arguments_subject.description).to eq "be delayed until #{Time.now + 3600} with arguments [Object]"
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
describe '#failure_message' do
|
74
|
-
context 'when expected is a delay' do
|
75
|
-
it 'returns message' do
|
76
|
-
expect(delay_subject.failure_message).to eq 'expected Object.nil? to be delayed'
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
context 'when expected is a delay with arguments' do
|
81
|
-
it 'returns message' do
|
82
|
-
expect(delay_with_arguments_subject.failure_message).to eq 'expected Object.is_a? to be delayed with arguments [Object]'
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
context 'when expected is a delay for' do
|
87
|
-
it 'returns message' do
|
88
|
-
expect(delay_for_subject.failure_message).to eq 'expected Object.nil? to be delayed for 3600 seconds'
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
context 'when expected is a delay for with arguments' do
|
93
|
-
it 'returns message' do
|
94
|
-
expect(delay_for_with_arguments_subject.failure_message).to eq 'expected Object.is_a? to be delayed for 3600 seconds with arguments [Object]'
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
context 'when expected is a delay until' do
|
99
|
-
it 'returns message' do
|
100
|
-
expect(delay_until_subject.failure_message).to eq "expected Object.nil? to be delayed until #{Time.now + 3600}"
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
context 'when expected is a delay until with arguments' do
|
105
|
-
it 'returns message' do
|
106
|
-
expect(delay_until_with_arguments_subject.failure_message).to eq "expected Object.is_a? to be delayed until #{Time.now + 3600} with arguments [Object]"
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
describe '#matches?' do
|
112
|
-
context 'when condition matches' do
|
113
|
-
context 'when expected is a delay' do
|
114
|
-
it 'returns true' do
|
115
|
-
Object.delay.nil?
|
116
|
-
|
117
|
-
expect(delay_subject.matches? Object.method :nil?).to be true
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
context 'when expected is a delay with arguments' do
|
122
|
-
it 'returns true' do
|
123
|
-
Object.delay.is_a? Object
|
124
|
-
|
125
|
-
expect(delay_with_arguments_subject.matches? Object.method :is_a?).to be true
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
context 'when expected is a delay for' do
|
130
|
-
it 'returns true' do
|
131
|
-
Object.delay_for(3600).nil?
|
132
|
-
|
133
|
-
expect(delay_for_subject.matches? Object.method :nil?).to be true
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
context 'when expected is a delay for with arguments' do
|
138
|
-
it 'returns true' do
|
139
|
-
Object.delay_for(3600).is_a? Object
|
140
|
-
|
141
|
-
expect(delay_for_with_arguments_subject.matches? Object.method :is_a?).to be true
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
context 'when expected is a delay until' do
|
146
|
-
it 'returns true' do
|
147
|
-
Object.delay_until(Time.now + 3600).nil?
|
148
|
-
|
149
|
-
expect(delay_until_subject.matches? Object.method :nil?).to be true
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
context 'when expected is a delay until with arguments' do
|
154
|
-
it 'returns true' do
|
155
|
-
Object.delay_until(Time.now + 3600).is_a? Object
|
156
|
-
|
157
|
-
expect(delay_until_with_arguments_subject.matches? Object.method :is_a?).to be true
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
context 'when condition does not match' do
|
163
|
-
context 'when expected is a delay' do
|
164
|
-
it 'returns false' do
|
165
|
-
expect(delay_subject.matches? Object.method :nil?).to be false
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
context 'when expected is a delay with arguments' do
|
170
|
-
it 'returns false' do
|
171
|
-
expect(delay_with_arguments_subject.matches? Object.method :is_a?).to be false
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
context 'when expected is a delay for' do
|
176
|
-
it 'returns false' do
|
177
|
-
expect(delay_for_subject.matches? Object.method :nil?).to be false
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
context 'when expected is a delay for with arguments' do
|
182
|
-
it 'returns false' do
|
183
|
-
expect(delay_for_with_arguments_subject.matches? Object.method :is_a?).to be false
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
context 'when expected is a delay until' do
|
188
|
-
it 'returns false' do
|
189
|
-
expect(delay_until_subject.matches? Object.method :nil?).to be false
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
context 'when expected is a delay until with arguments' do
|
194
|
-
it 'returns false' do
|
195
|
-
expect(delay_until_with_arguments_subject.matches? Object.method :is_a?).to be false
|
196
|
-
end
|
197
|
-
end
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
describe '#failure_message_when_negated' do
|
202
|
-
context 'when expected is a delay' do
|
203
|
-
it 'returns message' do
|
204
|
-
expect(delay_subject.failure_message_when_negated).to eq 'expected Object.nil? to not be delayed'
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
context 'when expected is a delay with arguments' do
|
209
|
-
it 'returns message' do
|
210
|
-
expect(delay_with_arguments_subject.failure_message_when_negated).to eq 'expected Object.is_a? to not be delayed with arguments [Object]'
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
context 'when expected is a delay for' do
|
215
|
-
it 'returns message' do
|
216
|
-
expect(delay_for_subject.failure_message_when_negated).to eq 'expected Object.nil? to not be delayed for 3600 seconds'
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
context 'when expected is a delay for with arguments' do
|
221
|
-
it 'returns message' do
|
222
|
-
expect(delay_for_with_arguments_subject.failure_message_when_negated).to eq 'expected Object.is_a? to not be delayed for 3600 seconds with arguments [Object]'
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
context 'when expected is a delay until' do
|
227
|
-
it 'returns message' do
|
228
|
-
expect(delay_until_subject.failure_message_when_negated).to eq "expected Object.nil? to not be delayed until #{Time.now + 3600}"
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
context 'when expected is a delay until with arguments' do
|
233
|
-
it 'returns message' do
|
234
|
-
expect(delay_until_with_arguments_subject.failure_message_when_negated).to eq "expected Object.is_a? to not be delayed until #{Time.now + 3600} with arguments [Object]"
|
235
|
-
end
|
236
|
-
end
|
237
|
-
end
|
238
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe RSpec::Sidekiq::Matchers::BeExpiredIn do
|
4
|
-
let(:subject) { RSpec::Sidekiq::Matchers::BeExpiredIn.new 1 }
|
5
|
-
let(:worker) { create_worker expires_in: 1 }
|
6
|
-
|
7
|
-
describe '#be_expired_in' do
|
8
|
-
it 'returns instance' do
|
9
|
-
expect(be_expired_in 1).to be_a RSpec::Sidekiq::Matchers::BeExpiredIn
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
describe 'expected usage' do
|
14
|
-
it 'matches' do
|
15
|
-
expect(worker).to be_expired_in 1
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'with negated' do
|
19
|
-
it 'matches' do
|
20
|
-
expect(worker).to_not be_expired_in 2
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe '#failure_message' do
|
26
|
-
it 'returns message' do
|
27
|
-
subject.matches? worker
|
28
|
-
expect(subject.failure_message).to eq "expected to expire in #{worker.sidekiq_options['expires_in']} but expired in #{subject.instance_variable_get(:@expected_argument)}"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe '#matches?' do
|
33
|
-
context 'when expected equals actual' do
|
34
|
-
it 'returns true' do
|
35
|
-
expect(subject.matches? worker).to be true
|
36
|
-
end
|
37
|
-
end
|
38
|
-
context 'when expected is not equal to actual' do
|
39
|
-
it 'returns false' do
|
40
|
-
expect(RSpec::Sidekiq::Matchers::BeExpiredIn.new(2).matches? worker). to be false
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe '#failure_message_when_negated' do
|
46
|
-
it 'returns message' do
|
47
|
-
subject.matches? worker
|
48
|
-
expect(subject.failure_message_when_negated).to eq "expected to not expire in #{subject.instance_variable_get(:@expected_argument)}"
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe '#description' do
|
53
|
-
it 'returns message' do
|
54
|
-
expect(subject.description).to eq "to expire in #{subject.instance_variable_get(:@expected_argument)}"
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,114 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe RSpec::Sidekiq::Matchers::BeProcessedIn do
|
4
|
-
let(:symbol_subject) { RSpec::Sidekiq::Matchers::BeProcessedIn.new :a_queue }
|
5
|
-
let(:symbol_worker) { create_worker queue: :a_queue }
|
6
|
-
let(:string_subject) { RSpec::Sidekiq::Matchers::BeProcessedIn.new 'a_queue' }
|
7
|
-
let(:string_worker) { create_worker queue: 'a_queue' }
|
8
|
-
let(:active_job) { create_active_job :mailers }
|
9
|
-
|
10
|
-
before(:each) do
|
11
|
-
symbol_subject.matches? symbol_worker
|
12
|
-
string_subject.matches? string_worker
|
13
|
-
end
|
14
|
-
|
15
|
-
describe 'expected usage' do
|
16
|
-
it 'matches' do
|
17
|
-
expect(symbol_worker).to be_processed_in :a_queue
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'matches on an ActiveJob' do
|
21
|
-
expect(active_job).to be_processed_in :mailers
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe '#be_processed_in' do
|
26
|
-
it 'returns instance' do
|
27
|
-
expect(be_processed_in :a_queue).to be_a RSpec::Sidekiq::Matchers::BeProcessedIn
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe '#description' do
|
32
|
-
context 'when expected is a symbol' do
|
33
|
-
it 'returns description' do
|
34
|
-
expect(symbol_subject.description).to eq "be processed in the \"a_queue\" queue"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
context 'when expected is a string' do
|
39
|
-
it 'returns description' do
|
40
|
-
expect(string_subject.description).to eq "be processed in the \"a_queue\" queue"
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe '#failure_message' do
|
46
|
-
context 'when expected is a symbol' do
|
47
|
-
it 'returns message' do
|
48
|
-
expect(symbol_subject.failure_message).to eq "expected #{symbol_worker} to be processed in the \"a_queue\" queue but got \"a_queue\""
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
context 'when expected is a string' do
|
53
|
-
it 'returns message' do
|
54
|
-
expect(string_subject.failure_message).to eq "expected #{string_worker} to be processed in the \"a_queue\" queue but got \"a_queue\""
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe '#matches?' do
|
60
|
-
context 'when condition matches' do
|
61
|
-
context 'when expected is a symbol' do
|
62
|
-
it 'returns true' do
|
63
|
-
expect(symbol_subject.matches? symbol_worker).to be true
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context 'when expected is a symbol and actual is string' do
|
68
|
-
it 'returns true' do
|
69
|
-
expect(symbol_subject.matches? string_worker).to be true
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
context 'when expected is a string' do
|
74
|
-
it 'returns true' do
|
75
|
-
expect(string_subject.matches? string_worker).to be true
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
context 'when expected is a string and actual is symbol' do
|
80
|
-
it 'returns true' do
|
81
|
-
expect(string_subject.matches? symbol_worker).to be true
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
context 'when condition does not match' do
|
87
|
-
context 'when expected is a symbol' do
|
88
|
-
it 'returns false' do
|
89
|
-
expect(symbol_subject.matches? create_worker queue: :another_queue).to be false
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
context 'when expected is a string' do
|
94
|
-
it 'returns false' do
|
95
|
-
expect(string_subject.matches? create_worker queue: 'another_queue').to be false
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
describe '#failure_message_when_negated' do
|
102
|
-
context 'when expected is a symbol' do
|
103
|
-
it 'returns message' do
|
104
|
-
expect(symbol_subject.failure_message_when_negated).to eq "expected #{symbol_worker} to not be processed in the \"a_queue\" queue"
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
context 'when expected is a string' do
|
109
|
-
it 'returns message' do
|
110
|
-
expect(string_subject.failure_message_when_negated).to eq "expected #{string_worker} to not be processed in the \"a_queue\" queue"
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
@@ -1,129 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe RSpec::Sidekiq::Matchers::BeRetryable do
|
4
|
-
let(:specific_subject) { RSpec::Sidekiq::Matchers::BeRetryable.new 2 }
|
5
|
-
let(:specific_worker) { create_worker retry: 2 }
|
6
|
-
let(:default_subject) { RSpec::Sidekiq::Matchers::BeRetryable.new true }
|
7
|
-
let(:default_worker) { create_worker retry: true }
|
8
|
-
let(:negative_subject) { RSpec::Sidekiq::Matchers::BeRetryable.new false }
|
9
|
-
let(:negative_worker) { create_worker retry: false }
|
10
|
-
before(:each) do
|
11
|
-
specific_subject.matches? specific_worker
|
12
|
-
default_subject.matches? default_worker
|
13
|
-
negative_subject.matches? negative_worker
|
14
|
-
end
|
15
|
-
|
16
|
-
describe 'expected usage' do
|
17
|
-
it 'matches' do
|
18
|
-
expect(default_worker).to be_retryable true
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe '#be_retryable' do
|
23
|
-
it 'returns instance' do
|
24
|
-
expect(be_retryable true).to be_a RSpec::Sidekiq::Matchers::BeRetryable
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe '#description' do
|
29
|
-
context 'when expected is a number' do
|
30
|
-
it 'returns description' do
|
31
|
-
expect(specific_subject.description).to eq 'retry 2 times'
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'when expected is true' do
|
36
|
-
it 'returns description' do
|
37
|
-
expect(default_subject.description).to eq 'retry the default number of times'
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context 'when expected is false' do
|
42
|
-
it 'returns description' do
|
43
|
-
expect(negative_subject.description).to eq 'not retry'
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe '#failure_message' do
|
49
|
-
context 'when expected is a number' do
|
50
|
-
it 'returns message' do
|
51
|
-
expect(specific_subject.failure_message).to eq "expected #{specific_worker} to retry 2 times but got 2"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context 'when expected is true' do
|
56
|
-
it 'returns message' do
|
57
|
-
expect(default_subject.failure_message).to eq "expected #{default_worker} to retry the default number of times but got true"
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context 'when expected is false' do
|
62
|
-
it 'returns message' do
|
63
|
-
expect(negative_subject.failure_message).to eq "expected #{negative_worker} to not retry but got false"
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe '#matches?' do
|
69
|
-
context 'when condition matches' do
|
70
|
-
context 'when expected is a number' do
|
71
|
-
it 'returns true' do
|
72
|
-
expect(specific_subject.matches? specific_worker).to be true
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
context 'when expected is true' do
|
77
|
-
it 'returns true' do
|
78
|
-
expect(default_subject.matches? default_worker).to be true
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
context 'when expected is false' do
|
83
|
-
it 'returns true' do
|
84
|
-
expect(negative_subject.matches? negative_worker).to be true
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context 'when condition does not match' do
|
90
|
-
context 'when expected is a number' do
|
91
|
-
it 'returns false' do
|
92
|
-
expect(specific_subject.matches? default_worker).to be false
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
context 'when expected is true' do
|
97
|
-
it 'returns false' do
|
98
|
-
expect(default_subject.matches? negative_worker).to be false
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
context 'when expected is false' do
|
103
|
-
it 'returns false' do
|
104
|
-
expect(negative_subject.matches? specific_worker).to be false
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
describe '#failure_message_when_negated' do
|
111
|
-
context 'when expected is a number' do
|
112
|
-
it 'returns message' do
|
113
|
-
expect(specific_subject.failure_message_when_negated).to eq "expected #{specific_worker} to not retry 2 times"
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
context 'when expected is true' do
|
118
|
-
it 'returns message' do
|
119
|
-
expect(default_subject.failure_message_when_negated).to eq "expected #{default_worker} to not retry the default number of times"
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
context 'when expected is false' do
|
124
|
-
it 'returns message' do
|
125
|
-
expect(negative_subject.failure_message_when_negated).to eq "expected #{negative_worker} to retry"
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|