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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d7e467dfe5e14a9de4e6e0b2f0dc11103b2f7da3950520cd94ffed429b0eef6
4
- data.tar.gz: 0b6af1c86e14a62c8d3a4244576b5805c667788b81e276ca3e89ab03e9f293a9
3
+ metadata.gz: 4fc7ba1c5a520fd78933d838b99697a1aeb3e13aab9383f430ca22b3c227b6de
4
+ data.tar.gz: 4feb370c926b26b7499e51cf547bca870edc0ebff1184c4431b9fbf107258493
5
5
  SHA512:
6
- metadata.gz: 338465ba22c6e888adbf36f973fc56479ec58b8fb2bb3635f3c028fa02783e90fbb408d68d4399a0cb9515e7ad6bbbd6e7e1da549af2ac7258abdf87c4208b31
7
- data.tar.gz: dd456ab9cb4c907272fc8813e93d18cae68d85f09e2a2f7cc8e019a156d7911a7f99e7a267215d98cec4b0800248d4294ddf5471e1df1832fbb7629875eb38e3
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
@@ -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.
@@ -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
@@ -3,7 +3,7 @@
3
3
  module CMDx
4
4
  module RSpec
5
5
 
6
- VERSION = "1.1.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.1.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez