rspec-sidekiq 1.1.0 → 2.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.gitignore +1 -1
- data/.rspec +1 -1
- data/.simplecov +1 -1
- data/CHANGES.md +5 -0
- data/Gemfile +5 -5
- data/LICENSE +2 -2
- data/README.md +0 -4
- data/lib/rspec-sidekiq.rb +8 -7
- data/lib/rspec/sidekiq/batch.rb +4 -2
- data/lib/rspec/sidekiq/configuration.rb +2 -1
- data/lib/rspec/sidekiq/helpers.rb +3 -2
- data/lib/rspec/sidekiq/helpers/within_sidekiq_retries_exhausted_block.rb +5 -4
- data/lib/rspec/sidekiq/matchers.rb +8 -8
- data/lib/rspec/sidekiq/matchers/be_delayed.rb +1 -2
- data/lib/rspec/sidekiq/matchers/be_processed_in.rb +1 -2
- data/lib/rspec/sidekiq/matchers/be_retryable.rb +1 -2
- data/lib/rspec/sidekiq/matchers/be_unique.rb +1 -2
- data/lib/rspec/sidekiq/matchers/have_enqueued_job.rb +19 -9
- data/lib/rspec/sidekiq/sidekiq.rb +4 -3
- data/lib/rspec/sidekiq/version.rb +2 -1
- data/rspec-sidekiq.gemspec +25 -25
- data/spec/rspec/sidekiq/batch_spec.rb +10 -9
- data/spec/rspec/sidekiq/helpers/retries_exhausted_spec.rb +2 -2
- data/spec/rspec/sidekiq/matchers/be_delayed_spec.rb +87 -86
- data/spec/rspec/sidekiq/matchers/be_processed_in_spec.rb +42 -41
- data/spec/rspec/sidekiq/matchers/be_retryable_spec.rb +49 -48
- data/spec/rspec/sidekiq/matchers/be_unique_spec.rb +24 -23
- data/spec/rspec/sidekiq/matchers/have_enqueued_job_spec.rb +29 -28
- data/spec/rspec/sidekiq/sidekiq_spec.rb +8 -7
- data/spec/rspec/sidekiq/version_spec.rb +3 -2
- data/spec/spec_helper.rb +7 -6
- data/spec/support/factories.rb +4 -3
- data/spec/support/init.rb +4 -3
- data/spec/support/test_worker.rb +2 -1
- data/spec/support/test_worker_alternative.rb +3 -2
- metadata +23 -25
- data/lib/rspec/sidekiq/matchers/have_enqueued_jobs.rb +0 -12
- data/spec/rspec/sidekiq/matchers/have_enqueued_jobs_spec.rb +0 -9
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
2
3
|
|
3
4
|
describe RSpec::Sidekiq::Matchers::BeRetryable do
|
4
5
|
let(:specific_subject) { RSpec::Sidekiq::Matchers::BeRetryable.new 2 }
|
@@ -13,117 +14,117 @@ describe RSpec::Sidekiq::Matchers::BeRetryable do
|
|
13
14
|
negative_subject.matches? negative_worker
|
14
15
|
end
|
15
16
|
|
16
|
-
describe
|
17
|
-
it
|
17
|
+
describe 'expected usage' do
|
18
|
+
it 'matches' do
|
18
19
|
expect(default_worker).to be_retryable true
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
22
|
-
describe
|
23
|
-
it
|
23
|
+
describe '#be_retryable' do
|
24
|
+
it 'returns instance' do
|
24
25
|
expect(be_retryable true).to be_a RSpec::Sidekiq::Matchers::BeRetryable
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
28
|
-
describe
|
29
|
-
context
|
30
|
-
it
|
31
|
-
expect(specific_subject.description).to eq
|
29
|
+
describe '#description' do
|
30
|
+
context 'when expected is a number' do
|
31
|
+
it 'returns description' do
|
32
|
+
expect(specific_subject.description).to eq 'retry 2 times'
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
35
|
-
context
|
36
|
-
it
|
37
|
-
expect(default_subject.description).to eq
|
36
|
+
context 'when expected is true' do
|
37
|
+
it 'returns description' do
|
38
|
+
expect(default_subject.description).to eq 'retry the default number of times'
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
41
|
-
context
|
42
|
-
it
|
43
|
-
expect(negative_subject.description).to eq
|
42
|
+
context 'when expected is false' do
|
43
|
+
it 'returns description' do
|
44
|
+
expect(negative_subject.description).to eq 'not retry'
|
44
45
|
end
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
48
|
-
describe
|
49
|
-
context
|
50
|
-
it
|
49
|
+
describe '#failure_message' do
|
50
|
+
context 'when expected is a number' do
|
51
|
+
it 'returns message' do
|
51
52
|
expect(specific_subject.failure_message).to eq "expected #{specific_worker} to retry 2 times but got 2"
|
52
53
|
end
|
53
54
|
end
|
54
55
|
|
55
|
-
context
|
56
|
-
it
|
56
|
+
context 'when expected is true' do
|
57
|
+
it 'returns message' do
|
57
58
|
expect(default_subject.failure_message).to eq "expected #{default_worker} to retry the default number of times but got true"
|
58
59
|
end
|
59
60
|
end
|
60
61
|
|
61
|
-
context
|
62
|
-
it
|
62
|
+
context 'when expected is false' do
|
63
|
+
it 'returns message' do
|
63
64
|
expect(negative_subject.failure_message).to eq "expected #{negative_worker} to not retry but got false"
|
64
65
|
end
|
65
66
|
end
|
66
67
|
end
|
67
68
|
|
68
|
-
describe
|
69
|
-
context
|
70
|
-
context
|
71
|
-
it
|
69
|
+
describe '#matches?' do
|
70
|
+
context 'when condition matches' do
|
71
|
+
context 'when expected is a number' do
|
72
|
+
it 'returns true' do
|
72
73
|
expect(specific_subject.matches? specific_worker).to be true
|
73
74
|
end
|
74
75
|
end
|
75
76
|
|
76
|
-
context
|
77
|
-
it
|
77
|
+
context 'when expected is true' do
|
78
|
+
it 'returns true' do
|
78
79
|
expect(default_subject.matches? default_worker).to be true
|
79
80
|
end
|
80
81
|
end
|
81
82
|
|
82
|
-
context
|
83
|
-
it
|
83
|
+
context 'when expected is false' do
|
84
|
+
it 'returns true' do
|
84
85
|
expect(negative_subject.matches? negative_worker).to be true
|
85
86
|
end
|
86
87
|
end
|
87
88
|
end
|
88
89
|
|
89
|
-
context
|
90
|
-
context
|
91
|
-
it
|
90
|
+
context 'when condition does not match' do
|
91
|
+
context 'when expected is a number' do
|
92
|
+
it 'returns false' do
|
92
93
|
expect(specific_subject.matches? default_worker).to be false
|
93
94
|
end
|
94
95
|
end
|
95
96
|
|
96
|
-
context
|
97
|
-
it
|
97
|
+
context 'when expected is true' do
|
98
|
+
it 'returns false' do
|
98
99
|
expect(default_subject.matches? negative_worker).to be false
|
99
100
|
end
|
100
101
|
end
|
101
102
|
|
102
|
-
context
|
103
|
-
it
|
103
|
+
context 'when expected is false' do
|
104
|
+
it 'returns false' do
|
104
105
|
expect(negative_subject.matches? specific_worker).to be false
|
105
106
|
end
|
106
107
|
end
|
107
108
|
end
|
108
109
|
end
|
109
110
|
|
110
|
-
describe
|
111
|
-
context
|
112
|
-
it
|
113
|
-
expect(specific_subject.
|
111
|
+
describe '#failure_message_when_negated' do
|
112
|
+
context 'when expected is a number' do
|
113
|
+
it 'returns message' do
|
114
|
+
expect(specific_subject.failure_message_when_negated).to eq "expected #{specific_worker} to not retry 2 times"
|
114
115
|
end
|
115
116
|
end
|
116
117
|
|
117
|
-
context
|
118
|
-
it
|
119
|
-
expect(default_subject.
|
118
|
+
context 'when expected is true' do
|
119
|
+
it 'returns message' do
|
120
|
+
expect(default_subject.failure_message_when_negated).to eq "expected #{default_worker} to not retry the default number of times"
|
120
121
|
end
|
121
122
|
end
|
122
123
|
|
123
|
-
context
|
124
|
-
it
|
125
|
-
expect(negative_subject.
|
124
|
+
context 'when expected is false' do
|
125
|
+
it 'returns message' do
|
126
|
+
expect(negative_subject.failure_message_when_negated).to eq "expected #{negative_worker} to retry"
|
126
127
|
end
|
127
128
|
end
|
128
129
|
end
|
129
|
-
end
|
130
|
+
end
|
@@ -1,62 +1,63 @@
|
|
1
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
2
3
|
|
3
4
|
describe RSpec::Sidekiq::Matchers::BeUnique do
|
4
|
-
shared_context
|
5
|
+
shared_context 'a unique worker' do
|
5
6
|
before(:each) { subject.matches? @worker }
|
6
7
|
|
7
|
-
describe
|
8
|
-
it
|
8
|
+
describe 'expected usage' do
|
9
|
+
it 'matches' do
|
9
10
|
expect(@worker).to be_unique
|
10
11
|
end
|
11
12
|
|
12
|
-
describe
|
13
|
-
it
|
13
|
+
describe '#failure_message' do
|
14
|
+
it 'returns message' do
|
14
15
|
expect(subject.failure_message).to eq "expected #{@worker} to be unique in the queue"
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
18
19
|
end
|
19
20
|
|
20
|
-
describe
|
21
|
-
context
|
22
|
-
it
|
21
|
+
describe '#matches?' do
|
22
|
+
context 'when condition matches' do
|
23
|
+
it 'returns true' do
|
23
24
|
expect(subject.matches? @worker).to be true
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
27
|
-
context
|
28
|
-
it
|
28
|
+
context 'when condition does not match' do
|
29
|
+
it 'returns false' do
|
29
30
|
expect(subject.matches? create_worker unique: false).to be false
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
33
|
-
describe
|
34
|
-
it
|
34
|
+
describe '#negative_failure_message' do
|
35
|
+
it 'returns message' do
|
35
36
|
expect(subject.negative_failure_message).to eq "expected #{@worker} to not be unique in the queue"
|
36
37
|
end
|
37
38
|
end
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
41
|
-
context
|
42
|
+
context 'a scheduled worker' do
|
42
43
|
before { @worker = create_worker unique: :all }
|
43
|
-
include_context
|
44
|
+
include_context 'a unique worker'
|
44
45
|
end
|
45
46
|
|
46
|
-
context
|
47
|
-
before { @worker = create_worker unique: true}
|
48
|
-
include_context
|
47
|
+
context 'a regular worker' do
|
48
|
+
before { @worker = create_worker unique: true }
|
49
|
+
include_context 'a unique worker'
|
49
50
|
end
|
50
51
|
|
51
|
-
describe
|
52
|
-
it
|
52
|
+
describe '#be_unique' do
|
53
|
+
it 'returns instance' do
|
53
54
|
expect(be_unique).to be_a RSpec::Sidekiq::Matchers::BeUnique
|
54
55
|
end
|
55
56
|
end
|
56
57
|
|
57
|
-
describe
|
58
|
-
it
|
59
|
-
expect(subject.
|
58
|
+
describe '#failure_message_when_negated' do
|
59
|
+
it 'returns message' do
|
60
|
+
expect(subject.failure_message_when_negated).to eq "expected #{worker} to not be unique in the queue"
|
60
61
|
end
|
61
62
|
end
|
62
63
|
end
|
@@ -1,73 +1,74 @@
|
|
1
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
2
3
|
|
3
4
|
describe RSpec::Sidekiq::Matchers::HaveEnqueuedJob do
|
4
|
-
let(:argument_subject) { RSpec::Sidekiq::Matchers::HaveEnqueuedJob.new [
|
5
|
-
let(:matcher_subject) { RSpec::Sidekiq::Matchers::HaveEnqueuedJob.new [
|
5
|
+
let(:argument_subject) { RSpec::Sidekiq::Matchers::HaveEnqueuedJob.new ['string', 1, true] }
|
6
|
+
let(:matcher_subject) { RSpec::Sidekiq::Matchers::HaveEnqueuedJob.new [be_a(String), be_a(Fixnum), true] }
|
6
7
|
let(:worker) { create_worker }
|
7
8
|
before(:each) do
|
8
|
-
worker.perform_async
|
9
|
+
worker.perform_async 'string', 1, true
|
9
10
|
argument_subject.matches? worker
|
10
11
|
end
|
11
12
|
|
12
|
-
describe
|
13
|
-
it
|
14
|
-
expect(worker).to have_enqueued_job
|
13
|
+
describe 'expected usage' do
|
14
|
+
it 'matches' do
|
15
|
+
expect(worker).to have_enqueued_job 'string', 1, true
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
18
|
-
describe
|
19
|
-
it
|
19
|
+
describe '#have_enqueued_job' do
|
20
|
+
it 'returns instance' do
|
20
21
|
expect(have_enqueued_job).to be_a RSpec::Sidekiq::Matchers::HaveEnqueuedJob
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
24
|
-
describe
|
25
|
-
it
|
25
|
+
describe '#description' do
|
26
|
+
it 'returns description' do
|
26
27
|
expect(argument_subject.description).to eq "have an enqueued #{worker} job with arguments [\"string\", 1, true]"
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
30
|
-
describe
|
31
|
-
it
|
31
|
+
describe '#failure_message' do
|
32
|
+
it 'returns message' do
|
32
33
|
expect(argument_subject.failure_message).to eq "expected to have an enqueued #{worker} job with arguments [\"string\", 1, true]\n\nfound: [[\"string\", 1, true]]"
|
33
34
|
end
|
34
35
|
end
|
35
36
|
|
36
|
-
describe
|
37
|
-
context
|
38
|
-
context
|
39
|
-
it
|
37
|
+
describe '#matches?' do
|
38
|
+
context 'when condition matches' do
|
39
|
+
context 'when expected are arguments' do
|
40
|
+
it 'returns true' do
|
40
41
|
expect(argument_subject.matches? worker).to be true
|
41
42
|
end
|
42
43
|
end
|
43
44
|
|
44
|
-
context
|
45
|
-
it
|
45
|
+
context 'when expected are matchers' do
|
46
|
+
it 'returns true' do
|
46
47
|
expect(matcher_subject.matches? worker).to be true
|
47
48
|
end
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
51
|
-
context
|
52
|
+
context 'when condition does not match' do
|
52
53
|
before(:each) { Sidekiq::Worker.clear_all }
|
53
54
|
|
54
|
-
context
|
55
|
-
it
|
55
|
+
context 'when expected are arguments' do
|
56
|
+
it 'returns false' do
|
56
57
|
expect(argument_subject.matches? worker).to be false
|
57
58
|
end
|
58
59
|
end
|
59
60
|
|
60
|
-
context
|
61
|
-
it
|
61
|
+
context 'when expected are matchers' do
|
62
|
+
it 'returns false' do
|
62
63
|
expect(matcher_subject.matches? worker).to be false
|
63
64
|
end
|
64
65
|
end
|
65
66
|
end
|
66
67
|
end
|
67
68
|
|
68
|
-
describe
|
69
|
-
it
|
70
|
-
expect(argument_subject.
|
69
|
+
describe '#failure_message_when_negated' do
|
70
|
+
it 'returns message' do
|
71
|
+
expect(argument_subject.failure_message_when_negated).to eq "expected to not have an enqueued #{worker} job with arguments [\"string\", 1, true]"
|
71
72
|
end
|
72
73
|
end
|
73
|
-
end
|
74
|
+
end
|
@@ -1,15 +1,16 @@
|
|
1
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
2
3
|
|
3
4
|
describe RSpec::Sidekiq do
|
4
|
-
describe
|
5
|
-
it
|
6
|
-
expect{ |block| RSpec::Sidekiq.configure(&block) }.to yield_with_args RSpec::Sidekiq.configuration
|
5
|
+
describe '#configure' do
|
6
|
+
it 'yields with configuration' do
|
7
|
+
expect { |block| RSpec::Sidekiq.configure(&block) }.to yield_with_args RSpec::Sidekiq.configuration
|
7
8
|
end
|
8
9
|
end
|
9
10
|
|
10
|
-
describe
|
11
|
-
it
|
11
|
+
describe '#configuration' do
|
12
|
+
it 'returns instance' do
|
12
13
|
expect(RSpec::Sidekiq.configuration).to be_a RSpec::Sidekiq::Configuration
|
13
14
|
end
|
14
15
|
end
|
15
|
-
end
|
16
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
|
2
|
-
require
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'simplecov'
|
3
|
+
require 'coveralls'
|
3
4
|
|
4
|
-
require
|
5
|
-
require
|
5
|
+
require 'sidekiq'
|
6
|
+
require 'rspec-sidekiq'
|
6
7
|
|
7
|
-
require_relative
|
8
|
+
require_relative 'support/init'
|
8
9
|
|
9
10
|
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
10
11
|
Coveralls::SimpleCov::Formatter,
|
@@ -25,4 +26,4 @@ end
|
|
25
26
|
RSpec::Core::MemoizedHelpers.module_eval do
|
26
27
|
alias to should
|
27
28
|
alias to_not should_not
|
28
|
-
end
|
29
|
+
end
|
data/spec/support/factories.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
module RSpec
|
2
3
|
module Sidekiq
|
3
4
|
module Spec
|
4
5
|
module Support
|
5
6
|
module Factories
|
6
|
-
def create_worker
|
7
|
-
clazz_name = "Worker#{ rand(36
|
7
|
+
def create_worker(options = {})
|
8
|
+
clazz_name = "Worker#{ rand(36**10).to_s 36 }"
|
8
9
|
clazz = Class.new do
|
9
10
|
include ::Sidekiq::Worker
|
10
11
|
|
@@ -19,4 +20,4 @@ module RSpec
|
|
19
20
|
end
|
20
21
|
end
|
21
22
|
end
|
22
|
-
end
|
23
|
+
end
|
data/spec/support/init.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
-
|
2
|
-
require_relative
|
3
|
-
require_relative
|
1
|
+
# encoding: utf-8
|
2
|
+
require_relative 'factories'
|
3
|
+
require_relative 'test_worker'
|
4
|
+
require_relative 'test_worker_alternative'
|