f_service 0.4.1 → 0.5.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 -0
- data/README.md +29 -1
- data/lib/f_service/rspec/support/helpers/result.rb +19 -1
- data/lib/f_service/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: 7e67e52f53d87a6ef69e75049dbde13dee8e57966ff6709215416a4e2eceb2c8
|
|
4
|
+
data.tar.gz: 061da3eafc01b904885ec3f60df2f33bc3cd492c123af23aa83b0bf330c125de
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c73801a230b41d8597186e8996f6bcd0e4c529c26e859eb5fac622e01d398c4bc817e705b1087fd4baa46a30c741ee9aa2139a9536cc2a7fb4caeb07a4e8eae9
|
|
7
|
+
data.tar.gz: 0eaece233ff3e02cf5a3af3bd032f9801b36dd1f1e776e7610bf5af5eeb44492568d58ea9cb7e892ca16d49d71af966c20c99e631a6360aff90abc69b7854d7f
|
data/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [0.5.0](https://github.com/Fretadao/f_service/compare/v0.4.1...v0.5.0) (2026-09-30)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### ⚠ BREAKING CHANGES
|
|
11
|
+
|
|
12
|
+
* specs that call a mocked service with arguments its initializer rejects now fail with ArgumentError, and mock_service / f_service_result raise ArgumentError for a result other than :success or :failure (e.g. :failed).
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* verify mock_service calls against the service initializer [CU-86akqxnfz] ([#77](https://github.com/Fretadao/f_service/issues/77)) ([c4efd45](https://github.com/Fretadao/f_service/commit/c4efd4588a337302e5b40e9ba8ff262984d333ee))
|
|
17
|
+
|
|
7
18
|
## [0.4.1](https://github.com/Fretadao/f_service/compare/v0.4.0...v0.4.1) (2026-08-19)
|
|
8
19
|
|
|
9
20
|
|
data/README.md
CHANGED
|
@@ -25,7 +25,7 @@ Add this line to your application's Gemfile:
|
|
|
25
25
|
|
|
26
26
|
<!-- x-release-please-start-version -->
|
|
27
27
|
```ruby
|
|
28
|
-
gem 'f_service', '~> 0.
|
|
28
|
+
gem 'f_service', '~> 0.5.0'
|
|
29
29
|
```
|
|
30
30
|
<!-- x-release-please-end-version -->
|
|
31
31
|
|
|
@@ -322,6 +322,34 @@ mock_service(
|
|
|
322
322
|
> way. `types:` also accepts a bare symbol, but an array reads consistently. The deprecated
|
|
323
323
|
> singular `type:` argument was removed in 0.4.0.
|
|
324
324
|
|
|
325
|
+
`result:` accepts only `:success` or `:failure`. Anything else raises `ArgumentError` instead of
|
|
326
|
+
silently becoming a Failure — a typo like `result: :failed` used to pass for the wrong reason.
|
|
327
|
+
|
|
328
|
+
#### Calls are checked against the service's signature
|
|
329
|
+
|
|
330
|
+
Every call to a mocked service runs the service's real `initialize` with the call's arguments,
|
|
331
|
+
so a call the service would reject fails the spec with `ArgumentError` — the same error it
|
|
332
|
+
would raise in production. The service's `#run` is never executed.
|
|
333
|
+
|
|
334
|
+
```ruby
|
|
335
|
+
class User::Create < FService::Base
|
|
336
|
+
def initialize(name:)
|
|
337
|
+
@name = name
|
|
338
|
+
end
|
|
339
|
+
end
|
|
340
|
+
|
|
341
|
+
mock_service(User::Create, types: [:created])
|
|
342
|
+
|
|
343
|
+
User::Create.(name: 'John') # => the mocked Success
|
|
344
|
+
User::Create.() # => ArgumentError: missing keyword: :name
|
|
345
|
+
User::Create.(name: 'John', age: 42) # => ArgumentError: unknown keyword: :age
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
When a spec starts failing here after an upgrade, the mock was hiding a call the service no
|
|
349
|
+
longer accepts: fix the call (or the service), not the mock. A test double passed as the
|
|
350
|
+
service (`class_double(...)`) has no real initializer, so its calls are not checked — mock the
|
|
351
|
+
real service class to get the check.
|
|
352
|
+
|
|
325
353
|
Need the Result object itself rather than a stub — to pass it around in a unit test, say?
|
|
326
354
|
`f_service_result` builds one:
|
|
327
355
|
|
|
@@ -2,8 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
# Methods to mock a FService result from a service call.
|
|
4
4
|
module FServiceResultHelpers
|
|
5
|
+
# Results a mock can describe.
|
|
6
|
+
RESULTS = %i[success failure].freeze
|
|
7
|
+
|
|
5
8
|
# Create an Fservice result Success or Failure.
|
|
9
|
+
#
|
|
10
|
+
# @raise [ArgumentError] when the result is neither :success nor :failure
|
|
6
11
|
def f_service_result(result, value = nil, types = [])
|
|
12
|
+
raise ArgumentError, "result must be :success or :failure, got #{result.inspect}" unless RESULTS.include?(result)
|
|
13
|
+
|
|
7
14
|
if result == :success
|
|
8
15
|
FService::Result::Success.new(value, Array(types))
|
|
9
16
|
else
|
|
@@ -12,9 +19,20 @@ module FServiceResultHelpers
|
|
|
12
19
|
end
|
|
13
20
|
|
|
14
21
|
# Mock a Fservice service call returning a result.
|
|
22
|
+
#
|
|
23
|
+
# Every call to the mocked service runs the service's real initializer with the call's
|
|
24
|
+
# arguments, so a call the service would reject fails with ArgumentError. The service's
|
|
25
|
+
# #run is never executed. A double passed as the service is not verified.
|
|
26
|
+
#
|
|
27
|
+
# @raise [ArgumentError] when the result is neither :success nor :failure
|
|
15
28
|
def mock_service(service, result: :success, value: nil, types: [])
|
|
16
29
|
service_result = f_service_result(result, value, Array(types))
|
|
17
|
-
|
|
30
|
+
|
|
31
|
+
allow(service).to receive(:call) do |*args, **kwargs|
|
|
32
|
+
# allocate skips .new, so a spec that stubs .new does not interfere with the verification
|
|
33
|
+
service.allocate.send(:initialize, *args, **kwargs) if service.is_a?(Class)
|
|
34
|
+
service_result
|
|
35
|
+
end
|
|
18
36
|
end
|
|
19
37
|
end
|
|
20
38
|
|
data/lib/f_service/version.rb
CHANGED