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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 67fc94e6b07a0f9566fa7fc4687563affa38629a
4
- data.tar.gz: 5650bb54c6add28bd7b7ae830e3fec9d2a7ae925
3
+ metadata.gz: 9d09b4563475ff8556cae29a398448b78a3da4c7
4
+ data.tar.gz: 678218734197d92b674770b9a9fd91988e58c865
5
5
  SHA512:
6
- metadata.gz: 32f2e4850d9ce2f45f6639d1a656a4045f91d1158a1a822b3686ed588e4219c491489fc27900bd0dff99e02dfa0dd83bd6299ff18757d7172af0a3c14a81d03b
7
- data.tar.gz: 50c75b3434f3033d92129f09e99d2b09346c45444f33348f97a816a00303ee8f6a2b3fa430e86523fd8ad4fea0acc73b811fd871e1fa5e7c3204350968b79e3f
6
+ metadata.gz: 2f14e3e32d634747c09cc672f0eae2dfcf78c6fcd0f5af6e6fe39ff6426f62ad41b0a833c607042e9b97c8e957b672c56bf5c03c8c61ec18e8d55004d6b835d2
7
+ data.tar.gz: d0240dc8b98a58f4cfbdf13da957c5b37d51052ba27112fd67d55f6b618e55490715f7664da4a304e8b32007b1ccd3038fcce4649e7c3b520bb117394908a784
@@ -1,3 +1,7 @@
1
+ ## 0.6.0 - October 15, 2015
2
+
3
+ - Add `once` and `times(n)` modifiers - patch by [@antstorm](https://github.com/antstorm)
4
+
1
5
  ## 0.5.0 - September 16, 2015
2
6
 
3
7
  - Add `to_run_at` modifier - patch by [@vidmantas](https://github.com/vidmantas)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-activejob (0.5.0)
4
+ rspec-activejob (0.6.0)
5
5
  activejob (>= 4.2)
6
6
  rspec-mocks
7
7
 
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. Can be modified with a `.with(*args)` call to expect specific arguments. This will use the same argument list matcher as rspec-mocks' `receive(:message).with(*args)` matcher.
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
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module ActiveJob
3
- VERSION = '0.5.0'.freeze
3
+ VERSION = '0.6.0'.freeze
4
4
  end
5
5
  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
- it { is_expected.to be(true) }
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.5.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-09-16 00:00:00.000000000 Z
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