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.
- checksums.yaml +9 -9
- data/.gitattributes +22 -22
- data/.gitignore +1 -1
- data/.rspec +2 -2
- data/.simplecov +5 -0
- data/CHANGES.md +52 -35
- data/Gemfile +8 -2
- data/LICENSE +8 -8
- data/README.md +181 -135
- data/lib/rspec/sidekiq/batch.rb +46 -43
- data/lib/rspec/sidekiq/configuration.rb +12 -10
- data/lib/rspec/sidekiq/helpers/within_sidekiq_retries_exhausted_block.rb +11 -0
- data/lib/rspec/sidekiq/helpers.rb +2 -0
- data/lib/rspec/sidekiq/matchers/be_delayed.rb +67 -0
- data/lib/rspec/sidekiq/matchers/be_processed_in.rb +32 -32
- data/lib/rspec/sidekiq/matchers/be_retryable.rb +38 -38
- data/lib/rspec/sidekiq/matchers/be_unique.rb +28 -28
- data/lib/rspec/sidekiq/matchers/have_enqueued_job.rb +33 -33
- data/lib/rspec/sidekiq/matchers/have_enqueued_jobs.rb +11 -36
- data/lib/rspec/sidekiq/matchers.rb +10 -9
- data/lib/rspec/sidekiq/sidekiq.rb +24 -20
- data/lib/rspec/sidekiq/version.rb +4 -4
- data/lib/rspec-sidekiq.rb +7 -6
- data/rspec-sidekiq.gemspec +35 -34
- data/spec/rspec/sidekiq/batch_spec.rb +27 -0
- data/spec/rspec/sidekiq/helpers/retries_exhausted_spec.rb +18 -0
- data/spec/rspec/sidekiq/matchers/be_delayed_spec.rb +238 -0
- data/spec/rspec/sidekiq/matchers/be_processed_in_spec.rb +107 -28
- data/spec/rspec/sidekiq/matchers/be_retryable_spec.rb +128 -40
- data/spec/rspec/sidekiq/matchers/be_unique_spec.rb +49 -14
- data/spec/rspec/sidekiq/matchers/have_enqueued_job_spec.rb +73 -0
- data/spec/rspec/sidekiq/matchers/have_enqueued_jobs_spec.rb +9 -0
- data/spec/rspec/sidekiq/sidekiq_spec.rb +15 -0
- data/spec/rspec/sidekiq/version_spec.rb +4 -6
- data/spec/spec_helper.rb +27 -25
- data/spec/support/factories.rb +22 -0
- data/spec/support/init.rb +3 -3
- data/spec/support/test_worker.rb +7 -7
- data/spec/support/test_worker_alternative.rb +7 -7
- metadata +29 -21
- data/spec/support/test_worker_defaults.rb +0 -6
data/lib/rspec/sidekiq/batch.rb
CHANGED
@@ -1,44 +1,47 @@
|
|
1
|
-
if defined?
|
2
|
-
module RSpec
|
3
|
-
module Sidekiq
|
4
|
-
class NullObject
|
5
|
-
def initialize(*)
|
6
|
-
end
|
7
|
-
|
8
|
-
def method_missing(*args, &block)
|
9
|
-
self
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
class NullBatch < NullObject
|
14
|
-
def jobs(*)
|
15
|
-
yield
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
class NullStatus < NullObject
|
20
|
-
def join
|
21
|
-
::Sidekiq::Worker.drain_all
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
Sidekiq::Batch
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
1
|
+
if defined? Sidekiq::Batch
|
2
|
+
module RSpec
|
3
|
+
module Sidekiq
|
4
|
+
class NullObject
|
5
|
+
def initialize(*)
|
6
|
+
end
|
7
|
+
|
8
|
+
def method_missing(*args, &block)
|
9
|
+
self
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class NullBatch < NullObject
|
14
|
+
def jobs(*)
|
15
|
+
yield
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class NullStatus < NullObject
|
20
|
+
def join
|
21
|
+
::Sidekiq::Worker.drain_all
|
22
|
+
end
|
23
|
+
|
24
|
+
def total
|
25
|
+
::Sidekiq::Worker.jobs.size
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
RSpec.configure do |config|
|
32
|
+
config.before(:each) do
|
33
|
+
if mocked_with_mocha?
|
34
|
+
Sidekiq::Batch.stubs(:new) { RSpec::Sidekiq::NullBatch.new }
|
35
|
+
Sidekiq::Batch::Status.stubs(:new) { RSpec::Sidekiq::NullStatus.new }
|
36
|
+
else
|
37
|
+
Sidekiq::Batch.stub(:new) { RSpec::Sidekiq::NullBatch.new }
|
38
|
+
Sidekiq::Batch::Status.stub(:new) { RSpec::Sidekiq::NullStatus.new }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
## Helpers ----------------------------------------------
|
44
|
+
def mocked_with_mocha?
|
45
|
+
Sidekiq::Batch.respond_to? :stubs
|
46
|
+
end
|
44
47
|
end
|
@@ -1,11 +1,13 @@
|
|
1
|
-
module RSpec
|
2
|
-
module Sidekiq
|
3
|
-
class Configuration
|
4
|
-
attr_accessor :clear_all_enqueued_jobs
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
@clear_all_enqueued_jobs = true
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
module RSpec
|
2
|
+
module Sidekiq
|
3
|
+
class Configuration
|
4
|
+
attr_accessor :clear_all_enqueued_jobs, :enable_terminal_colours, :warn_when_jobs_not_processed_by_sidekiq
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@clear_all_enqueued_jobs = true
|
8
|
+
@enable_terminal_colours = true
|
9
|
+
@warn_when_jobs_not_processed_by_sidekiq = true
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
11
13
|
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Sidekiq
|
3
|
+
module Matchers
|
4
|
+
def be_delayed *expected_arguments
|
5
|
+
BeDelayed.new *expected_arguments
|
6
|
+
end
|
7
|
+
|
8
|
+
class BeDelayed
|
9
|
+
def initialize *expected_arguments
|
10
|
+
@expected_arguments = expected_arguments
|
11
|
+
end
|
12
|
+
|
13
|
+
def description
|
14
|
+
description = "be delayed"
|
15
|
+
description += " for #{@expected_interval} seconds" if @expected_interval
|
16
|
+
description += " until #{@expected_time}" if @expected_time
|
17
|
+
description += " with arguments #{@expected_arguments}" unless @expected_arguments.empty?
|
18
|
+
description
|
19
|
+
end
|
20
|
+
|
21
|
+
def failure_message
|
22
|
+
"expected #{@expected_method.receiver}.#{@expected_method.name} to " + description
|
23
|
+
end
|
24
|
+
|
25
|
+
def for interval
|
26
|
+
@expected_interval = interval
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
def matches? expected_method
|
31
|
+
@expected_method = expected_method
|
32
|
+
|
33
|
+
find_job @expected_method, @expected_arguments do |job|
|
34
|
+
if @expected_interval
|
35
|
+
return job["at"].to_i == job["enqueued_at"].to_i + @expected_interval
|
36
|
+
elsif @expected_time
|
37
|
+
return job["at"].to_i == @expected_time.to_i
|
38
|
+
else
|
39
|
+
return true
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
return false
|
44
|
+
end
|
45
|
+
|
46
|
+
def negative_failure_message
|
47
|
+
"expected #{@expected_method.receiver}.#{@expected_method.name} to not " + description
|
48
|
+
end
|
49
|
+
|
50
|
+
def until time
|
51
|
+
@expected_time = time
|
52
|
+
self
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
def find_job method, arguments, &block
|
57
|
+
job = (::Sidekiq::Extensions::DelayedClass.jobs + ::Sidekiq::Extensions::DelayedModel.jobs + ::Sidekiq::Extensions::DelayedMailer.jobs).find do |job|
|
58
|
+
yaml = YAML.load(job["args"].first)
|
59
|
+
@expected_method.receiver == yaml[0] && @expected_method.name == yaml[1] && (@expected_arguments <=> yaml[2]) == 0
|
60
|
+
end
|
61
|
+
|
62
|
+
yield job if block && job
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -1,33 +1,33 @@
|
|
1
|
-
module RSpec
|
2
|
-
module Sidekiq
|
3
|
-
module Matchers
|
4
|
-
def be_processed_in
|
5
|
-
BeProcessedIn.new
|
6
|
-
end
|
7
|
-
|
8
|
-
class BeProcessedIn
|
9
|
-
def initialize
|
10
|
-
@
|
11
|
-
end
|
12
|
-
|
13
|
-
def description
|
14
|
-
"be processed in the \"#{@
|
15
|
-
end
|
16
|
-
|
17
|
-
def failure_message
|
18
|
-
"expected #{@klass} to be processed in the #{@
|
19
|
-
end
|
20
|
-
|
21
|
-
def matches? job
|
22
|
-
@klass = job.kind_of?(Class) ? job : job.class
|
23
|
-
@actual = @klass.get_sidekiq_options["queue"]
|
24
|
-
@actual.to_s == @
|
25
|
-
end
|
26
|
-
|
27
|
-
def negative_failure_message
|
28
|
-
"expected #{@klass} to not be processed in the #{@
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
1
|
+
module RSpec
|
2
|
+
module Sidekiq
|
3
|
+
module Matchers
|
4
|
+
def be_processed_in expected_queue
|
5
|
+
BeProcessedIn.new expected_queue
|
6
|
+
end
|
7
|
+
|
8
|
+
class BeProcessedIn
|
9
|
+
def initialize expected_queue
|
10
|
+
@expected_queue = expected_queue
|
11
|
+
end
|
12
|
+
|
13
|
+
def description
|
14
|
+
"be processed in the \"#{@expected_queue}\" queue"
|
15
|
+
end
|
16
|
+
|
17
|
+
def failure_message
|
18
|
+
"expected #{@klass} to be processed in the \"#{@expected_queue}\" queue but got \"#{@actual}\""
|
19
|
+
end
|
20
|
+
|
21
|
+
def matches? job
|
22
|
+
@klass = job.kind_of?(Class) ? job : job.class
|
23
|
+
@actual = @klass.get_sidekiq_options["queue"]
|
24
|
+
@actual.to_s == @expected_queue.to_s
|
25
|
+
end
|
26
|
+
|
27
|
+
def negative_failure_message
|
28
|
+
"expected #{@klass} to not be processed in the \"#{@expected_queue}\" queue"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
33
|
end
|
@@ -1,39 +1,39 @@
|
|
1
|
-
module RSpec
|
2
|
-
module Sidekiq
|
3
|
-
module Matchers
|
4
|
-
def be_retryable
|
5
|
-
BeRetryable.new
|
6
|
-
end
|
7
|
-
|
8
|
-
class BeRetryable
|
9
|
-
def initialize
|
10
|
-
@
|
11
|
-
end
|
12
|
-
|
13
|
-
def description
|
14
|
-
if @
|
15
|
-
"retry #{@
|
16
|
-
elsif @
|
17
|
-
"retry the default number of times" # retry: true
|
18
|
-
else
|
19
|
-
"not retry" # retry: false
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def failure_message
|
24
|
-
"expected #{@klass} to #{description} but got #{@actual}"
|
25
|
-
end
|
26
|
-
|
27
|
-
def matches? job
|
28
|
-
@klass = job.kind_of?(Class) ? job : job.class
|
29
|
-
@actual = @klass.get_sidekiq_options["retry"]
|
30
|
-
@actual == @
|
31
|
-
end
|
32
|
-
|
33
|
-
def negative_failure_message
|
34
|
-
"expected #{@klass} to not #{description}"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
1
|
+
module RSpec
|
2
|
+
module Sidekiq
|
3
|
+
module Matchers
|
4
|
+
def be_retryable expected_retry
|
5
|
+
BeRetryable.new expected_retry
|
6
|
+
end
|
7
|
+
|
8
|
+
class BeRetryable
|
9
|
+
def initialize expected_retry
|
10
|
+
@expected_retry = expected_retry
|
11
|
+
end
|
12
|
+
|
13
|
+
def description
|
14
|
+
if @expected_retry.is_a?(Fixnum)
|
15
|
+
"retry #{@expected_retry} times" # retry: 5
|
16
|
+
elsif @expected_retry
|
17
|
+
"retry the default number of times" # retry: true
|
18
|
+
else
|
19
|
+
"not retry" # retry: false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def failure_message
|
24
|
+
"expected #{@klass} to #{description} but got #{@actual}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def matches? job
|
28
|
+
@klass = job.kind_of?(Class) ? job : job.class
|
29
|
+
@actual = @klass.get_sidekiq_options["retry"]
|
30
|
+
@actual == @expected_retry
|
31
|
+
end
|
32
|
+
|
33
|
+
def negative_failure_message
|
34
|
+
"expected #{@klass} to not #{description}".gsub "not not ", ""
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
39
|
end
|
@@ -1,29 +1,29 @@
|
|
1
|
-
module RSpec
|
2
|
-
module Sidekiq
|
3
|
-
module Matchers
|
4
|
-
def be_unique
|
5
|
-
BeUnique.new
|
6
|
-
end
|
7
|
-
|
8
|
-
class BeUnique
|
9
|
-
def description
|
10
|
-
"be unique in the queue"
|
11
|
-
end
|
12
|
-
|
13
|
-
def failure_message
|
14
|
-
"expected #{@klass} to be unique in the queue
|
15
|
-
end
|
16
|
-
|
17
|
-
def matches? job
|
18
|
-
@klass = job.kind_of?(Class) ? job : job.class
|
19
|
-
@actual = @klass.get_sidekiq_options["unique"]
|
20
|
-
@actual == true
|
21
|
-
end
|
22
|
-
|
23
|
-
def negative_failure_message
|
24
|
-
"expected #{@klass} to not be unique in the queue"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
1
|
+
module RSpec
|
2
|
+
module Sidekiq
|
3
|
+
module Matchers
|
4
|
+
def be_unique
|
5
|
+
BeUnique.new
|
6
|
+
end
|
7
|
+
|
8
|
+
class BeUnique
|
9
|
+
def description
|
10
|
+
"be unique in the queue"
|
11
|
+
end
|
12
|
+
|
13
|
+
def failure_message
|
14
|
+
"expected #{@klass} to be unique in the queue"
|
15
|
+
end
|
16
|
+
|
17
|
+
def matches? job
|
18
|
+
@klass = job.kind_of?(Class) ? job : job.class
|
19
|
+
@actual = @klass.get_sidekiq_options["unique"]
|
20
|
+
@actual == true
|
21
|
+
end
|
22
|
+
|
23
|
+
def negative_failure_message
|
24
|
+
"expected #{@klass} to not be unique in the queue"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
29
|
end
|
@@ -1,34 +1,34 @@
|
|
1
|
-
module RSpec
|
2
|
-
module Sidekiq
|
3
|
-
module Matchers
|
4
|
-
def have_enqueued_job *
|
5
|
-
HaveEnqueuedJob.new
|
6
|
-
end
|
7
|
-
|
8
|
-
class HaveEnqueuedJob
|
9
|
-
def initialize
|
10
|
-
@
|
11
|
-
end
|
12
|
-
|
13
|
-
def description
|
14
|
-
"have an enqueued #{@klass} job with arguments #{@
|
15
|
-
end
|
16
|
-
|
17
|
-
def failure_message
|
18
|
-
"expected to have an enqueued #{@klass} job with arguments #{@
|
19
|
-
"found: #{@actual}"
|
20
|
-
end
|
21
|
-
|
22
|
-
def matches? klass
|
23
|
-
@klass = klass
|
24
|
-
@actual = klass.jobs.map { |job| job["args"] }
|
25
|
-
@actual.
|
26
|
-
end
|
27
|
-
|
28
|
-
def negative_failure_message
|
29
|
-
"expected to not have an enqueued #{@klass} job with arguments #{@
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
1
|
+
module RSpec
|
2
|
+
module Sidekiq
|
3
|
+
module Matchers
|
4
|
+
def have_enqueued_job *expected_arguments
|
5
|
+
HaveEnqueuedJob.new expected_arguments
|
6
|
+
end
|
7
|
+
|
8
|
+
class HaveEnqueuedJob
|
9
|
+
def initialize expected_arguments
|
10
|
+
@expected_arguments = expected_arguments
|
11
|
+
end
|
12
|
+
|
13
|
+
def description
|
14
|
+
"have an enqueued #{@klass} job with arguments #{@expected_arguments}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def failure_message
|
18
|
+
"expected to have an enqueued #{@klass} job with arguments #{@expected_arguments}\n\n" +
|
19
|
+
"found: #{@actual}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def matches? klass
|
23
|
+
@klass = klass
|
24
|
+
@actual = klass.jobs.map { |job| job["args"] }
|
25
|
+
@actual.any? { |arguments| Array(@expected_arguments) == arguments }
|
26
|
+
end
|
27
|
+
|
28
|
+
def negative_failure_message
|
29
|
+
"expected to not have an enqueued #{@klass} job with arguments #{@expected_arguments}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
34
|
end
|