rspec-activejob 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +3 -1
- data/lib/rspec/active_job/enqueue_a.rb +31 -2
- data/lib/rspec/active_job/version.rb +1 -1
- data/spec/rspec/active_job/enqueue_a_spec.rb +64 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d09b4563475ff8556cae29a398448b78a3da4c7
|
4
|
+
data.tar.gz: 678218734197d92b674770b9a9fd91988e58c865
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f14e3e32d634747c09cc672f0eae2dfcf78c6fcd0f5af6e6fe39ff6426f62ad41b0a833c607042e9b97c8e957b672c56bf5c03c8c61ec18e8d55004d6b835d2
|
7
|
+
data.tar.gz: d0240dc8b98a58f4cfbdf13da957c5b37d51052ba27112fd67d55f6b618e55490715f7664da4a304e8b32007b1ccd3038fcce4649e7c3b520bb117394908a784
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -58,8 +58,10 @@ This gem defines four matchers:
|
|
58
58
|
takes the job class as its argument, and can be modified with a `.with(*args)` call to expect specific arguments.
|
59
59
|
This will use the same argument list matcher as rspec-mocks' `receive(:message).with(*args)` matcher.
|
60
60
|
If your job uses `set(wait_until: time)`, you can use `.to_run_at(time)` chain after `enqueue_a` call as well.
|
61
|
+
In order to check for the right number of enqueued jobs use a `.once` or `.times(n)` modifiers.
|
61
62
|
|
62
|
-
* `have_been_enqueued`: expects to have enqueued an job in the ActiveJob test adapter.
|
63
|
+
* `have_been_enqueued`: expects to have enqueued an job in the ActiveJob test adapter. Optionally accepts all the
|
64
|
+
same modifiers as `enqueue_a`.
|
63
65
|
|
64
66
|
* `global_id(model_or_class)`: an argument matcher, matching ActiveJob-serialized versions of model classes or
|
65
67
|
specific models (or any other class which implements `to_global_id`). If you pass a model class, it will match
|
@@ -32,10 +32,21 @@ module RSpec
|
|
32
32
|
self
|
33
33
|
end
|
34
34
|
|
35
|
+
def once
|
36
|
+
@number_of_times = 1
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
def times(n)
|
41
|
+
@number_of_times = n
|
42
|
+
self
|
43
|
+
end
|
44
|
+
|
35
45
|
def failure_message
|
36
46
|
enqueued_nothing_message ||
|
37
47
|
enqueued_wrong_class_message ||
|
38
48
|
enqueued_at_wrong_time_message ||
|
49
|
+
enqueued_wrong_number_of_times_message ||
|
39
50
|
wrong_arguments_message
|
40
51
|
end
|
41
52
|
|
@@ -67,13 +78,14 @@ module RSpec
|
|
67
78
|
private
|
68
79
|
|
69
80
|
attr_reader :before_count, :after_count, :job_class, :argument_list_matcher,
|
70
|
-
:run_time
|
81
|
+
:run_time, :number_of_times
|
71
82
|
|
72
83
|
def all_checks_pass?
|
73
84
|
enqueued_something? &&
|
74
85
|
enqueued_correct_class? &&
|
75
86
|
with_correct_args? &&
|
76
|
-
at_correct_time?
|
87
|
+
at_correct_time? &&
|
88
|
+
enqueued_correct_number_of_times?
|
77
89
|
end
|
78
90
|
|
79
91
|
def enqueued_something?
|
@@ -113,6 +125,17 @@ module RSpec
|
|
113
125
|
"#{new_jobs_with_correct_class.first[:args]}"
|
114
126
|
end
|
115
127
|
|
128
|
+
def enqueued_wrong_number_of_times_message
|
129
|
+
return if enqueued_correct_number_of_times?
|
130
|
+
"expected to enqueue a #{job_class} " \
|
131
|
+
"#{times_count(number_of_times)}, but enqueued " \
|
132
|
+
"#{times_count(new_jobs.count)}"
|
133
|
+
end
|
134
|
+
|
135
|
+
def times_count(n)
|
136
|
+
n == 1 ? 'once' : "#{n} times"
|
137
|
+
end
|
138
|
+
|
116
139
|
def new_jobs
|
117
140
|
enqueued_jobs - @before_jobs
|
118
141
|
end
|
@@ -139,6 +162,12 @@ module RSpec
|
|
139
162
|
def format_enqueued_times
|
140
163
|
new_jobs_with_correct_class.map { |job| Time.at(job[:at]).utc.to_s }.join(', ')
|
141
164
|
end
|
165
|
+
|
166
|
+
def enqueued_correct_number_of_times?
|
167
|
+
return true unless number_of_times
|
168
|
+
|
169
|
+
new_jobs.count == number_of_times
|
170
|
+
end
|
142
171
|
end
|
143
172
|
end
|
144
173
|
end
|
@@ -124,7 +124,16 @@ RSpec.describe RSpec::ActiveJob::Matchers::EnqueueA do
|
|
124
124
|
|
125
125
|
context "when it enqueues two jobs" do
|
126
126
|
let(:enqueued_jobs) { [{ job: AJob, args: [] }, { job: BJob, args: [] }] }
|
127
|
-
|
127
|
+
|
128
|
+
context "matches first job" do
|
129
|
+
let(:job_class) { AJob }
|
130
|
+
it { is_expected.to be(true) }
|
131
|
+
end
|
132
|
+
|
133
|
+
context "matches second job" do
|
134
|
+
let(:job_class) { BJob }
|
135
|
+
it { is_expected.to be(true) }
|
136
|
+
end
|
128
137
|
end
|
129
138
|
|
130
139
|
context "with argument expectations" do
|
@@ -175,4 +184,58 @@ RSpec.describe RSpec::ActiveJob::Matchers::EnqueueA do
|
|
175
184
|
end
|
176
185
|
end
|
177
186
|
end
|
187
|
+
|
188
|
+
context "with number of times expectations" do
|
189
|
+
let(:instance) { described_class.new }
|
190
|
+
|
191
|
+
context "once" do
|
192
|
+
subject(:matches?) { instance.once.matches?(AJob) }
|
193
|
+
|
194
|
+
context "correct number of times" do
|
195
|
+
let(:enqueued_jobs) { [{ job: AJob, args: [] }] }
|
196
|
+
|
197
|
+
it { is_expected.to be(true) }
|
198
|
+
end
|
199
|
+
|
200
|
+
context "wrong number of times" do
|
201
|
+
let(:enqueued_jobs) do
|
202
|
+
[{ job: AJob, args: [] }, { job: AJob, args: [] }]
|
203
|
+
end
|
204
|
+
|
205
|
+
it { is_expected.to be(false) }
|
206
|
+
|
207
|
+
specify do
|
208
|
+
matches?
|
209
|
+
expect(instance.failure_message).
|
210
|
+
to eq("expected to enqueue a AJob once, but enqueued 2 times")
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
context "mutiple times" do
|
216
|
+
subject(:matches?) { instance.times(2).matches?(AJob) }
|
217
|
+
|
218
|
+
context "correct number of times" do
|
219
|
+
let(:enqueued_jobs) do
|
220
|
+
[{ job: AJob, args: [] }, { job: AJob, args: [] }]
|
221
|
+
end
|
222
|
+
|
223
|
+
it { is_expected.to be(true) }
|
224
|
+
end
|
225
|
+
|
226
|
+
context "wrong number of times" do
|
227
|
+
let(:enqueued_jobs) do
|
228
|
+
[{ job: AJob, args: [] }]
|
229
|
+
end
|
230
|
+
|
231
|
+
it { is_expected.to be(false) }
|
232
|
+
|
233
|
+
specify do
|
234
|
+
matches?
|
235
|
+
expect(instance.failure_message).
|
236
|
+
to eq("expected to enqueue a AJob 2 times, but enqueued once")
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
178
241
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-activejob
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Isaac Seymour
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|
@@ -141,9 +141,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
141
|
version: '0'
|
142
142
|
requirements: []
|
143
143
|
rubyforge_project:
|
144
|
-
rubygems_version: 2.4.1
|
144
|
+
rubygems_version: 2.4.5.1
|
145
145
|
signing_key:
|
146
146
|
specification_version: 4
|
147
147
|
summary: RSpec matchers to test ActiveJob
|
148
148
|
test_files: []
|
149
|
-
has_rdoc: false
|