cmdx-rspec 1.1.0 → 1.3.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 +10 -0
- data/README.md +14 -0
- data/lib/cmdx/rspec/helpers.rb +73 -5
- 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: 4fc7ba1c5a520fd78933d838b99697a1aeb3e13aab9383f430ca22b3c227b6de
|
|
4
|
+
data.tar.gz: 4feb370c926b26b7499e51cf547bca870edc0ebff1184c4431b9fbf107258493
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4656c4a7f6cd3a4d4c111edcc6d8cee2fe26049f9925d195734a13e8e9bf63c3dd03cbe60a3805e6bcb47c8e4fa327e60f24cd2f7970d07cc225cec702172127
|
|
7
|
+
data.tar.gz: 6f0ceb3dca15652a1dbdff3ee6f06cf0530b7562365fa98ac698f4618310ab5bff2f6c0a2ce83b88b8ed443115dbfc7f8194eb7fb7498316ce27317041c0040d
|
data/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [1.3.0] - 2025-11-09
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
- Added context options to unstub and unmock methods
|
|
13
|
+
|
|
14
|
+
## [1.2.0] - 2025-11-08
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
- Added unmock helpers
|
|
18
|
+
|
|
9
19
|
## [1.1.0] - 2025-11-08
|
|
10
20
|
|
|
11
21
|
### Added
|
data/README.md
CHANGED
|
@@ -233,6 +233,16 @@ it "unstubs task executions by type" do
|
|
|
233
233
|
|
|
234
234
|
# Your specs...
|
|
235
235
|
end
|
|
236
|
+
|
|
237
|
+
it "unstubs task with arguments" do
|
|
238
|
+
# eg: SomeTask.execute(some: "value")
|
|
239
|
+
unstub_task(SomeTask, some: "value")
|
|
240
|
+
|
|
241
|
+
# eg: SomeTask.execute!(some: "value")
|
|
242
|
+
unstub_task!(SomeTask, some: "value")
|
|
243
|
+
|
|
244
|
+
# Your specs...
|
|
245
|
+
end
|
|
236
246
|
```
|
|
237
247
|
|
|
238
248
|
### Mocks
|
|
@@ -245,9 +255,11 @@ Helper methods for setting expectations on CMDx command execution.
|
|
|
245
255
|
it "mocks task executions by type" do
|
|
246
256
|
# eg: SomeTask.execute
|
|
247
257
|
expect_task_execution(SomeTask)
|
|
258
|
+
expect_no_task_execution(SomeTask)
|
|
248
259
|
|
|
249
260
|
# eg: SomeTask.execute!
|
|
250
261
|
expect_task_execution!(BangCommand)
|
|
262
|
+
expect_no_task_execution!(SomeTask)
|
|
251
263
|
|
|
252
264
|
# Your specs...
|
|
253
265
|
end
|
|
@@ -255,9 +267,11 @@ end
|
|
|
255
267
|
it "mocks task with arguments" do
|
|
256
268
|
# eg: SomeTask.execute(some: "value")
|
|
257
269
|
expect_task_execution(SomeTask, some: "value")
|
|
270
|
+
expect_no_task_execution(SomeTask, some: "value")
|
|
258
271
|
|
|
259
272
|
# eg: SomeTask.execute!(some: "value")
|
|
260
273
|
expect_task_execution!(SomeTask, some: "value")
|
|
274
|
+
expect_no_task_execution!(SomeTask, some: "value")
|
|
261
275
|
|
|
262
276
|
# Your specs...
|
|
263
277
|
end
|
data/lib/cmdx/rspec/helpers.rb
CHANGED
|
@@ -208,29 +208,49 @@ module CMDx
|
|
|
208
208
|
# Unstubs a command's :execute method.
|
|
209
209
|
#
|
|
210
210
|
# @param command [Class] The command class to unstub execution on
|
|
211
|
+
# @param context [Hash] Optional keyword arguments to match against
|
|
211
212
|
#
|
|
212
213
|
# @return [void]
|
|
213
214
|
#
|
|
214
|
-
# @example Unstubbing execute
|
|
215
|
+
# @example Unstubbing execute with context
|
|
216
|
+
# unstub_task(MyCommand, foo: "bar")
|
|
217
|
+
#
|
|
218
|
+
# MyCommand.execute(foo: "bar")
|
|
219
|
+
#
|
|
220
|
+
# @example Unstubbing execute without context
|
|
215
221
|
# unstub_task(MyCommand)
|
|
216
222
|
#
|
|
217
223
|
# MyCommand.execute
|
|
218
|
-
def unstub_task(command)
|
|
219
|
-
|
|
224
|
+
def unstub_task(command, **context)
|
|
225
|
+
if context.empty?
|
|
226
|
+
allow(command).to receive(:execute).and_call_original
|
|
227
|
+
else
|
|
228
|
+
allow(command).to receive(:execute).with(**context).and_call_original
|
|
229
|
+
end
|
|
220
230
|
end
|
|
221
231
|
|
|
222
232
|
# Unstubs a command's :execute! method.
|
|
223
233
|
#
|
|
224
234
|
# @param command [Class] The command class to unstub execution on
|
|
235
|
+
# @param context [Hash] Optional keyword arguments to match against
|
|
225
236
|
#
|
|
226
237
|
# @return [void]
|
|
227
238
|
#
|
|
228
239
|
# @example Unstubbing execute!
|
|
240
|
+
# unstub_task!(MyCommand, foo: "bar")
|
|
241
|
+
#
|
|
242
|
+
# MyCommand.execute!(foo: "bar")
|
|
243
|
+
#
|
|
244
|
+
# @example Unstubbing execute! without context
|
|
229
245
|
# unstub_task!(MyCommand)
|
|
230
246
|
#
|
|
231
247
|
# MyCommand.execute!
|
|
232
|
-
def unstub_task!(command)
|
|
233
|
-
|
|
248
|
+
def unstub_task!(command, **context)
|
|
249
|
+
if context.empty?
|
|
250
|
+
allow(command).to receive(:execute!).and_call_original
|
|
251
|
+
else
|
|
252
|
+
allow(command).to receive(:execute!).with(**context).and_call_original
|
|
253
|
+
end
|
|
234
254
|
end
|
|
235
255
|
|
|
236
256
|
# Sets up an expectation that a command will receive :execute with the given context.
|
|
@@ -281,6 +301,54 @@ module CMDx
|
|
|
281
301
|
end
|
|
282
302
|
end
|
|
283
303
|
|
|
304
|
+
# Sets up an expectation that a command will not receive :execute.
|
|
305
|
+
#
|
|
306
|
+
# @param command [Class] The command class to expect execution on
|
|
307
|
+
# @param context [Hash] Optional keyword arguments to match against
|
|
308
|
+
#
|
|
309
|
+
# @return [RSpec::Mocks::MessageExpectation] The RSpec expectation object
|
|
310
|
+
#
|
|
311
|
+
# @example Expecting no execution with context
|
|
312
|
+
# expect_no_task_execution(MyCommand, foo: "bar")
|
|
313
|
+
#
|
|
314
|
+
# MyCommand.execute(foo: "bar")
|
|
315
|
+
#
|
|
316
|
+
# @example Expecting no execution with empty context
|
|
317
|
+
# expect_no_task_execution(MyCommand)
|
|
318
|
+
#
|
|
319
|
+
# MyCommand.execute
|
|
320
|
+
def expect_no_task_execution(command, **context)
|
|
321
|
+
if context.empty?
|
|
322
|
+
expect(command).not_to receive(:execute)
|
|
323
|
+
else
|
|
324
|
+
expect(command).not_to receive(:execute).with(**context)
|
|
325
|
+
end
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
# Sets up an expectation that a command will not receive :execute!.
|
|
329
|
+
#
|
|
330
|
+
# @param command [Class] The command class to expect execution on
|
|
331
|
+
# @param context [Hash] Optional keyword arguments to match against
|
|
332
|
+
#
|
|
333
|
+
# @return [RSpec::Mocks::MessageExpectation] The RSpec expectation object
|
|
334
|
+
#
|
|
335
|
+
# @example Expecting no execution! with context
|
|
336
|
+
# expect_no_task_execution!(MyCommand, foo: "bar")
|
|
337
|
+
#
|
|
338
|
+
# MyCommand.execute!(foo: "bar")
|
|
339
|
+
#
|
|
340
|
+
# @example Expecting no execution! with empty context
|
|
341
|
+
# expect_no_task_execution!(MyCommand)
|
|
342
|
+
#
|
|
343
|
+
# MyCommand.execute!
|
|
344
|
+
def expect_no_task_execution!(command, **context)
|
|
345
|
+
if context.empty?
|
|
346
|
+
expect(command).not_to receive(:execute!)
|
|
347
|
+
else
|
|
348
|
+
expect(command).not_to receive(:execute!).with(**context)
|
|
349
|
+
end
|
|
350
|
+
end
|
|
351
|
+
|
|
284
352
|
end
|
|
285
353
|
end
|
|
286
354
|
end
|
data/lib/cmdx/rspec/version.rb
CHANGED