cmdx-rspec 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 65acfca8209e73048a17abf0bc8c9b260904be2d222eb8d2f620c39452da0d0b
4
- data.tar.gz: 64c7756f01efe07324193ca891bf4ce841361e2ce93235437b0a63ed4c74bfea
3
+ metadata.gz: 4fc7ba1c5a520fd78933d838b99697a1aeb3e13aab9383f430ca22b3c227b6de
4
+ data.tar.gz: 4feb370c926b26b7499e51cf547bca870edc0ebff1184c4431b9fbf107258493
5
5
  SHA512:
6
- metadata.gz: e05b1817afbfacd6d8fca1bf97b3f1b94ba9fdff4ab9acbb089655641430cc636efd9a60cdadc506d347ab58b907b7b11e3991eff22655a24b5b7c5660599d75
7
- data.tar.gz: 5b37bad356a2973d7ab0030afe938a8baa2b8a86d62a769e1ecd9bc7ffa31c5aa424b24016b14cb564e4e5db48c10b7dfce58dfbc626a81666212ae3b77923aa
6
+ metadata.gz: 4656c4a7f6cd3a4d4c111edcc6d8cee2fe26049f9925d195734a13e8e9bf63c3dd03cbe60a3805e6bcb47c8e4fa327e60f24cd2f7970d07cc225cec702172127
7
+ data.tar.gz: 6f0ceb3dca15652a1dbdff3ee6f06cf0530b7562365fa98ac698f4618310ab5bff2f6c0a2ce83b88b8ed443115dbfc7f8194eb7fb7498316ce27317041c0040d
data/CHANGELOG.md CHANGED
@@ -6,6 +6,11 @@ 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
+
9
14
  ## [1.2.0] - 2025-11-08
10
15
 
11
16
  ### 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,19 +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")
261
-
262
- # Your specs...
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)
274
+ expect_no_task_execution!(SomeTask, some: "value")
271
275
 
272
276
  # Your specs...
273
277
  end
@@ -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
- allow(command).to receive(:execute).and_call_original
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
- allow(command).to receive(:execute!).and_call_original
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.
@@ -284,29 +304,49 @@ module CMDx
284
304
  # Sets up an expectation that a command will not receive :execute.
285
305
  #
286
306
  # @param command [Class] The command class to expect execution on
307
+ # @param context [Hash] Optional keyword arguments to match against
287
308
  #
288
309
  # @return [RSpec::Mocks::MessageExpectation] The RSpec expectation object
289
310
  #
290
- # @example Expecting no execution
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
291
317
  # expect_no_task_execution(MyCommand)
292
318
  #
293
319
  # MyCommand.execute
294
- def expect_no_task_execution(command)
295
- expect(command).not_to receive(: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
296
326
  end
297
327
 
298
328
  # Sets up an expectation that a command will not receive :execute!.
299
329
  #
300
330
  # @param command [Class] The command class to expect execution on
331
+ # @param context [Hash] Optional keyword arguments to match against
301
332
  #
302
333
  # @return [RSpec::Mocks::MessageExpectation] The RSpec expectation object
303
334
  #
304
- # @example Expecting no execution!
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
305
341
  # expect_no_task_execution!(MyCommand)
306
342
  #
307
343
  # MyCommand.execute!
308
- def expect_no_task_execution!(command)
309
- expect(command).not_to receive(: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
310
350
  end
311
351
 
312
352
  end
@@ -3,7 +3,7 @@
3
3
  module CMDx
4
4
  module RSpec
5
5
 
6
- VERSION = "1.2.0"
6
+ VERSION = "1.3.0"
7
7
 
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cmdx-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez