axn 0.1.0.pre.alpha.2.1 → 0.1.0.pre.alpha.2.2
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 +3 -1
- data/docs/recipes/testing.md +30 -1
- data/lib/action/core/context_facade.rb +14 -4
- data/lib/axn/factory.rb +1 -1
- data/lib/axn/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dcfb310e364c4fb2c7159a6bdc1ff6766c0025b3b0741a62316d3e18cb5f3bf7
|
4
|
+
data.tar.gz: 7af1c3d88a69c0d109983c85fb6dc1b5ddf162568ee1e1aa516f15bf1d12a1d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13868e68f4a7b9a45bebbcf793bba1855ec2fa524ccd6f24fdaf1364bb143fcd4cfd862f0906d6455d10e61492b723ffbdc2c836a887052b030d509bf18171b0
|
7
|
+
data.tar.gz: 53014437d7a3972ec584195b2c20955ff9f2c1138dba3eeb35df2e82db8d62ec3b3561ec6b1d870472fc7fcea79dd1c2abe759cf341c46e024ae143d266bfa64
|
data/CHANGELOG.md
CHANGED
data/docs/recipes/testing.md
CHANGED
@@ -4,7 +4,36 @@
|
|
4
4
|
* TODO: document testing patterns
|
5
5
|
:::
|
6
6
|
|
7
|
-
|
7
|
+
## Mocking Axn calls
|
8
|
+
|
9
|
+
Say you're writing unit specs for PrimaryAction that calls Subaction, and you want to mock out the Subaction call.
|
10
|
+
|
11
|
+
To generate a successful Action::Result:
|
12
|
+
|
13
|
+
* Base case: `Action::Result.ok`
|
14
|
+
* [Optional] Custom message: `Action::Result.ok("It went awesome")`
|
15
|
+
* [Optional] Custom exposures: `Action::Result.ok("It went awesome", some_var: 123)`
|
16
|
+
|
17
|
+
To generate a failed Action::Result:
|
18
|
+
|
19
|
+
* Base case: `Action::Result.error`
|
20
|
+
* [Optional] Custom message: `Action::Result.error("It went poorly")`
|
21
|
+
* [Optional] Custom exposures: `Action::Result.error("It went poorly", some_var: 123)`
|
22
|
+
* [Optional] Custom exception: `Action::Result.error(some_var: 123) { raise FooBarException.new("bad thing") }`
|
23
|
+
|
24
|
+
Either way, using those to mock an actual call would look something like this in your rspec:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
let(:subaction_response) { Action::Result.ok("custom message", foo: 1) }
|
28
|
+
|
29
|
+
before do
|
30
|
+
expect(Subaction).to receive(:call).and_return(subaction_response)
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
## RSpec configuration
|
35
|
+
|
36
|
+
Configuring rspec to treat files in spec/actions as service specs (very optional):
|
8
37
|
|
9
38
|
```ruby
|
10
39
|
RSpec.configure do |config|
|
@@ -94,11 +94,21 @@ module Action
|
|
94
94
|
class Result < ContextFacade
|
95
95
|
# For ease of mocking return results in tests
|
96
96
|
class << self
|
97
|
-
def ok =
|
97
|
+
def ok(msg = nil, **exposures)
|
98
|
+
Axn::Factory.build(exposes: exposures.keys, messages: { success: msg }) do
|
99
|
+
exposures.each do |key, value|
|
100
|
+
expose(key, value)
|
101
|
+
end
|
102
|
+
end.call
|
103
|
+
end
|
98
104
|
|
99
|
-
def error(msg =
|
100
|
-
|
101
|
-
|
105
|
+
def error(msg = nil, **exposures, &block)
|
106
|
+
Axn::Factory.build(exposes: exposures.keys, messages: { error: msg }) do
|
107
|
+
exposures.each do |key, value|
|
108
|
+
expose(key, value)
|
109
|
+
end
|
110
|
+
block.call if block_given?
|
111
|
+
fail!
|
102
112
|
end.call
|
103
113
|
end
|
104
114
|
end
|
data/lib/axn/factory.rb
CHANGED
data/lib/axn/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: axn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.pre.alpha.2.
|
4
|
+
version: 0.1.0.pre.alpha.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kali Donovan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-05-
|
11
|
+
date: 2025-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|