cmdx-rspec 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -1
- data/README.md +38 -12
- data/lib/cmdx/rspec/helpers.rb +56 -0
- data/lib/cmdx/rspec/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 65acfca8209e73048a17abf0bc8c9b260904be2d222eb8d2f620c39452da0d0b
|
|
4
|
+
data.tar.gz: 64c7756f01efe07324193ca891bf4ce841361e2ce93235437b0a63ed4c74bfea
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e05b1817afbfacd6d8fca1bf97b3f1b94ba9fdff4ab9acbb089655641430cc636efd9a60cdadc506d347ab58b907b7b11e3991eff22655a24b5b7c5660599d75
|
|
7
|
+
data.tar.gz: 5b37bad356a2973d7ab0030afe938a8baa2b8a86d62a769e1ecd9bc7ffa31c5aa424b24016b14cb564e4e5db48c10b7dfce58dfbc626a81666212ae3b77923aa
|
data/CHANGELOG.md
CHANGED
|
@@ -6,7 +6,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
-
## [1.
|
|
9
|
+
## [1.2.0] - 2025-11-08
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
- Added unmock helpers
|
|
13
|
+
|
|
14
|
+
## [1.1.0] - 2025-11-08
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
- Added unstub helpers
|
|
18
|
+
|
|
19
|
+
## [1.0.0] - 2025-11-08
|
|
10
20
|
|
|
11
21
|
### Added
|
|
12
22
|
- Added mock and stub helpers
|
data/README.md
CHANGED
|
@@ -59,7 +59,11 @@ it "returns skipped" do
|
|
|
59
59
|
expect(result).to have_skipped
|
|
60
60
|
|
|
61
61
|
# Custom result
|
|
62
|
-
expect(result).to have_skipped(
|
|
62
|
+
expect(result).to have_skipped(
|
|
63
|
+
reason: "Skipping for a custom reason",
|
|
64
|
+
cause: be_a(CMDx::SkipFault)
|
|
65
|
+
# Other members of `result.to_h`...
|
|
66
|
+
)
|
|
63
67
|
end
|
|
64
68
|
```
|
|
65
69
|
|
|
@@ -75,7 +79,11 @@ it "returns failure" do
|
|
|
75
79
|
expect(result).to have_failed
|
|
76
80
|
|
|
77
81
|
# Custom result
|
|
78
|
-
expect(result).to have_failed(
|
|
82
|
+
expect(result).to have_failed(
|
|
83
|
+
reason: "Failed for a custom reason",
|
|
84
|
+
cause: be_a(NoMethodError)
|
|
85
|
+
# Other members of `result.to_h`...
|
|
86
|
+
)
|
|
79
87
|
end
|
|
80
88
|
```
|
|
81
89
|
|
|
@@ -163,7 +171,7 @@ end
|
|
|
163
171
|
|
|
164
172
|
Helper methods for stubbing CMDx command execution.
|
|
165
173
|
|
|
166
|
-
|
|
174
|
+
#### Types
|
|
167
175
|
|
|
168
176
|
```ruby
|
|
169
177
|
it "stubs task executions by type" do
|
|
@@ -179,11 +187,7 @@ it "stubs task executions by type" do
|
|
|
179
187
|
|
|
180
188
|
# Your specs...
|
|
181
189
|
end
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
### Options
|
|
185
190
|
|
|
186
|
-
```ruby
|
|
187
191
|
it "stubs task with arguments" do
|
|
188
192
|
# eg: SomeTask.execute(some: "value")
|
|
189
193
|
stub_task_success(SomeTask, some: "value")
|
|
@@ -195,6 +199,8 @@ it "stubs task with arguments" do
|
|
|
195
199
|
end
|
|
196
200
|
```
|
|
197
201
|
|
|
202
|
+
#### Options
|
|
203
|
+
|
|
198
204
|
```ruby
|
|
199
205
|
it "stubs task with metadata" do
|
|
200
206
|
stub_task_success(SomeTask, metadata: { some: "value" })
|
|
@@ -215,11 +221,25 @@ it "stubs task with a custom cause" do
|
|
|
215
221
|
end
|
|
216
222
|
```
|
|
217
223
|
|
|
224
|
+
#### Reset
|
|
225
|
+
|
|
226
|
+
```ruby
|
|
227
|
+
it "unstubs task executions by type" do
|
|
228
|
+
# eg: SomeTask.execute
|
|
229
|
+
unstub_task(SomeTask)
|
|
230
|
+
|
|
231
|
+
# eg: SomeTask.execute!
|
|
232
|
+
unstub_task!(SomeTask)
|
|
233
|
+
|
|
234
|
+
# Your specs...
|
|
235
|
+
end
|
|
236
|
+
```
|
|
237
|
+
|
|
218
238
|
### Mocks
|
|
219
239
|
|
|
220
240
|
Helper methods for setting expectations on CMDx command execution.
|
|
221
241
|
|
|
222
|
-
|
|
242
|
+
#### Types
|
|
223
243
|
|
|
224
244
|
```ruby
|
|
225
245
|
it "mocks task executions by type" do
|
|
@@ -231,11 +251,7 @@ it "mocks task executions by type" do
|
|
|
231
251
|
|
|
232
252
|
# Your specs...
|
|
233
253
|
end
|
|
234
|
-
```
|
|
235
254
|
|
|
236
|
-
### Options
|
|
237
|
-
|
|
238
|
-
```ruby
|
|
239
255
|
it "mocks task with arguments" do
|
|
240
256
|
# eg: SomeTask.execute(some: "value")
|
|
241
257
|
expect_task_execution(SomeTask, some: "value")
|
|
@@ -245,6 +261,16 @@ it "mocks task with arguments" do
|
|
|
245
261
|
|
|
246
262
|
# Your specs...
|
|
247
263
|
end
|
|
264
|
+
|
|
265
|
+
it "mocks no task executions by type" do
|
|
266
|
+
# eg: SomeTask.execute
|
|
267
|
+
expect_no_task_execution(SomeTask)
|
|
268
|
+
|
|
269
|
+
# eg: SomeTask.execute!
|
|
270
|
+
expect_no_task_execution!(SomeTask)
|
|
271
|
+
|
|
272
|
+
# Your specs...
|
|
273
|
+
end
|
|
248
274
|
```
|
|
249
275
|
|
|
250
276
|
## Development
|
data/lib/cmdx/rspec/helpers.rb
CHANGED
|
@@ -205,6 +205,34 @@ module CMDx
|
|
|
205
205
|
result
|
|
206
206
|
end
|
|
207
207
|
|
|
208
|
+
# Unstubs a command's :execute method.
|
|
209
|
+
#
|
|
210
|
+
# @param command [Class] The command class to unstub execution on
|
|
211
|
+
#
|
|
212
|
+
# @return [void]
|
|
213
|
+
#
|
|
214
|
+
# @example Unstubbing execute
|
|
215
|
+
# unstub_task(MyCommand)
|
|
216
|
+
#
|
|
217
|
+
# MyCommand.execute
|
|
218
|
+
def unstub_task(command)
|
|
219
|
+
allow(command).to receive(:execute).and_call_original
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
# Unstubs a command's :execute! method.
|
|
223
|
+
#
|
|
224
|
+
# @param command [Class] The command class to unstub execution on
|
|
225
|
+
#
|
|
226
|
+
# @return [void]
|
|
227
|
+
#
|
|
228
|
+
# @example Unstubbing execute!
|
|
229
|
+
# unstub_task!(MyCommand)
|
|
230
|
+
#
|
|
231
|
+
# MyCommand.execute!
|
|
232
|
+
def unstub_task!(command)
|
|
233
|
+
allow(command).to receive(:execute!).and_call_original
|
|
234
|
+
end
|
|
235
|
+
|
|
208
236
|
# Sets up an expectation that a command will receive :execute with the given context.
|
|
209
237
|
#
|
|
210
238
|
# @param command [Class] The command class to expect execution on
|
|
@@ -253,6 +281,34 @@ module CMDx
|
|
|
253
281
|
end
|
|
254
282
|
end
|
|
255
283
|
|
|
284
|
+
# Sets up an expectation that a command will not receive :execute.
|
|
285
|
+
#
|
|
286
|
+
# @param command [Class] The command class to expect execution on
|
|
287
|
+
#
|
|
288
|
+
# @return [RSpec::Mocks::MessageExpectation] The RSpec expectation object
|
|
289
|
+
#
|
|
290
|
+
# @example Expecting no execution
|
|
291
|
+
# expect_no_task_execution(MyCommand)
|
|
292
|
+
#
|
|
293
|
+
# MyCommand.execute
|
|
294
|
+
def expect_no_task_execution(command)
|
|
295
|
+
expect(command).not_to receive(:execute)
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
# Sets up an expectation that a command will not receive :execute!.
|
|
299
|
+
#
|
|
300
|
+
# @param command [Class] The command class to expect execution on
|
|
301
|
+
#
|
|
302
|
+
# @return [RSpec::Mocks::MessageExpectation] The RSpec expectation object
|
|
303
|
+
#
|
|
304
|
+
# @example Expecting no execution!
|
|
305
|
+
# expect_no_task_execution!(MyCommand)
|
|
306
|
+
#
|
|
307
|
+
# MyCommand.execute!
|
|
308
|
+
def expect_no_task_execution!(command)
|
|
309
|
+
expect(command).not_to receive(:execute!)
|
|
310
|
+
end
|
|
311
|
+
|
|
256
312
|
end
|
|
257
313
|
end
|
|
258
314
|
end
|
data/lib/cmdx/rspec/version.rb
CHANGED