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
@@ -1,29 +1,108 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe RSpec::Sidekiq::Matchers::BeProcessedIn do
|
4
|
+
let(:symbol_subject) { RSpec::Sidekiq::Matchers::BeProcessedIn.new :a_queue }
|
5
|
+
let(:symbol_worker) { create_worker queue: :a_queue }
|
6
|
+
let(:string_subject) { RSpec::Sidekiq::Matchers::BeProcessedIn.new "a_queue" }
|
7
|
+
let(:string_worker) { create_worker queue: "a_queue" }
|
8
|
+
before(:each) do
|
9
|
+
symbol_subject.matches? symbol_worker
|
10
|
+
string_subject.matches? string_worker
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "expected usage" do
|
14
|
+
it "matches" do
|
15
|
+
expect(symbol_worker).to be_processed_in :a_queue
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#be_processed_in" do
|
20
|
+
it "returns instance" do
|
21
|
+
expect(be_processed_in :a_queue).to be_a RSpec::Sidekiq::Matchers::BeProcessedIn
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#description" do
|
26
|
+
context "when expected is a symbol" do
|
27
|
+
it "returns description" do
|
28
|
+
expect(symbol_subject.description).to eq "be processed in the \"a_queue\" queue"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when expected is a string" do
|
33
|
+
it "returns description" do
|
34
|
+
expect(string_subject.description).to eq "be processed in the \"a_queue\" queue"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#failure_message" do
|
40
|
+
context "when expected is a symbol" do
|
41
|
+
it "returns message" do
|
42
|
+
expect(symbol_subject.failure_message).to eq "expected #{symbol_worker} to be processed in the \"a_queue\" queue but got \"a_queue\""
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "when expected is a string" do
|
47
|
+
it "returns message" do
|
48
|
+
expect(string_subject.failure_message).to eq "expected #{string_worker} to be processed in the \"a_queue\" queue but got \"a_queue\""
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#matches?" do
|
54
|
+
context "when condition matches" do
|
55
|
+
context "when expected is a symbol" do
|
56
|
+
it "returns true" do
|
57
|
+
expect(symbol_subject.matches? symbol_worker).to be true
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "when expected is a symbol and actual is string" do
|
62
|
+
it "returns true" do
|
63
|
+
expect(symbol_subject.matches? string_worker).to be true
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "when expected is a string" do
|
68
|
+
it "returns true" do
|
69
|
+
expect(string_subject.matches? string_worker).to be true
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "when expected is a string and actual is symbol" do
|
74
|
+
it "returns true" do
|
75
|
+
expect(string_subject.matches? symbol_worker).to be true
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "when condition does not match" do
|
81
|
+
context "when expected is a symbol" do
|
82
|
+
it "returns false" do
|
83
|
+
expect(symbol_subject.matches? create_worker queue: :another_queue).to be false
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context "when expected is a string" do
|
88
|
+
it "returns false" do
|
89
|
+
expect(string_subject.matches? create_worker queue: "another_queue").to be false
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "#negative_failure_message" do
|
96
|
+
context "when expected is a symbol" do
|
97
|
+
it "returns message" do
|
98
|
+
expect(symbol_subject.negative_failure_message).to eq "expected #{symbol_worker} to not be processed in the \"a_queue\" queue"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context "when expected is a string" do
|
103
|
+
it "returns message" do
|
104
|
+
expect(string_subject.negative_failure_message).to eq "expected #{string_worker} to not be processed in the \"a_queue\" queue"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
29
108
|
end
|
@@ -1,41 +1,129 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
40
|
-
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe RSpec::Sidekiq::Matchers::BeRetryable do
|
4
|
+
let(:specific_subject) { RSpec::Sidekiq::Matchers::BeRetryable.new 2 }
|
5
|
+
let(:specific_worker) { create_worker retry: 2 }
|
6
|
+
let(:default_subject) { RSpec::Sidekiq::Matchers::BeRetryable.new true }
|
7
|
+
let(:default_worker) { create_worker retry: true }
|
8
|
+
let(:negative_subject) { RSpec::Sidekiq::Matchers::BeRetryable.new false }
|
9
|
+
let(:negative_worker) { create_worker retry: false }
|
10
|
+
before(:each) do
|
11
|
+
specific_subject.matches? specific_worker
|
12
|
+
default_subject.matches? default_worker
|
13
|
+
negative_subject.matches? negative_worker
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "expected usage" do
|
17
|
+
it "matches" do
|
18
|
+
expect(default_worker).to be_retryable true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#be_retryable" do
|
23
|
+
it "returns instance" do
|
24
|
+
expect(be_retryable true).to be_a RSpec::Sidekiq::Matchers::BeRetryable
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#description" do
|
29
|
+
context "when expected is a number" do
|
30
|
+
it "returns description" do
|
31
|
+
expect(specific_subject.description).to eq "retry 2 times"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when expected is true" do
|
36
|
+
it "returns description" do
|
37
|
+
expect(default_subject.description).to eq "retry the default number of times"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "when expected is false" do
|
42
|
+
it "returns description" do
|
43
|
+
expect(negative_subject.description).to eq "not retry"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "#failure_message" do
|
49
|
+
context "when expected is a number" do
|
50
|
+
it "returns message" do
|
51
|
+
expect(specific_subject.failure_message).to eq "expected #{specific_worker} to retry 2 times but got 2"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "when expected is true" do
|
56
|
+
it "returns message" do
|
57
|
+
expect(default_subject.failure_message).to eq "expected #{default_worker} to retry the default number of times but got true"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "when expected is false" do
|
62
|
+
it "returns message" do
|
63
|
+
expect(negative_subject.failure_message).to eq "expected #{negative_worker} to not retry but got false"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#matches?" do
|
69
|
+
context "when condition matches" do
|
70
|
+
context "when expected is a number" do
|
71
|
+
it "returns true" do
|
72
|
+
expect(specific_subject.matches? specific_worker).to be true
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "when expected is true" do
|
77
|
+
it "returns true" do
|
78
|
+
expect(default_subject.matches? default_worker).to be true
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "when expected is false" do
|
83
|
+
it "returns true" do
|
84
|
+
expect(negative_subject.matches? negative_worker).to be true
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context "when condition does not match" do
|
90
|
+
context "when expected is a number" do
|
91
|
+
it "returns false" do
|
92
|
+
expect(specific_subject.matches? default_worker).to be false
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context "when expected is true" do
|
97
|
+
it "returns false" do
|
98
|
+
expect(default_subject.matches? negative_worker).to be false
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context "when expected is false" do
|
103
|
+
it "returns false" do
|
104
|
+
expect(negative_subject.matches? specific_worker).to be false
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "#negative_failure_message" do
|
111
|
+
context "when expected is a number" do
|
112
|
+
it "returns message" do
|
113
|
+
expect(specific_subject.negative_failure_message).to eq "expected #{specific_worker} to not retry 2 times"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context "when expected is true" do
|
118
|
+
it "returns message" do
|
119
|
+
expect(default_subject.negative_failure_message).to eq "expected #{default_worker} to not retry the default number of times"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
context "when expected is false" do
|
124
|
+
it "returns message" do
|
125
|
+
expect(negative_subject.negative_failure_message).to eq "expected #{negative_worker} to retry"
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
41
129
|
end
|
@@ -1,15 +1,50 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe RSpec::Sidekiq::Matchers::BeUnique do
|
4
|
+
let(:worker) { create_worker unique: true }
|
5
|
+
before(:each) { subject.matches? worker }
|
6
|
+
|
7
|
+
describe "expected usage" do
|
8
|
+
it "matches" do
|
9
|
+
expect(worker).to be_unique
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#be_unique" do
|
14
|
+
it "returns instance" do
|
15
|
+
expect(be_unique).to be_a RSpec::Sidekiq::Matchers::BeUnique
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#description" do
|
20
|
+
it "returns description" do
|
21
|
+
expect(subject.description).to eq "be unique in the queue"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#failure_message" do
|
26
|
+
it "returns message" do
|
27
|
+
expect(subject.failure_message).to eq "expected #{worker} to be unique in the queue"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#matches?" do
|
32
|
+
context "when condition matches" do
|
33
|
+
it "returns true" do
|
34
|
+
expect(subject.matches? worker).to be true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "when condition does not match" do
|
39
|
+
it "returns false" do
|
40
|
+
expect(subject.matches? create_worker unique: false).to be false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#negative_failure_message" do
|
46
|
+
it "returns message" do
|
47
|
+
expect(subject.negative_failure_message).to eq "expected #{worker} to not be unique in the queue"
|
48
|
+
end
|
49
|
+
end
|
15
50
|
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe RSpec::Sidekiq::Matchers::HaveEnqueuedJob do
|
4
|
+
let(:argument_subject) { RSpec::Sidekiq::Matchers::HaveEnqueuedJob.new ["string", 1, true] }
|
5
|
+
let(:matcher_subject) { RSpec::Sidekiq::Matchers::HaveEnqueuedJob.new [an_instance_of(String), an_instance_of(Fixnum), true] }
|
6
|
+
let(:worker) { create_worker }
|
7
|
+
before(:each) do
|
8
|
+
worker.perform_async "string", 1, true
|
9
|
+
argument_subject.matches? worker
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "expected usage" do
|
13
|
+
it "matches" do
|
14
|
+
expect(worker).to have_enqueued_job "string", 1, true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#have_enqueued_job" do
|
19
|
+
it "returns instance" do
|
20
|
+
expect(have_enqueued_job).to be_a RSpec::Sidekiq::Matchers::HaveEnqueuedJob
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#description" do
|
25
|
+
it "returns description" do
|
26
|
+
expect(argument_subject.description).to eq "have an enqueued #{worker} job with arguments [\"string\", 1, true]"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#failure_message" do
|
31
|
+
it "returns message" do
|
32
|
+
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
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#matches?" do
|
37
|
+
context "when condition matches" do
|
38
|
+
context "when expected are arguments" do
|
39
|
+
it "returns true" do
|
40
|
+
expect(argument_subject.matches? worker).to be true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "when expected are matchers" do
|
45
|
+
it "returns true" do
|
46
|
+
expect(matcher_subject.matches? worker).to be true
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "when condition does not match" do
|
52
|
+
before(:each) { Sidekiq::Worker.clear_all }
|
53
|
+
|
54
|
+
context "when expected are arguments" do
|
55
|
+
it "returns false" do
|
56
|
+
expect(argument_subject.matches? worker).to be false
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "when expected are matchers" do
|
61
|
+
it "returns false" do
|
62
|
+
expect(matcher_subject.matches? worker).to be false
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#negative_failure_message" do
|
69
|
+
it "returns message" do
|
70
|
+
expect(argument_subject.negative_failure_message).to eq "expected to not have an enqueued #{worker} job with arguments [\"string\", 1, true]"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe RSpec::Sidekiq::Matchers::HaveEnqueuedJobs do
|
4
|
+
describe "#have_enqueued_jobs" do
|
5
|
+
it "raise error" do
|
6
|
+
expect{ have_enqueued_jobs 0 }.to raise_error 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"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|