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,29 +1,108 @@
1
- require "spec_helper"
2
-
3
- describe "Be Processed In matcher" do
4
- subject { TestWorker }
5
-
6
- describe "expect syntax" do
7
- context "when queue is specified as a string" do
8
- it "correctly matches" do
9
- expect(TestWorker).to be_processed_in "data"
10
- end
11
- end
12
-
13
- context "when queue is specified as a symbol" do
14
- it "correctly matches" do
15
- expect(TestWorker).to be_processed_in :data
16
- end
17
- end
18
- end
19
-
20
- describe "one liner syntax" do
21
- context "when queue is specified as a string" do
22
- expect_it { to be_processed_in "data" }
23
- end
24
-
25
- context "when queue is specified as a symbol" do
26
- expect_it { to be_processed_in :data }
27
- end
28
- end
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 "Be Retryable matcher" do
4
-
5
- describe "expect syntax" do
6
- context "when retryable is number" do
7
- it "correctly matches" do
8
- expect(TestWorker).to be_retryable 5
9
- end
10
- end
11
-
12
- context "when retryable is true" do
13
- it "correctly matches" do
14
- expect(TestWorkerDefaults).to be_retryable true
15
- end
16
- end
17
-
18
- context "when retryable is false" do
19
- it "correctly matches" do
20
- expect(TestWorkerAlternative).to be_retryable false
21
- end
22
- end
23
- end
24
-
25
- describe "one liner syntax" do
26
- context "when retryable is number" do
27
- subject { TestWorker }
28
- expect_it { to be_retryable 5 }
29
- end
30
-
31
- context "when retryable is true" do
32
- subject { TestWorkerDefaults }
33
- expect_it { to be_retryable true }
34
- end
35
-
36
- context "when retryable is false" do
37
- subject { TestWorkerAlternative }
38
- expect_it { to be_retryable false }
39
- end
40
- end
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 "Be Unique matcher" do
4
- subject { TestWorker }
5
-
6
- describe "expect syntax" do
7
- it "correctly matches" do
8
- expect(TestWorker).to be_unique
9
- end
10
- end
11
-
12
- describe "one liner syntax" do
13
- expect_it { to be_unique }
14
- end
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