rspec-sidekiq_pro 0.0.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +172 -2
- data/lib/rspec/sidekiq_pro/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0209fc3fe2a82f7cd7355cd0514da771926c8557b68fd4ea23680d0b5cc95e6
|
4
|
+
data.tar.gz: bea903392cd28942099eb2b70e6ee0111df93842c569d7a5ccba113e4e9fdb4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fddfe519ba229d75f3c6bcd1f1a68eade0e7c23babb04ebe377484a3704857bb47feb12d6f9de213cdf0fe9a037b874bfb78692c5a69359f5cf270bb0a28f020
|
7
|
+
data.tar.gz: f1177195cf806d86619f027255619fdd5b47f370aba696a4d3931cccf8498197f758895c7fb7cee1a10320fe5cea94d48cc7e044a7250d9a767bcfd5252c0d2a
|
data/README.md
CHANGED
@@ -1,14 +1,182 @@
|
|
1
1
|
# Rspec for Sidekiq Pro
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/rspec-sidekiq_pro.svg)](https://rubygems.org/gems/rspec-sidekiq_pro)
|
4
|
+
[![CI Status](https://github.com/inkstak/rspec-sidekiq_pro/actions/workflows/ci.yml/badge.svg)](https://github.com/inkstak/rspec-sidekiq_pro/actions/workflows/ci.yml)
|
5
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/9bb8b75ea8c66b1a9c94/maintainability)](https://codeclimate.com/github/inkstak/rspec-sidekiq_pro/maintainability)
|
6
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/3de8ad4b1787cdb9ca20/test_coverage)](https://codeclimate.com/github/inkstak/rspec-sidekiq_pro/test_coverage)
|
7
|
+
|
3
8
|
### Installation
|
4
9
|
|
5
10
|
```bash
|
6
|
-
bundle add rspec-sidekiq_pro
|
11
|
+
bundle add rspec-sidekiq_pro --group=test
|
12
|
+
```
|
13
|
+
|
14
|
+
### Configuration
|
15
|
+
|
16
|
+
`rspec/sidekiq_pro` requires `sidekiq/testing` by default so there is no need to include it.
|
17
|
+
|
18
|
+
It also means that Sidekiq in set to `fake` mode by default. Take a look at [Sidekiq wiki](https://github.com/mperham/sidekiq/wiki/Testing) for more details.
|
19
|
+
|
20
|
+
If you wish to start each spec without enqueued jobs or batches:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
require "rspec/sidekiq_pro"
|
24
|
+
|
25
|
+
RSpec.configure do |config|
|
26
|
+
config.before do
|
27
|
+
Sidekiq::Queues.clear_all
|
28
|
+
RSpec::SidekiqPro::Batches.clear_all
|
29
|
+
end
|
30
|
+
end
|
7
31
|
```
|
8
32
|
|
9
33
|
### Usage
|
10
34
|
|
11
|
-
|
35
|
+
Two matchers are provided:
|
36
|
+
|
37
|
+
* `enqueue_sidekiq_job` supports block expectation
|
38
|
+
* `have_enqueued_sidekiq_job` supports value expectation
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
it do
|
42
|
+
expect { SampleJob.perform_async }.to enqueue_sidekiq_job(SampleJob)
|
43
|
+
end
|
44
|
+
```
|
45
|
+
```ruby
|
46
|
+
it do
|
47
|
+
SampleJob.perform_async
|
48
|
+
expect(SampleJob).to have_enqueued_sidekiq_job
|
49
|
+
end
|
50
|
+
```
|
51
|
+
|
52
|
+
Both matchers provide the same chainable methods:
|
53
|
+
|
54
|
+
* `.with`
|
55
|
+
* `.once`
|
56
|
+
* `.twice`
|
57
|
+
* `.exactly().times`
|
58
|
+
* `.in`
|
59
|
+
* `.at`
|
60
|
+
* `.within_batch`
|
61
|
+
* `.without_batch`
|
62
|
+
|
63
|
+
|
64
|
+
#### Checking arguments
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
it do
|
68
|
+
expect { SampleJob.perform_async(1, 2, 3) }
|
69
|
+
.to enqueue_sidekiq_job(SampleJob).with(1, 2, 3)
|
70
|
+
end
|
71
|
+
```
|
72
|
+
```ruby
|
73
|
+
it do
|
74
|
+
SampleJob.perform_async(1, 2, 3)
|
75
|
+
expect(SampleJob).to have_enqueued_sidekiq_job.with(1, 2, 3)
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
|
80
|
+
#### Checking counts
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
it do
|
84
|
+
expect { SampleJob.perform_async }
|
85
|
+
.to enqueue_sidekiq_job(SampleJob).once
|
86
|
+
end
|
87
|
+
```
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
it do
|
91
|
+
expect {
|
92
|
+
2.times { SampleJob.perform_async }
|
93
|
+
}.to enqueue_sidekiq_job(SampleJob).twice
|
94
|
+
end
|
95
|
+
```
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
it do
|
99
|
+
expect {
|
100
|
+
3.times { SampleJob.perform_async }
|
101
|
+
}.to enqueue_sidekiq_job(SampleJob).exactly(3).times
|
102
|
+
end
|
103
|
+
```
|
104
|
+
|
105
|
+
Be careful when checking both counts and arguments:
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
it do
|
109
|
+
expect {
|
110
|
+
SampleJob.perform_async.with(1)
|
111
|
+
SampleJob.perform_async.with(2)
|
112
|
+
}
|
113
|
+
.to enqueue_sidekiq_job(SampleJob).twice
|
114
|
+
.and enqueue_sidekiq_job(SampleJob).once.with(1)
|
115
|
+
.and enqueue_sidekiq_job(SampleJob).once.with(2)
|
116
|
+
end
|
117
|
+
```
|
118
|
+
|
119
|
+
#### Checking schedules
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
it do
|
123
|
+
expect {
|
124
|
+
SampleJob.perform_in(5.minutes)
|
125
|
+
}.to enqueue_sidekiq_job(SampleJob).in(5.minutes)
|
126
|
+
end
|
127
|
+
```
|
128
|
+
|
129
|
+
```ruby
|
130
|
+
it do
|
131
|
+
expect {
|
132
|
+
SampleJob.perform_at(10.minutes.from_now)
|
133
|
+
}.to enqueue_sidekiq_job(SampleJob).at(10.minutes.from_now)
|
134
|
+
end
|
135
|
+
```
|
136
|
+
|
137
|
+
Time matching is performed to the second, if you have code that takes some time to be executed consider using [Timecop](https://github.com/travisjeffery/timecop).
|
138
|
+
|
139
|
+
|
140
|
+
#### Batches
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
it do
|
144
|
+
expect {
|
145
|
+
SampleJob.perform_async
|
146
|
+
}.to enqueue_sidekiq_job(SampleJob).without_batch
|
147
|
+
end
|
148
|
+
```
|
149
|
+
|
150
|
+
```ruby
|
151
|
+
it do
|
152
|
+
expect {
|
153
|
+
batch = Sidekiq::Batch.new
|
154
|
+
batch.jobs { SampleJob.perform_async }
|
155
|
+
}.to enqueue_sidekiq_job(SampleJob).within_batch
|
156
|
+
end
|
157
|
+
```
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
it do
|
161
|
+
expect { start_some_complex_workflow }
|
162
|
+
.to enqueue_sidekiq_job(SampleJob).twice.within_batch { |batch|
|
163
|
+
expect(batch).to have_attributes(description: "Complex Workflow first step")
|
164
|
+
}
|
165
|
+
end
|
166
|
+
```
|
167
|
+
|
168
|
+
`within_batch` and `without_batch` require `Sidekiq::Testing` to be enabled.
|
169
|
+
|
170
|
+
When `Sidekiq::Testing` is enabled, every batch is pushed to `RSpec::SidekiqPro::Batches` instead of Redis.
|
171
|
+
|
172
|
+
```ruby
|
173
|
+
it do
|
174
|
+
batch = Sidekiq::Batch.new
|
175
|
+
batch.jobs { SampleJob.perform_async }
|
176
|
+
|
177
|
+
expect(RSpec::SidekiqPro::Batches.first.bid).to eq(batch.bid)
|
178
|
+
end
|
179
|
+
```
|
12
180
|
|
13
181
|
## Contributing
|
14
182
|
|
@@ -35,4 +203,6 @@ bundle exec rake
|
|
35
203
|
|
36
204
|
Please see [LICENSE](https://github.com/inkstak/rspec-sidekiq_pro/blob/main/LICENSE) for further details.
|
37
205
|
|
206
|
+
Inspired by the [philostler/rspec-sidekiq](https://github.com/philostler/rspec-sidekiq/) & [pirj/rspec-enqueue_sidekiq_job](https://github.com/pirj/rspec-enqueue_sidekiq_job)
|
207
|
+
|
38
208
|
Contributors: [./graphs/contributors](https://github.com/inkstak/rspec-sidekiq_pro/graphs/contributors)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-sidekiq_pro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Savater Sebastien
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|