rspec-activejob 0.3.0 → 0.4.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 +5 -1
- data/Gemfile.lock +1 -1
- data/lib/rspec/active_job.rb +4 -0
- data/lib/rspec/active_job/enqueue_a.rb +12 -6
- data/lib/rspec/active_job/version.rb +1 -1
- data/spec/rspec/active_job/enqueue_a_spec.rb +91 -34
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 431377e4319168b42fb4104e7dc0c28a998f5133
|
4
|
+
data.tar.gz: 8034829d7058af0d12e4880bf524e86f973a3dcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8adb28bccf0d2cb6931743e167a7e97ad3122a19ec108b056fb87bb5254375e8553cc8cc9c6ef96f8839f6dacd774ab00abf8ffda381c4a8777239656702199
|
7
|
+
data.tar.gz: a725449f9766d47161b8831a8c8153da92c9ef58b8055b3b9f70f24c371154ec63960070e58d706b7db9620b7b3c1d36476cefc45293e5f2411df51aaab560a4
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/lib/rspec/active_job.rb
CHANGED
@@ -8,15 +8,21 @@ module RSpec
|
|
8
8
|
@job_class = job_class
|
9
9
|
end
|
10
10
|
|
11
|
-
def matches?(
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
def matches?(actual)
|
12
|
+
raise "must use a block with enqueue_a" if !actual.is_a?(Proc) && @job_class
|
13
|
+
|
14
|
+
if actual.is_a?(Proc)
|
15
|
+
@before_jobs = enqueued_jobs.dup
|
16
|
+
actual.call
|
17
|
+
enqueued_something? && enqueued_correct_class? && with_correct_args?
|
18
|
+
else
|
19
|
+
@job_class = actual
|
20
|
+
@before_jobs = []
|
21
|
+
enqueued_something? && enqueued_correct_class? && with_correct_args?
|
22
|
+
end
|
15
23
|
end
|
16
24
|
|
17
25
|
def with(*args)
|
18
|
-
raise "Must specify the job class when specifying arguments" unless job_class
|
19
|
-
|
20
26
|
@argument_list_matcher = RSpec::Mocks::ArgumentListMatcher.new(*args)
|
21
27
|
self
|
22
28
|
end
|
@@ -11,62 +11,119 @@ RSpec.describe RSpec::ActiveJob::Matchers::EnqueueA do
|
|
11
11
|
|
12
12
|
let(:job_class) { nil }
|
13
13
|
let(:instance) { described_class.new(job_class) }
|
14
|
-
subject(:matches?) { instance.matches?(proc) }
|
15
|
-
|
16
|
-
context "when nothing gets enqueued" do
|
17
|
-
let(:proc) { -> {} }
|
18
|
-
it { is_expected.to be(false) }
|
19
|
-
specify do
|
20
|
-
matches?
|
21
|
-
expect(instance.failure_message).
|
22
|
-
to eq("expected to enqueue a job, enqueued nothing")
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context "when something gets enqueued" do
|
27
|
-
let(:proc) { -> { enqueued_jobs << { job: AJob, args: [] } } }
|
28
14
|
|
29
|
-
|
30
|
-
|
31
|
-
context "when it enqueues the wrong job" do
|
32
|
-
let(:job_class) { BJob }
|
15
|
+
context "with a block" do
|
16
|
+
subject(:matches?) { instance.matches?(proc) }
|
33
17
|
|
18
|
+
context "when nothing gets enqueued" do
|
19
|
+
let(:proc) { -> {} }
|
34
20
|
it { is_expected.to be(false) }
|
35
21
|
specify do
|
36
22
|
matches?
|
37
23
|
expect(instance.failure_message).
|
38
|
-
to eq("expected to enqueue a
|
24
|
+
to eq("expected to enqueue a job, enqueued nothing")
|
39
25
|
end
|
40
26
|
end
|
41
27
|
|
42
|
-
context "when
|
28
|
+
context "when something gets enqueued" do
|
29
|
+
let(:proc) { -> { enqueued_jobs << { job: AJob, args: [] } } }
|
30
|
+
|
31
|
+
it { is_expected.to be(true) }
|
32
|
+
|
33
|
+
context "when it enqueues the wrong job" do
|
34
|
+
let(:job_class) { BJob }
|
35
|
+
|
36
|
+
it { is_expected.to be(false) }
|
37
|
+
specify do
|
38
|
+
matches?
|
39
|
+
expect(instance.failure_message).
|
40
|
+
to eq("expected to enqueue a BJob, enqueued a AJob")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "when it enqueues two jobs" do
|
45
|
+
let(:proc) do
|
46
|
+
-> { enqueued_jobs << { job: AJob, args: [] } << { job: BJob, args: [] } }
|
47
|
+
end
|
48
|
+
|
49
|
+
it { is_expected.to be(true) }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "with argument expectations" do
|
54
|
+
let(:job_class) { AJob }
|
55
|
+
let(:instance) { described_class.new(job_class).with(*arguments) }
|
56
|
+
let(:arguments) { [instance_of(BJob), hash_including(thing: 1)] }
|
57
|
+
|
43
58
|
let(:proc) do
|
44
|
-
-> { enqueued_jobs << { job: AJob, args: [
|
59
|
+
-> { enqueued_jobs << { job: AJob, args: [BJob.new, { thing: 1, 'thing' => 2 }] } }
|
45
60
|
end
|
46
61
|
|
47
62
|
it { is_expected.to be(true) }
|
48
|
-
end
|
49
|
-
end
|
50
63
|
|
51
|
-
|
52
|
-
|
53
|
-
let(:instance) { described_class.new(job_class).with(*arguments) }
|
54
|
-
let(:arguments) { [instance_of(BJob), hash_including(thing: 1)] }
|
64
|
+
context "with mismatching arguments" do
|
65
|
+
let(:proc) { -> { enqueued_jobs << { job: AJob, args: [] } } }
|
55
66
|
|
56
|
-
|
57
|
-
|
67
|
+
it { is_expected.to be(false) }
|
68
|
+
specify do
|
69
|
+
matches?
|
70
|
+
expect(instance.failure_message).
|
71
|
+
to eq("expected to enqueue a AJob with #{arguments}, but enqueued with []")
|
72
|
+
end
|
73
|
+
end
|
58
74
|
end
|
75
|
+
end
|
59
76
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
let(:proc) { -> { enqueued_jobs << { job: AJob, args: [] } } }
|
77
|
+
context "with job class" do
|
78
|
+
let(:instance) { described_class.new }
|
79
|
+
subject(:matches?) { instance.matches?(job_class) }
|
64
80
|
|
81
|
+
context "when nothing has been enqueued" do
|
65
82
|
it { is_expected.to be(false) }
|
66
83
|
specify do
|
67
84
|
matches?
|
68
85
|
expect(instance.failure_message).
|
69
|
-
to eq("expected to enqueue a
|
86
|
+
to eq("expected to enqueue a job, enqueued nothing")
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "when something gets enqueued" do
|
91
|
+
let(:enqueued_jobs) { [{ job: AJob, args: [] }] }
|
92
|
+
|
93
|
+
it { is_expected.to be(true) }
|
94
|
+
|
95
|
+
context "when it enqueues the wrong job" do
|
96
|
+
let(:job_class) { BJob }
|
97
|
+
|
98
|
+
it { is_expected.to be(false) }
|
99
|
+
specify do
|
100
|
+
matches?
|
101
|
+
expect(instance.failure_message).
|
102
|
+
to eq("expected to enqueue a BJob, enqueued a AJob")
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context "when it enqueues two jobs" do
|
107
|
+
let(:enqueued_jobs) { [{ job: AJob, args: [] }, { job: BJob, args: [] }] }
|
108
|
+
it { is_expected.to be(true) }
|
109
|
+
end
|
110
|
+
|
111
|
+
context "with argument expectations" do
|
112
|
+
let(:job_class) { AJob }
|
113
|
+
let(:instance) { described_class.new.with(*arguments) }
|
114
|
+
let(:arguments) { [instance_of(BJob), hash_including(thing: 1)] }
|
115
|
+
let(:enqueued_jobs) { [{ job: AJob, args: [BJob.new, { thing: 1, 'thing' => 2}] }] }
|
116
|
+
it { is_expected.to be(true) }
|
117
|
+
|
118
|
+
context "with mismatching arguments"do
|
119
|
+
let(:enqueued_jobs) { [{ job: AJob, args: [] }] }
|
120
|
+
it { is_expected.to be(false) }
|
121
|
+
specify do
|
122
|
+
matches?
|
123
|
+
expect(instance.failure_message).
|
124
|
+
to eq("expected to enqueue a AJob with #{arguments}, but enqueued with []")
|
125
|
+
end
|
126
|
+
end
|
70
127
|
end
|
71
128
|
end
|
72
129
|
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.4.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-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|