rspec-activejob 0.4.2 → 0.5.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/.rubocop.yml +0 -2
- data/.travis.yml +10 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +16 -1
- data/README.md +5 -3
- data/lib/rspec/active_job.rb +2 -0
- data/lib/rspec/active_job/enqueue_a.rb +53 -15
- data/lib/rspec/active_job/version.rb +1 -1
- data/rspec-activejob.gemspec +1 -0
- data/spec/rspec/active_job/enqueue_a_spec.rb +27 -0
- metadata +17 -3
- data/.rubocop_todo.yml +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67fc94e6b07a0f9566fa7fc4687563affa38629a
|
4
|
+
data.tar.gz: 5650bb54c6add28bd7b7ae830e3fec9d2a7ae925
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32f2e4850d9ce2f45f6639d1a656a4045f91d1158a1a822b3686ed588e4219c491489fc27900bd0dff99e02dfa0dd83bd6299ff18757d7172af0a3c14a81d03b
|
7
|
+
data.tar.gz: 50c75b3434f3033d92129f09e99d2b09346c45444f33348f97a816a00303ee8f6a2b3fa430e86523fd8ad4fea0acc73b811fd871e1fa5e7c3204350968b79e3f
|
data/.rubocop.yml
CHANGED
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rspec-activejob (0.
|
4
|
+
rspec-activejob (0.5.0)
|
5
5
|
activejob (>= 4.2)
|
6
6
|
rspec-mocks
|
7
7
|
|
@@ -17,6 +17,9 @@ GEM
|
|
17
17
|
minitest (~> 5.1)
|
18
18
|
thread_safe (~> 0.3, >= 0.3.4)
|
19
19
|
tzinfo (~> 1.1)
|
20
|
+
ast (2.1.0)
|
21
|
+
astrolabe (1.3.1)
|
22
|
+
parser (~> 2.2)
|
20
23
|
coderay (1.1.0)
|
21
24
|
diff-lcs (1.2.5)
|
22
25
|
globalid (0.3.3)
|
@@ -25,10 +28,14 @@ GEM
|
|
25
28
|
json (1.8.2)
|
26
29
|
method_source (0.8.2)
|
27
30
|
minitest (5.5.1)
|
31
|
+
parser (2.2.2.6)
|
32
|
+
ast (>= 1.1, < 3.0)
|
33
|
+
powerpack (0.1.1)
|
28
34
|
pry (0.10.1)
|
29
35
|
coderay (~> 1.1.0)
|
30
36
|
method_source (~> 0.8.1)
|
31
37
|
slop (~> 3.4)
|
38
|
+
rainbow (2.0.0)
|
32
39
|
rspec (3.2.0)
|
33
40
|
rspec-core (~> 3.2.0)
|
34
41
|
rspec-expectations (~> 3.2.0)
|
@@ -45,6 +52,13 @@ GEM
|
|
45
52
|
diff-lcs (>= 1.2.0, < 2.0)
|
46
53
|
rspec-support (~> 3.2.0)
|
47
54
|
rspec-support (3.2.2)
|
55
|
+
rubocop (0.34.1)
|
56
|
+
astrolabe (~> 1.3)
|
57
|
+
parser (>= 2.2.2.5, < 3.0)
|
58
|
+
powerpack (~> 0.1)
|
59
|
+
rainbow (>= 1.99.1, < 3.0)
|
60
|
+
ruby-progressbar (~> 1.4)
|
61
|
+
ruby-progressbar (1.7.5)
|
48
62
|
slop (3.6.0)
|
49
63
|
thread_safe (0.3.5)
|
50
64
|
tzinfo (1.2.2)
|
@@ -59,6 +73,7 @@ DEPENDENCIES
|
|
59
73
|
rspec
|
60
74
|
rspec-activejob!
|
61
75
|
rspec-its
|
76
|
+
rubocop
|
62
77
|
|
63
78
|
BUNDLED WITH
|
64
79
|
1.10.6
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+

|
2
|
+
# Installation
|
2
3
|
|
3
4
|
```gem install rspec-activejob ```
|
4
5
|
|
@@ -39,7 +40,7 @@ RSpec.describe MyController do
|
|
39
40
|
subject(:make_request) { described_class.make_request(params) }
|
40
41
|
|
41
42
|
specify { expect { make_request }.to enqueue_a(RequestMaker).with(global_id(user)) }
|
42
|
-
|
43
|
+
|
43
44
|
# or
|
44
45
|
make_request
|
45
46
|
expect(RequestMaker).to have_been_enqueued.with(global_id(user))
|
@@ -48,7 +49,7 @@ end
|
|
48
49
|
|
49
50
|
rspec-activejob expects the current queue adapter to expose an array of `enqueued_jobs`, like the included
|
50
51
|
test adapter. The test adapter included in ActiveJob 4.2.0 does not fully serialize its arguments, so you
|
51
|
-
will not need to use the GlobalID matcher unless you're using ActiveJob 4.2.1. See rails/rails#18266 for
|
52
|
+
will not need to use the GlobalID matcher unless you're using ActiveJob 4.2.1. See rails/rails#18266 for
|
52
53
|
the improved test adapter.
|
53
54
|
|
54
55
|
This gem defines four matchers:
|
@@ -56,6 +57,7 @@ This gem defines four matchers:
|
|
56
57
|
* `enqueue_a`: for a block or proc, expects that to enqueue an job to the ActiveJob test adapter. Optionally
|
57
58
|
takes the job class as its argument, and can be modified with a `.with(*args)` call to expect specific arguments.
|
58
59
|
This will use the same argument list matcher as rspec-mocks' `receive(:message).with(*args)` matcher.
|
60
|
+
If your job uses `set(wait_until: time)`, you can use `.to_run_at(time)` chain after `enqueue_a` call as well.
|
59
61
|
|
60
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.
|
61
63
|
|
data/lib/rspec/active_job.rb
CHANGED
@@ -8,9 +8,11 @@ module RSpec
|
|
8
8
|
Matchers::EnqueueA.new(job_class)
|
9
9
|
end
|
10
10
|
|
11
|
+
# rubocop:disable Style/PredicateName
|
11
12
|
def have_been_enqueued
|
12
13
|
Matchers::EnqueueA.new
|
13
14
|
end
|
15
|
+
# rubocop:enable Style/PredicateName
|
14
16
|
|
15
17
|
def global_id(expected)
|
16
18
|
Matchers::GlobalID.new(expected)
|
@@ -14,11 +14,11 @@ module RSpec
|
|
14
14
|
if actual.is_a?(Proc)
|
15
15
|
@before_jobs = enqueued_jobs.dup
|
16
16
|
actual.call
|
17
|
-
|
17
|
+
all_checks_pass?
|
18
18
|
else
|
19
19
|
@job_class = actual
|
20
20
|
@before_jobs = []
|
21
|
-
|
21
|
+
all_checks_pass?
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -27,19 +27,16 @@ module RSpec
|
|
27
27
|
self
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
unless enqueued_correct_class?
|
36
|
-
return "expected to enqueue a #{job_class}, " \
|
37
|
-
"enqueued a #{enqueued_jobs.last[:job]}"
|
38
|
-
end
|
30
|
+
def to_run_at(time)
|
31
|
+
@run_time = time.to_f
|
32
|
+
self
|
33
|
+
end
|
39
34
|
|
40
|
-
|
41
|
-
|
42
|
-
|
35
|
+
def failure_message
|
36
|
+
enqueued_nothing_message ||
|
37
|
+
enqueued_wrong_class_message ||
|
38
|
+
enqueued_at_wrong_time_message ||
|
39
|
+
wrong_arguments_message
|
43
40
|
end
|
44
41
|
|
45
42
|
def failure_message_when_negated
|
@@ -69,7 +66,15 @@ module RSpec
|
|
69
66
|
|
70
67
|
private
|
71
68
|
|
72
|
-
attr_reader :before_count, :after_count, :job_class, :argument_list_matcher
|
69
|
+
attr_reader :before_count, :after_count, :job_class, :argument_list_matcher,
|
70
|
+
:run_time
|
71
|
+
|
72
|
+
def all_checks_pass?
|
73
|
+
enqueued_something? &&
|
74
|
+
enqueued_correct_class? &&
|
75
|
+
with_correct_args? &&
|
76
|
+
at_correct_time?
|
77
|
+
end
|
73
78
|
|
74
79
|
def enqueued_something?
|
75
80
|
new_jobs.any?
|
@@ -85,6 +90,29 @@ module RSpec
|
|
85
90
|
new_jobs_with_correct_class_and_args.any?
|
86
91
|
end
|
87
92
|
|
93
|
+
def enqueued_nothing_message
|
94
|
+
return if enqueued_something?
|
95
|
+
"expected to enqueue a #{job_class || 'job'}, enqueued nothing"
|
96
|
+
end
|
97
|
+
|
98
|
+
def enqueued_wrong_class_message
|
99
|
+
return if enqueued_correct_class?
|
100
|
+
"expected to enqueue a #{job_class}, enqueued a " \
|
101
|
+
"#{enqueued_jobs.last[:job]}"
|
102
|
+
end
|
103
|
+
|
104
|
+
def enqueued_at_wrong_time_message
|
105
|
+
return if at_correct_time?
|
106
|
+
"expected to run job at #{Time.at(run_time).utc}, but enqueued to " \
|
107
|
+
"run at #{format_enqueued_times}"
|
108
|
+
end
|
109
|
+
|
110
|
+
def wrong_arguments_message
|
111
|
+
"expected to enqueue a #{job_class} with " \
|
112
|
+
"#{argument_list_matcher.expected_args}, but enqueued with " \
|
113
|
+
"#{new_jobs_with_correct_class.first[:args]}"
|
114
|
+
end
|
115
|
+
|
88
116
|
def new_jobs
|
89
117
|
enqueued_jobs - @before_jobs
|
90
118
|
end
|
@@ -101,6 +129,16 @@ module RSpec
|
|
101
129
|
def enqueued_jobs
|
102
130
|
::ActiveJob::Base.queue_adapter.enqueued_jobs
|
103
131
|
end
|
132
|
+
|
133
|
+
def at_correct_time?
|
134
|
+
return true unless run_time
|
135
|
+
|
136
|
+
!new_jobs_with_correct_class.find { |job| job[:at] == run_time }.nil?
|
137
|
+
end
|
138
|
+
|
139
|
+
def format_enqueued_times
|
140
|
+
new_jobs_with_correct_class.map { |job| Time.at(job[:at]).utc.to_s }.join(', ')
|
141
|
+
end
|
104
142
|
end
|
105
143
|
end
|
106
144
|
end
|
data/rspec-activejob.gemspec
CHANGED
@@ -148,4 +148,31 @@ RSpec.describe RSpec::ActiveJob::Matchers::EnqueueA do
|
|
148
148
|
end
|
149
149
|
end
|
150
150
|
end
|
151
|
+
|
152
|
+
context "with run time expectations" do
|
153
|
+
let(:instance) { described_class.new }
|
154
|
+
let(:run_time) { Time.parse('2015-09-10 00:00:00 UTC').to_f }
|
155
|
+
subject(:matches?) { instance.to_run_at(run_time).matches?(AJob) }
|
156
|
+
|
157
|
+
let(:enqueued_jobs) do
|
158
|
+
[{ job: AJob, args: [], at: time }]
|
159
|
+
end
|
160
|
+
|
161
|
+
context "correct time" do
|
162
|
+
let(:time) { run_time }
|
163
|
+
it { is_expected.to be(true) }
|
164
|
+
end
|
165
|
+
|
166
|
+
context "wrong time" do
|
167
|
+
let(:time) { run_time + 1 }
|
168
|
+
it { is_expected.to be(false) }
|
169
|
+
|
170
|
+
specify do
|
171
|
+
matches?
|
172
|
+
expect(instance.failure_message).
|
173
|
+
to eq("expected to run job at 2015-09-10 00:00:00 UTC, " \
|
174
|
+
"but enqueued to run at 2015-09-10 00:00:01 UTC")
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
151
178
|
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.5.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-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description: |2
|
84
98
|
RSpec matchers for ActiveJob:
|
85
99
|
* expect { method }.to enqueue_a(MyJob).with(global_id(some_model),
|
@@ -92,7 +106,7 @@ extra_rdoc_files: []
|
|
92
106
|
files:
|
93
107
|
- ".gitignore"
|
94
108
|
- ".rubocop.yml"
|
95
|
-
- ".
|
109
|
+
- ".travis.yml"
|
96
110
|
- CHANGELOG.md
|
97
111
|
- Gemfile
|
98
112
|
- Gemfile.lock
|
data/.rubocop_todo.yml
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
-
# on 2015-05-05 20:58:29 +0100 using RuboCop version 0.27.1.
|
3
|
-
# The point is for the user to remove these configuration records
|
4
|
-
# one by one as the offenses are removed from the code base.
|
5
|
-
# Note that changes in the inspected code, or installation of new
|
6
|
-
# versions of RuboCop, may require this file to be generated again.
|
7
|
-
|
8
|
-
# Offense count: 1
|
9
|
-
Metrics/AbcSize:
|
10
|
-
Max: 16
|
11
|
-
|
12
|
-
# Offense count: 1
|
13
|
-
Metrics/CyclomaticComplexity:
|
14
|
-
Max: 8
|
15
|
-
|
16
|
-
# Offense count: 1
|
17
|
-
Metrics/PerceivedComplexity:
|
18
|
-
Max: 9
|
19
|
-
|
20
|
-
# Offense count: 1
|
21
|
-
# Configuration parameters: NamePrefix, NamePrefixBlacklist.
|
22
|
-
Style/PredicateName:
|
23
|
-
Enabled: false
|