rspec-activejob 0.3.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ed4f20a431ed47d9bac346276c28f5c66143cf5
4
- data.tar.gz: 2ac30436e51224415b3a083acbfb008eeaf7a1c8
3
+ metadata.gz: 431377e4319168b42fb4104e7dc0c28a998f5133
4
+ data.tar.gz: 8034829d7058af0d12e4880bf524e86f973a3dcb
5
5
  SHA512:
6
- metadata.gz: 41552e56407232b5f260b1b8459725916a86b3b5411938bf87a23074f84f62bf58c011195952fac04dad56519bbe3970c06d98bd7c01c7ad9a8ad92135b870f5
7
- data.tar.gz: f057e07d01d62994ec8d586f56af964075bafe140c95c3843a29913eb79d46b01f37f2cfd90b984641f133a106042625cc02ba09e806ff42c0a894062bdb7cd9
6
+ metadata.gz: f8adb28bccf0d2cb6931743e167a7e97ad3122a19ec108b056fb87bb5254375e8553cc8cc9c6ef96f8839f6dacd774ab00abf8ffda381c4a8777239656702199
7
+ data.tar.gz: a725449f9766d47161b8831a8c8153da92c9ef58b8055b3b9f70f24c371154ec63960070e58d706b7db9620b7b3c1d36476cefc45293e5f2411df51aaab560a4
@@ -1,4 +1,8 @@
1
- ## 0.3.0 - Unreleased
1
+ ## 0.4.0 - April 20, 2015
2
+
3
+ - Added the `have_been_enqueued` matcher
4
+
5
+ ## 0.3.0 - March 21, 2015
2
6
 
3
7
  - Added the `deserialize_as` matcher
4
8
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-activejob (0.3.0)
4
+ rspec-activejob (0.4.0)
5
5
  activejob (>= 4.2)
6
6
  rspec-mocks
7
7
 
@@ -8,6 +8,10 @@ module RSpec
8
8
  Matchers::EnqueueA.new(job_class)
9
9
  end
10
10
 
11
+ def have_been_enqueued
12
+ Matchers::EnqueueA.new
13
+ end
14
+
11
15
  def global_id(expected)
12
16
  Matchers::GlobalID.new(expected)
13
17
  end
@@ -8,15 +8,21 @@ module RSpec
8
8
  @job_class = job_class
9
9
  end
10
10
 
11
- def matches?(block)
12
- @before_jobs = enqueued_jobs.dup
13
- block.call
14
- enqueued_something? && enqueued_correct_class? && with_correct_args?
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
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module ActiveJob
3
- VERSION = '0.3.0'.freeze
3
+ VERSION = '0.4.0'.freeze
4
4
  end
5
5
  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
- it { is_expected.to be(true) }
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 BJob, enqueued a AJob")
24
+ to eq("expected to enqueue a job, enqueued nothing")
39
25
  end
40
26
  end
41
27
 
42
- context "when it enqueues two jobs" do
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: [] } << { job: BJob, 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
- context "with argument expectations" do
52
- let(:job_class) { AJob }
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
- let(:proc) do
57
- -> { enqueued_jobs << { job: AJob, args: [BJob.new, { thing: 1, 'thing' => 2 }] } }
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
- it { is_expected.to be(true) }
61
-
62
- context "with mismatching arguments" do
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 AJob with #{arguments}, but enqueued with []")
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.3.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-03-31 00:00:00.000000000 Z
11
+ date: 2015-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob