rspec-sidekiq 0.5.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +9 -9
  2. data/.gitattributes +22 -22
  3. data/.gitignore +1 -1
  4. data/.rspec +2 -2
  5. data/.simplecov +5 -0
  6. data/CHANGES.md +52 -35
  7. data/Gemfile +8 -2
  8. data/LICENSE +8 -8
  9. data/README.md +181 -135
  10. data/lib/rspec/sidekiq/batch.rb +46 -43
  11. data/lib/rspec/sidekiq/configuration.rb +12 -10
  12. data/lib/rspec/sidekiq/helpers/within_sidekiq_retries_exhausted_block.rb +11 -0
  13. data/lib/rspec/sidekiq/helpers.rb +2 -0
  14. data/lib/rspec/sidekiq/matchers/be_delayed.rb +67 -0
  15. data/lib/rspec/sidekiq/matchers/be_processed_in.rb +32 -32
  16. data/lib/rspec/sidekiq/matchers/be_retryable.rb +38 -38
  17. data/lib/rspec/sidekiq/matchers/be_unique.rb +28 -28
  18. data/lib/rspec/sidekiq/matchers/have_enqueued_job.rb +33 -33
  19. data/lib/rspec/sidekiq/matchers/have_enqueued_jobs.rb +11 -36
  20. data/lib/rspec/sidekiq/matchers.rb +10 -9
  21. data/lib/rspec/sidekiq/sidekiq.rb +24 -20
  22. data/lib/rspec/sidekiq/version.rb +4 -4
  23. data/lib/rspec-sidekiq.rb +7 -6
  24. data/rspec-sidekiq.gemspec +35 -34
  25. data/spec/rspec/sidekiq/batch_spec.rb +27 -0
  26. data/spec/rspec/sidekiq/helpers/retries_exhausted_spec.rb +18 -0
  27. data/spec/rspec/sidekiq/matchers/be_delayed_spec.rb +238 -0
  28. data/spec/rspec/sidekiq/matchers/be_processed_in_spec.rb +107 -28
  29. data/spec/rspec/sidekiq/matchers/be_retryable_spec.rb +128 -40
  30. data/spec/rspec/sidekiq/matchers/be_unique_spec.rb +49 -14
  31. data/spec/rspec/sidekiq/matchers/have_enqueued_job_spec.rb +73 -0
  32. data/spec/rspec/sidekiq/matchers/have_enqueued_jobs_spec.rb +9 -0
  33. data/spec/rspec/sidekiq/sidekiq_spec.rb +15 -0
  34. data/spec/rspec/sidekiq/version_spec.rb +4 -6
  35. data/spec/spec_helper.rb +27 -25
  36. data/spec/support/factories.rb +22 -0
  37. data/spec/support/init.rb +3 -3
  38. data/spec/support/test_worker.rb +7 -7
  39. data/spec/support/test_worker_alternative.rb +7 -7
  40. metadata +29 -21
  41. data/spec/support/test_worker_defaults.rb +0 -6
@@ -1,37 +1,12 @@
1
- module RSpec
2
- module Sidekiq
3
- module Matchers
4
- def have_enqueued_jobs expected
5
- HaveEnqueuedJobs.new expected
6
- end
7
-
8
- class HaveEnqueuedJobs
9
- def initialize expected
10
- @expected = expected
11
- end
12
-
13
- def description
14
- "have #{@expected} enqueued #{@klass} job#{jobs_description}"
15
- end
16
-
17
- def failure_message
18
- "expected #{@klass} to have #{@expected} enqueued job#{jobs_description} but got #{@actual}"
19
- end
20
-
21
- def jobs_description
22
- "s" unless @expected == 1
23
- end
24
-
25
- def matches? klass
26
- @klass = klass
27
- @actual = klass.jobs.size
28
- @actual == @expected
29
- end
30
-
31
- def negative_failure_message
32
- "expected #{@klass} to not have #{@expected} enqueued job#{jobs_description}"
33
- end
34
- end
35
- end
36
- end
1
+ module RSpec
2
+ module Sidekiq
3
+ module Matchers
4
+ def have_enqueued_jobs expected_number_of_jobs
5
+ raise RuntimeError, "have_enqueued_jobs matcher has been removed from rspec-sidekiq 1.x.x. Use \"expect(Job).to have(2).jobs\" instead. See https://github.com/philostler/rspec-sidekiq/wiki/FAQ-&-Troubleshooting"
6
+ end
7
+
8
+ class HaveEnqueuedJobs
9
+ end
10
+ end
11
+ end
37
12
  end
@@ -1,10 +1,11 @@
1
- require "rspec/core"
2
- require "rspec/sidekiq/matchers/be_processed_in"
3
- require "rspec/sidekiq/matchers/be_retryable"
4
- require "rspec/sidekiq/matchers/be_unique"
5
- require "rspec/sidekiq/matchers/have_enqueued_job"
6
- require "rspec/sidekiq/matchers/have_enqueued_jobs"
7
-
8
- RSpec.configure do |config|
9
- config.include RSpec::Sidekiq::Matchers
1
+ require "rspec/core"
2
+ require "rspec/sidekiq/matchers/be_delayed"
3
+ require "rspec/sidekiq/matchers/be_processed_in"
4
+ require "rspec/sidekiq/matchers/be_retryable"
5
+ require "rspec/sidekiq/matchers/be_unique"
6
+ require "rspec/sidekiq/matchers/have_enqueued_job"
7
+ require "rspec/sidekiq/matchers/have_enqueued_jobs"
8
+
9
+ RSpec.configure do |config|
10
+ config.include RSpec::Sidekiq::Matchers
10
11
  end
@@ -1,21 +1,25 @@
1
- module RSpec
2
- module Sidekiq
3
- class << self
4
- def configure &block
5
- yield configuration
6
-
7
- configuration
8
- end
9
-
10
- def configuration
11
- @configuration ||= Configuration.new
12
- end
13
- end
14
- end
15
- end
16
-
17
- RSpec.configure do |config|
18
- config.before(:each) do
19
- Sidekiq::Worker.clear_all if RSpec::Sidekiq.configuration.clear_all_enqueued_jobs
20
- end
1
+ module RSpec
2
+ module Sidekiq
3
+ class << self
4
+ def configure &block
5
+ yield configuration if block
6
+ end
7
+
8
+ def configuration
9
+ @configuration ||= Configuration.new
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ RSpec.configure do |config|
16
+ config.before(:suite) do
17
+ message = "[rspec-sidekiq] WARNING! Sidekiq will *NOT* process jobs in this environment. See https://github.com/philostler/rspec-sidekiq/wiki/FAQ-&-Troubleshooting"
18
+ message = "\e[33m#{message}\e[0m" if RSpec::Sidekiq.configuration.enable_terminal_colours
19
+ puts message if RSpec::Sidekiq.configuration.warn_when_jobs_not_processed_by_sidekiq
20
+ end
21
+
22
+ config.before(:each) do
23
+ Sidekiq::Worker.clear_all if RSpec::Sidekiq.configuration.clear_all_enqueued_jobs
24
+ end
21
25
  end
@@ -1,5 +1,5 @@
1
- module RSpec
2
- module Sidekiq
3
- VERSION = "0.5.1"
4
- end
1
+ module RSpec
2
+ module Sidekiq
3
+ VERSION = "1.0.0"
4
+ end
5
5
  end
data/lib/rspec-sidekiq.rb CHANGED
@@ -1,6 +1,7 @@
1
- require "sidekiq/testing"
2
-
3
- require "rspec/sidekiq/configuration"
4
- require "rspec/sidekiq/matchers"
5
- require "rspec/sidekiq/sidekiq"
6
- require "rspec/sidekiq/batch"
1
+ require "sidekiq/testing"
2
+
3
+ require "rspec/sidekiq/batch"
4
+ require "rspec/sidekiq/configuration"
5
+ require "rspec/sidekiq/helpers"
6
+ require "rspec/sidekiq/matchers"
7
+ require "rspec/sidekiq/sidekiq"
@@ -1,34 +1,35 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path("../lib/rspec/sidekiq/version", __FILE__)
3
-
4
- Gem::Specification.new do |s|
5
- s.name = "rspec-sidekiq"
6
- s.version = RSpec::Sidekiq::VERSION
7
- s.platform = Gem::Platform::RUBY
8
- s.author = "Phil Ostler"
9
- s.email = "github@philostler.com"
10
- s.homepage = "http://github.com/philostler/rspec-sidekiq"
11
- s.summary = "RSpec for Sidekiq"
12
- s.description = "Simple testing of Sidekiq jobs via a collection of matchers and common tasks"
13
- s.license = "MIT"
14
-
15
- s.add_dependency "rspec", "~> 2.0"
16
- s.add_dependency "sidekiq", ">= 2.4.0"
17
-
18
- s.add_development_dependency "coveralls", "~> 0.6.0"
19
- s.add_development_dependency "fuubar", "~> 1.1"
20
- s.add_development_dependency "rspec", "~> 2.0"
21
- s.add_development_dependency "sidekiq", ">= 2.4.0"
22
-
23
- s.files = Dir[".gitattributes"] +
24
- Dir[".gitignore"] +
25
- Dir[".rspec"] +
26
- Dir[".travis"] +
27
- Dir["CHANGES.md"] +
28
- Dir["Gemfile"] +
29
- Dir["LICENSE"] +
30
- Dir["README.md"] +
31
- Dir["rspec-sidekiq.gemspec"] +
32
- Dir["**/*.rb"]
33
- s.require_paths = ["lib"]
34
- end
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../lib/rspec/sidekiq/version", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "rspec-sidekiq"
6
+ s.version = RSpec::Sidekiq::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.author = "Phil Ostler"
9
+ s.email = "github@philostler.com"
10
+ s.homepage = "http://github.com/philostler/rspec-sidekiq"
11
+ s.summary = "RSpec for Sidekiq"
12
+ s.description = "Simple testing of Sidekiq jobs via a collection of matchers and helpers"
13
+ s.license = "MIT"
14
+
15
+ s.add_dependency "rspec", ">= 2.0.0"
16
+ s.add_dependency "sidekiq", ">= 2.4.0"
17
+
18
+ s.add_development_dependency "coveralls", "~> 0.7.0"
19
+ s.add_development_dependency "fuubar", ">= 1.1.0"
20
+ s.add_development_dependency "rspec", ">= 2.0.0"
21
+ s.add_development_dependency "sidekiq", ">= 2.4.0"
22
+
23
+ s.files = Dir[".gitattributes"] +
24
+ Dir[".gitignore"] +
25
+ Dir[".rspec"] +
26
+ Dir[".simplecov"] +
27
+ Dir[".travis"] +
28
+ Dir["CHANGES.md"] +
29
+ Dir["Gemfile"] +
30
+ Dir["LICENSE"] +
31
+ Dir["README.md"] +
32
+ Dir["rspec-sidekiq.gemspec"] +
33
+ Dir["**/*.rb"]
34
+ s.require_paths = ["lib"]
35
+ end
@@ -0,0 +1,27 @@
1
+ require "spec_helper"
2
+
3
+ describe "Batch" do
4
+ module Sidekiq
5
+ module Batch
6
+ class Status
7
+ end
8
+ end
9
+ end
10
+
11
+ load File.expand_path(File.join(File.dirname(__FILE__), "../../../lib/rspec/sidekiq/batch.rb"))
12
+
13
+ describe "NullStatus" do
14
+ describe "#total" do
15
+ it "returns 0 when no jobs" do
16
+ null_status = RSpec::Sidekiq::NullStatus.new
17
+ expect(null_status.total).to eq(0)
18
+ end
19
+
20
+ it "returns 1 when 1 job" do
21
+ null_status = RSpec::Sidekiq::NullStatus.new
22
+ TestWorker.perform_async('5')
23
+ expect(null_status.total).to eq(1)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Retries Exhausted block' do
4
+
5
+ class FooClass < TestWorkerAlternative
6
+ sidekiq_retries_exhausted do |msg|
7
+ bar('hello')
8
+ end
9
+
10
+ def self.bar(input)
11
+ end
12
+ end
13
+
14
+ it 'executes whatever is within the block' do
15
+ FooClass.within_sidekiq_retries_exhausted_block { expect(FooClass).to receive(:bar).with('hello') }
16
+ end
17
+
18
+ end
@@ -0,0 +1,238 @@
1
+ require "spec_helper"
2
+
3
+ describe RSpec::Sidekiq::Matchers::BeDelayed do
4
+ let(:delay_subject) { RSpec::Sidekiq::Matchers::BeDelayed.new }
5
+ let(:delay_with_arguments_subject) { RSpec::Sidekiq::Matchers::BeDelayed.new Object }
6
+ let(:delay_for_subject) { RSpec::Sidekiq::Matchers::BeDelayed.new.for 3600 }
7
+ let(:delay_for_with_arguments_subject) { RSpec::Sidekiq::Matchers::BeDelayed.new(Object).for 3600 }
8
+ let(:delay_until_subject) { RSpec::Sidekiq::Matchers::BeDelayed.new.until Time.now + 3600 }
9
+ let(:delay_until_with_arguments_subject) { RSpec::Sidekiq::Matchers::BeDelayed.new(Object).until Time.now + 3600 }
10
+ before(:each) do
11
+ delay_subject.matches? Object.method :nil?
12
+ delay_with_arguments_subject.matches? Object.method :is_a?
13
+
14
+ delay_for_subject.matches? Object.method :nil?
15
+ delay_for_with_arguments_subject.matches? Object.method :is_a?
16
+
17
+ delay_until_subject.matches? Object.method :nil?
18
+ delay_until_with_arguments_subject.matches? Object.method :is_a?
19
+ end
20
+
21
+ describe "expected usage" do
22
+ it "matches" do
23
+ Object.delay_for(3600).is_a? Object
24
+
25
+ expect(Object.method :is_a?).to be_delayed(Object).for 3600
26
+ end
27
+ end
28
+
29
+ describe "#be_delayed_job" do
30
+ it "returns instance" do
31
+ expect(be_delayed).to be_a RSpec::Sidekiq::Matchers::BeDelayed
32
+ end
33
+ end
34
+
35
+ describe "#description" do
36
+ context "when expected is a delay" do
37
+ it "returns description" do
38
+ expect(delay_subject.description).to eq "be delayed"
39
+ end
40
+ end
41
+
42
+ context "when expected is a delay with arguments" do
43
+ it "returns description" do
44
+ expect(delay_with_arguments_subject.description).to eq "be delayed with arguments [Object]"
45
+ end
46
+ end
47
+
48
+ context "when expected is a delay for" do
49
+ it "returns description" do
50
+ expect(delay_for_subject.description).to eq "be delayed for 3600 seconds"
51
+ end
52
+ end
53
+
54
+ context "when expected is a delay for with arguments" do
55
+ it "returns description" do
56
+ expect(delay_for_with_arguments_subject.description).to eq "be delayed for 3600 seconds with arguments [Object]"
57
+ end
58
+ end
59
+
60
+ context "when expected is a delay until" do
61
+ it "returns description" do
62
+ expect(delay_until_subject.description).to eq "be delayed until #{Time.now + 3600}"
63
+ end
64
+ end
65
+
66
+ context "when expected is a delay until with arguments" do
67
+ it "returns description" do
68
+ expect(delay_until_with_arguments_subject.description).to eq "be delayed until #{Time.now + 3600} with arguments [Object]"
69
+ end
70
+ end
71
+ end
72
+
73
+ describe "#failure_message" do
74
+ context "when expected is a delay" do
75
+ it "returns message" do
76
+ expect(delay_subject.failure_message).to eq "expected Object.nil? to be delayed"
77
+ end
78
+ end
79
+
80
+ context "when expected is a delay with arguments" do
81
+ it "returns message" do
82
+ expect(delay_with_arguments_subject.failure_message).to eq "expected Object.is_a? to be delayed with arguments [Object]"
83
+ end
84
+ end
85
+
86
+ context "when expected is a delay for" do
87
+ it "returns message" do
88
+ expect(delay_for_subject.failure_message).to eq "expected Object.nil? to be delayed for 3600 seconds"
89
+ end
90
+ end
91
+
92
+ context "when expected is a delay for with arguments" do
93
+ it "returns message" do
94
+ expect(delay_for_with_arguments_subject.failure_message).to eq "expected Object.is_a? to be delayed for 3600 seconds with arguments [Object]"
95
+ end
96
+ end
97
+
98
+ context "when expected is a delay until" do
99
+ it "returns message" do
100
+ expect(delay_until_subject.failure_message).to eq "expected Object.nil? to be delayed until #{Time.now + 3600}"
101
+ end
102
+ end
103
+
104
+ context "when expected is a delay until with arguments" do
105
+ it "returns message" do
106
+ expect(delay_until_with_arguments_subject.failure_message).to eq "expected Object.is_a? to be delayed until #{Time.now + 3600} with arguments [Object]"
107
+ end
108
+ end
109
+ end
110
+
111
+ describe "#matches?" do
112
+ context "when condition matches" do
113
+ context "when expected is a delay" do
114
+ it "returns true" do
115
+ Object.delay.nil?
116
+
117
+ expect(delay_subject.matches? Object.method :nil?).to be true
118
+ end
119
+ end
120
+
121
+ context "when expected is a delay with arguments" do
122
+ it "returns true" do
123
+ Object.delay.is_a? Object
124
+
125
+ expect(delay_with_arguments_subject.matches? Object.method :is_a?).to be true
126
+ end
127
+ end
128
+
129
+ context "when expected is a delay for" do
130
+ it "returns true" do
131
+ Object.delay_for(3600).nil?
132
+
133
+ expect(delay_for_subject.matches? Object.method :nil?).to be true
134
+ end
135
+ end
136
+
137
+ context "when expected is a delay for with arguments" do
138
+ it "returns true" do
139
+ Object.delay_for(3600).is_a? Object
140
+
141
+ expect(delay_for_with_arguments_subject.matches? Object.method :is_a?).to be true
142
+ end
143
+ end
144
+
145
+ context "when expected is a delay until" do
146
+ it "returns true" do
147
+ Object.delay_until(Time.now + 3600).nil?
148
+
149
+ expect(delay_until_subject.matches? Object.method :nil?).to be true
150
+ end
151
+ end
152
+
153
+ context "when expected is a delay until with arguments" do
154
+ it "returns true" do
155
+ Object.delay_until(Time.now + 3600).is_a? Object
156
+
157
+ expect(delay_until_with_arguments_subject.matches? Object.method :is_a?).to be true
158
+ end
159
+ end
160
+ end
161
+
162
+ context "when condition does not match" do
163
+ context "when expected is a delay" do
164
+ it "returns false" do
165
+ expect(delay_subject.matches? Object.method :nil?).to be false
166
+ end
167
+ end
168
+
169
+ context "when expected is a delay with arguments" do
170
+ it "returns false" do
171
+ expect(delay_with_arguments_subject.matches? Object.method :is_a?).to be false
172
+ end
173
+ end
174
+
175
+ context "when expected is a delay for" do
176
+ it "returns false" do
177
+ expect(delay_for_subject.matches? Object.method :nil?).to be false
178
+ end
179
+ end
180
+
181
+ context "when expected is a delay for with arguments" do
182
+ it "returns false" do
183
+ expect(delay_for_with_arguments_subject.matches? Object.method :is_a?).to be false
184
+ end
185
+ end
186
+
187
+ context "when expected is a delay until" do
188
+ it "returns false" do
189
+ expect(delay_until_subject.matches? Object.method :nil?).to be false
190
+ end
191
+ end
192
+
193
+ context "when expected is a delay until with arguments" do
194
+ it "returns false" do
195
+ expect(delay_until_with_arguments_subject.matches? Object.method :is_a?).to be false
196
+ end
197
+ end
198
+ end
199
+ end
200
+
201
+ describe "#negative_failure_message" do
202
+ context "when expected is a delay" do
203
+ it "returns message" do
204
+ expect(delay_subject.negative_failure_message).to eq "expected Object.nil? to not be delayed"
205
+ end
206
+ end
207
+
208
+ context "when expected is a delay with arguments" do
209
+ it "returns message" do
210
+ expect(delay_with_arguments_subject.negative_failure_message).to eq "expected Object.is_a? to not be delayed with arguments [Object]"
211
+ end
212
+ end
213
+
214
+ context "when expected is a delay for" do
215
+ it "returns message" do
216
+ expect(delay_for_subject.negative_failure_message).to eq "expected Object.nil? to not be delayed for 3600 seconds"
217
+ end
218
+ end
219
+
220
+ context "when expected is a delay for with arguments" do
221
+ it "returns message" do
222
+ expect(delay_for_with_arguments_subject.negative_failure_message).to eq "expected Object.is_a? to not be delayed for 3600 seconds with arguments [Object]"
223
+ end
224
+ end
225
+
226
+ context "when expected is a delay until" do
227
+ it "returns message" do
228
+ expect(delay_until_subject.negative_failure_message).to eq "expected Object.nil? to not be delayed until #{Time.now + 3600}"
229
+ end
230
+ end
231
+
232
+ context "when expected is a delay until with arguments" do
233
+ it "returns message" do
234
+ expect(delay_until_with_arguments_subject.negative_failure_message).to eq "expected Object.is_a? to not be delayed until #{Time.now + 3600} with arguments [Object]"
235
+ end
236
+ end
237
+ end
238
+ end