trailblazer-operation 0.4.1 → 0.6.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/.rubocop.yml +8 -0
- data/.rubocop_todo.yml +223 -0
- data/.travis.yml +6 -7
- data/CHANGES.md +16 -12
- data/Gemfile +5 -3
- data/README.md +13 -2
- data/Rakefile +2 -2
- data/lib/trailblazer/operation.rb +52 -67
- data/lib/trailblazer/operation/class_dependencies.rb +1 -1
- data/lib/trailblazer/operation/container.rb +14 -0
- data/lib/trailblazer/operation/deprecated_macro.rb +2 -2
- data/lib/trailblazer/operation/public_call.rb +23 -20
- data/lib/trailblazer/operation/railway.rb +2 -3
- data/lib/trailblazer/operation/railway/macaroni.rb +2 -2
- data/lib/trailblazer/operation/result.rb +14 -1
- data/lib/trailblazer/operation/trace.rb +9 -12
- data/lib/trailblazer/operation/version.rb +4 -2
- data/test/benchmark/skill_resolver_benchmark.rb +8 -9
- data/test/call_test.rb +57 -31
- data/test/callable_test.rb +147 -147
- data/test/class_dependencies_test.rb +6 -7
- data/test/docs/doormat_test.rb +13 -12
- data/test/docs/macaroni_test.rb +7 -9
- data/test/docs/operation_test.rb +69 -4
- data/test/docs/wiring_test.rb +85 -153
- data/test/dry_container_test.rb +4 -3
- data/test/fast_track_test.rb +24 -44
- data/test/inheritance_test.rb +13 -12
- data/test/introspect_test.rb +6 -6
- data/test/operation_test.rb +17 -25
- data/test/result_test.rb +4 -4
- data/test/ruby-2.0.0/operation_test.rb +9 -9
- data/test/ruby-2.0.0/step_test.rb +17 -16
- data/test/step_test.rb +55 -50
- data/test/test_helper.rb +7 -13
- data/test/trace_test.rb +27 -27
- data/test/wiring/defaults_test.rb +29 -33
- data/trailblazer-operation.gemspec +9 -7
- metadata +46 -27
- data/lib/trailblazer/operation/heritage.rb +0 -30
- data/lib/trailblazer/operation/inject.rb +0 -36
- data/lib/trailblazer/operation/inspect.rb +0 -79
- data/lib/trailblazer/operation/railway/fast_track.rb +0 -13
- data/lib/trailblazer/operation/railway/normalizer.rb +0 -58
- data/lib/trailblazer/operation/railway/task_builder.rb +0 -37
- data/test/inspect_test.rb +0 -43
- data/test/macro_test.rb +0 -60
- data/test/task_wrap_test.rb +0 -97
data/test/step_test.rb
CHANGED
@@ -7,45 +7,46 @@ require "test_helper"
|
|
7
7
|
# --- step MyMacro
|
8
8
|
class StepTest < Minitest::Spec
|
9
9
|
class Callable
|
10
|
-
def self.call(options, b:nil, **)
|
10
|
+
def self.call(options, b: nil, **)
|
11
11
|
options["b"] = b
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
module Implementation
|
16
16
|
module_function
|
17
|
-
|
17
|
+
|
18
|
+
def c(options, c: nil, **)
|
18
19
|
options["c"] = c
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
22
|
-
MyMacro = ->(
|
23
|
+
MyMacro = ->((options, flow_options), *) do
|
23
24
|
options["e"] = options[:e]
|
24
25
|
|
25
|
-
[
|
26
|
+
[Trailblazer::Activity::Right, options, flow_options]
|
26
27
|
end
|
27
28
|
|
28
29
|
class Create < Trailblazer::Operation
|
29
|
-
step ->(options, a:nil, **) { options["a"] = a }
|
30
|
+
step ->(options, a: nil, **) { options["a"] = a }
|
30
31
|
step Callable
|
31
32
|
step Implementation.method(:c)
|
32
33
|
step :d
|
33
|
-
step(
|
34
|
+
step(task: MyMacro, id: "MyMacro") # doesn't provide `runner_options` and `outputs`.
|
34
35
|
|
35
|
-
def d(options, d:nil, **)
|
36
|
+
def d(options, d: nil, **)
|
36
37
|
options["d"] = d
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
40
41
|
it { Create.(a: 1, b: 2, c: 3, d: 4, e: 5).inspect("a", "b", "c", "d", "e").must_equal "<Result:true [1, 2, 3, 4, 5] >" }
|
41
42
|
|
42
|
-
it { Trailblazer::
|
43
|
+
it { Trailblazer::Developer.railway(Create).gsub(/0x.+?step_test.rb/, "").must_equal %{[>#<Proc::30 (lambda)>,>StepTest::Callable,>#<Method: StepTest::Implementation.c>,>d,>MyMacro]} }
|
43
44
|
|
44
45
|
#---
|
45
46
|
#- :before, :after, :replace, :delete, :override
|
46
47
|
class A < Trailblazer::Operation
|
47
48
|
step :a!
|
48
|
-
def a!(options, **); options["order"] << "a"
|
49
|
+
def a!(options, **); options["order"] << "a"; end
|
49
50
|
end
|
50
51
|
|
51
52
|
class B < A
|
@@ -53,47 +54,51 @@ class StepTest < Minitest::Spec
|
|
53
54
|
step :c!, before: :a!
|
54
55
|
step :d!, after: :b!
|
55
56
|
|
56
|
-
def b!(options, **); options["order"] << "b"
|
57
|
-
|
58
|
-
def
|
57
|
+
def b!(options, **); options["order"] << "b"; end
|
58
|
+
|
59
|
+
def c!(options, **); options["order"] << "c"; end
|
60
|
+
|
61
|
+
def d!(options, **); options["order"] << "d"; end
|
59
62
|
end
|
60
63
|
|
61
|
-
it { Trailblazer::
|
64
|
+
it { Trailblazer::Developer.railway(B).must_equal %{[>b!,>d!,>c!,>a!]} }
|
62
65
|
|
63
66
|
class C < B
|
64
67
|
step :e!, replace: :c!
|
65
68
|
step "nil", delete: :d!
|
66
|
-
def e!(options, **); options["order"] << "e"
|
69
|
+
def e!(options, **); options["order"] << "e"; end
|
67
70
|
end
|
68
71
|
|
69
|
-
it { Trailblazer::
|
70
|
-
it { C.("order"=>[]).inspect("order").must_equal %{<Result:true [["b", "e", "a"]] >} }
|
72
|
+
it { Trailblazer::Developer.railway(C).must_equal %{[>b!,>e!,>a!]} }
|
73
|
+
it { C.("order" => []).inspect("order").must_equal %{<Result:true [["b", "e", "a"]] >} }
|
71
74
|
|
72
75
|
#---
|
73
76
|
#- override: true
|
74
77
|
class D < Trailblazer::Operation
|
75
78
|
step :a!
|
76
79
|
step :add!
|
77
|
-
step :add!, id: :another_add
|
80
|
+
step :add!, id: :another_add! # , override: true
|
78
81
|
|
79
82
|
def a!(options, **); options["a"] = []; end
|
83
|
+
|
80
84
|
def add!(options, **); options["a"] << :b; end
|
81
85
|
end
|
82
86
|
|
83
|
-
it { Trailblazer::
|
87
|
+
it { Trailblazer::Developer.railway(D).must_equal %{[>a!,>add!,>another_add!]} }
|
84
88
|
it { D.().inspect("a").must_equal %{<Result:true [[:b, :b]] >} }
|
85
89
|
|
86
90
|
class E < Trailblazer::Operation
|
87
|
-
|
88
|
-
step :add!
|
89
|
-
step :add!, override: true
|
91
|
+
imp = T.def_task(:b)
|
90
92
|
|
91
|
-
|
92
|
-
|
93
|
+
step :a
|
94
|
+
step(task: :b, id: :b)
|
95
|
+
step({task: imp, id: :b}, override: true)
|
96
|
+
|
97
|
+
include T.def_steps(:a)
|
93
98
|
end
|
94
99
|
|
95
|
-
it { Trailblazer::
|
96
|
-
it { E.().inspect(
|
100
|
+
it { Trailblazer::Developer.railway(E).must_equal %{[>a,>b]} }
|
101
|
+
it { E.(seq: []).inspect(:seq).must_equal %{<Result:true [[:a, :b]] >} }
|
97
102
|
|
98
103
|
#- with proc
|
99
104
|
class F < Trailblazer::Operation
|
@@ -104,33 +109,33 @@ class StepTest < Minitest::Spec
|
|
104
109
|
def a!(options, **); options["a"] = []; end
|
105
110
|
end
|
106
111
|
|
107
|
-
it { Trailblazer::
|
112
|
+
it { Trailblazer::Developer.railway(F).must_equal %{[>a!,>add!!!]} }
|
108
113
|
it { F.().inspect("a").must_equal %{<Result:true [[:b]] >} }
|
109
114
|
|
110
115
|
#- with macro
|
111
116
|
class G < Trailblazer::Operation
|
112
|
-
MyMacro1 = ->((options, flow_options), *) { options["a"] << :b; [
|
113
|
-
MyMacro2 = ->((options, flow_options), *) { options["a"] << :b; [
|
117
|
+
MyMacro1 = ->((options, flow_options), *) { options["a"] << :b; [Trailblazer::Activity::Right, options, flow_options] }
|
118
|
+
MyMacro2 = ->((options, flow_options), *) { options["a"] << :b; [Trailblazer::Activity::Right, options, flow_options] }
|
114
119
|
# MyMacro3 = ->(options, flow_options) { options["a"] << :b; [ Trailblazer::Activity::Right, options, flow_options ] }
|
115
120
|
|
116
121
|
step :a!
|
117
|
-
step(
|
118
|
-
step(
|
122
|
+
step(task: MyMacro1, id: "add")
|
123
|
+
step({task: MyMacro2, id: "add"}, replace: "add")
|
119
124
|
# step [ MyMacro3, {id: "add"}, {} ], override: true
|
120
125
|
|
121
126
|
def a!(options, **); options["a"] = []; end
|
122
127
|
end
|
123
128
|
|
124
|
-
it { Trailblazer::
|
129
|
+
it { Trailblazer::Developer.railway(G).must_equal %{[>a!,>add]} }
|
125
130
|
it { G.().inspect("a").must_equal %{<Result:true [[:b]] >} }
|
126
131
|
|
127
132
|
# override: true in inherited class with macro
|
128
133
|
class Go < G
|
129
|
-
MyMacro = ->((options, flow_options), *) { options["a"] << :m; [
|
134
|
+
MyMacro = ->((options, flow_options), *) { options["a"] << :m; [Trailblazer::Activity::Right, options, flow_options] }
|
130
135
|
step task: MyMacro, override: true, id: "add"
|
131
136
|
end
|
132
137
|
|
133
|
-
it { Trailblazer::
|
138
|
+
it { Trailblazer::Developer.railway(Go).must_equal %{[>a!,>add]} }
|
134
139
|
it { Go.().inspect("a").must_equal %{<Result:true [[:m]] >} }
|
135
140
|
|
136
141
|
#- with inheritance
|
@@ -139,6 +144,7 @@ class StepTest < Minitest::Spec
|
|
139
144
|
step :add!
|
140
145
|
|
141
146
|
def a!(options, **); options["a"] = []; end
|
147
|
+
|
142
148
|
def add!(options, **); options["a"] << :b; end
|
143
149
|
end
|
144
150
|
|
@@ -148,7 +154,7 @@ class StepTest < Minitest::Spec
|
|
148
154
|
def _add!(options, **); options["a"] << :hh; end
|
149
155
|
end
|
150
156
|
|
151
|
-
it { Trailblazer::
|
157
|
+
it { Trailblazer::Developer.railway(Hh).must_equal %{[>a!,>_add!]} }
|
152
158
|
it { Hh.().inspect("a").must_equal %{<Result:true [[:hh]] >} }
|
153
159
|
|
154
160
|
#- inheritance unit test
|
@@ -157,23 +163,21 @@ class StepTest < Minitest::Spec
|
|
157
163
|
end
|
158
164
|
|
159
165
|
class Ii < I
|
160
|
-
step :a, override: true
|
166
|
+
step({task: T.def_task(:b), id: :a}, override: true)
|
161
167
|
end
|
162
168
|
|
163
169
|
# FIXME: we have all fast track ends here.
|
164
|
-
it { skip;Ii["__activity__"].circuit.instance_variable_get(:@map).size.must_equal 6 }
|
170
|
+
it { skip; Ii["__activity__"].circuit.instance_variable_get(:@map).size.must_equal 6 }
|
165
171
|
|
166
172
|
#---
|
167
173
|
#-
|
168
174
|
# not existent :name
|
169
175
|
it do
|
170
|
-
assert_raises Trailblazer::Activity::
|
171
|
-
|
176
|
+
assert_raises Trailblazer::Activity::DSL::Linear::Sequence::IndexError do
|
172
177
|
Class.new(Trailblazer::Operation) do
|
173
178
|
step :a, before: "I don't exist!"
|
174
179
|
end
|
175
|
-
|
176
|
-
end.inspect.must_equal "#<Trailblazer::Activity::Schema::Sequence::IndexError: I don't exist!>"
|
180
|
+
end.inspect.must_equal %{#<Trailblazer::Activity::DSL::Linear::Sequence::IndexError: "I don't exist!">}
|
177
181
|
end
|
178
182
|
|
179
183
|
#---
|
@@ -182,30 +186,31 @@ class StepTest < Minitest::Spec
|
|
182
186
|
class Index < Trailblazer::Operation
|
183
187
|
step :validate!, id: "my validate"
|
184
188
|
step :persist!
|
185
|
-
step(
|
186
|
-
step(
|
189
|
+
step(task: MyMacro, id: "I win!")
|
190
|
+
step({task: "MyMacro", id: "I win!"}, id: "No, I do!")
|
187
191
|
end
|
188
192
|
|
189
|
-
it { Trailblazer::
|
193
|
+
it { Trailblazer::Developer.railway(Index).must_equal %{[>my validate,>persist!,>I win!,>No, I do!]} }
|
190
194
|
|
191
195
|
#---
|
192
196
|
#- inheritance
|
193
197
|
class New < Create
|
194
198
|
end
|
195
199
|
|
196
|
-
it { Trailblazer::
|
200
|
+
it { Trailblazer::Developer.railway(New).gsub(/0x.+?step_test.rb/, "").must_equal %{[>#<Proc::30 (lambda)>,>StepTest::Callable,>#<Method: StepTest::Implementation.c>,>d,>MyMacro]} }
|
197
201
|
|
198
202
|
class Update < Create
|
199
203
|
step :after_save!
|
200
204
|
end
|
201
205
|
|
202
|
-
it { Trailblazer::
|
206
|
+
it { Trailblazer::Developer.railway(Update).gsub(/0x.+?step_test.rb/, "").must_equal %{[>#<Proc::30 (lambda)>,>StepTest::Callable,>#<Method: StepTest::Implementation.c>,>d,>MyMacro,>after_save!]} }
|
203
207
|
end
|
204
208
|
|
205
209
|
#---
|
206
210
|
#- Macros with the old `input` arg.
|
207
211
|
# step [ ->(input, options) { } ]
|
208
|
-
|
212
|
+
# TODO: remove me in 2.2.
|
213
|
+
class StepWithDeprecatedMacroTest < Minitest::Spec
|
209
214
|
class Create < Trailblazer::Operation
|
210
215
|
MyOutdatedMacro = ->(input, options) {
|
211
216
|
options["x"] = input.class
|
@@ -217,12 +222,12 @@ class StepWithDeprecatedMacroTest < Minitest::Spec # TODO: remove me in 2.2.
|
|
217
222
|
end
|
218
223
|
end
|
219
224
|
|
220
|
-
step [
|
221
|
-
step [
|
225
|
+
step [MyOutdatedMacro, id: :outdated]
|
226
|
+
step [AnotherOldMacro, id: :oldie]
|
222
227
|
end
|
223
228
|
|
224
|
-
it { Trailblazer::
|
225
|
-
it { Create.().inspect("x", "y").must_equal %{<Result:true [StepWithDeprecatedMacroTest::Create, StepWithDeprecatedMacroTest::Create] >} }
|
229
|
+
it { skip; Trailblazer::Developer.railway(Create).gsub(/0x.+?step_test.rb/, "").must_equal %{[>outdated,>oldie]} }
|
230
|
+
it { skip; Create.().inspect("x", "y").must_equal %{<Result:true [StepWithDeprecatedMacroTest::Create, StepWithDeprecatedMacroTest::Create] >} }
|
226
231
|
end
|
227
232
|
|
228
233
|
# TODO: test failure and success aliases properly.
|
data/test/test_helper.rb
CHANGED
@@ -2,9 +2,15 @@ require "pp"
|
|
2
2
|
|
3
3
|
require "minitest/autorun"
|
4
4
|
require "trailblazer/operation"
|
5
|
+
require "trailblazer/activity/testing"
|
6
|
+
require "trailblazer/developer/render/linear"
|
5
7
|
|
6
|
-
Minitest::Spec
|
8
|
+
Minitest::Spec.class_eval do
|
9
|
+
Activity = Trailblazer::Activity
|
10
|
+
T = Activity::Testing
|
11
|
+
end
|
7
12
|
|
13
|
+
# TODO: replace all this with {Activity::Testing.def_steps}
|
8
14
|
module Test
|
9
15
|
# Create a step method in `klass` with the following body.
|
10
16
|
#
|
@@ -18,22 +24,10 @@ module Test
|
|
18
24
|
method_def =
|
19
25
|
%{def #{name}(options, #{name}_return:, data:, **)
|
20
26
|
data << :#{name}
|
21
|
-
|
22
27
|
#{name}_return
|
23
28
|
end}
|
24
29
|
|
25
30
|
klass.class_eval(method_def)
|
26
31
|
end
|
27
32
|
end
|
28
|
-
|
29
|
-
# builder for PlusPoles
|
30
|
-
def self.plus_poles_for(mapping)
|
31
|
-
ary = mapping.collect { |evt, semantic| [Trailblazer:: Activity::Output(evt, semantic), semantic ] }
|
32
|
-
|
33
|
-
Trailblazer::Activity::Magnetic::DSL::PlusPoles.new.merge(::Hash[ary])
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
Minitest::Spec.class_eval do
|
38
|
-
Activity = Trailblazer::Activity
|
39
33
|
end
|
data/test/trace_test.rb
CHANGED
@@ -8,50 +8,50 @@ class TraceTest < Minitest::Spec
|
|
8
8
|
|
9
9
|
class Create < Trailblazer::Operation
|
10
10
|
step ->(options, a_return:, **) { options[:a] = a_return }, id: "Create.task.a"
|
11
|
-
step(
|
11
|
+
step({task: B, id: "MyNested"}, B.to_h[:outputs][0] => Track(:success))
|
12
12
|
step ->(options, **) { options[:c] = true }, id: "Create.task.c"
|
13
|
-
step ->(
|
13
|
+
step ->(_options, params:, **) { params.any? }, id: "Create.task.params"
|
14
14
|
end
|
15
15
|
# raise Create["__task_wraps__"].inspect
|
16
16
|
|
17
17
|
it "allows using low-level Activity::Trace" do
|
18
|
-
|
18
|
+
->(*args) { puts "@@@@@ #{args.last.inspect}"; Create.__call__(*args) }
|
19
19
|
|
20
|
-
stack,
|
20
|
+
stack, = Trailblazer::Developer::Trace.(
|
21
21
|
Create,
|
22
22
|
[
|
23
|
-
{
|
23
|
+
{a_return: true, params: {}},
|
24
24
|
{}
|
25
25
|
]
|
26
26
|
)
|
27
27
|
|
28
|
-
puts output = Trailblazer::
|
28
|
+
puts output = Trailblazer::Developer::Trace::Present.(stack)
|
29
29
|
|
30
30
|
output.gsub(/0x\w+/, "").gsub(/@.+_test/, "").must_equal %{`-- TraceTest::Create
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
31
|
+
|-- Start.default
|
32
|
+
|-- Create.task.a
|
33
|
+
|-- MyNested
|
34
|
+
| |-- Start.default
|
35
|
+
| |-- B.task.b
|
36
|
+
| |-- B.task.e
|
37
|
+
| `-- End.success
|
38
|
+
|-- Create.task.c
|
39
|
+
|-- Create.task.params
|
40
|
+
`-- End.failure}
|
41
41
|
end
|
42
42
|
|
43
43
|
it "Operation::trace" do
|
44
|
-
result = Create.trace(
|
44
|
+
result = Create.trace(params: {x: 1}, a_return: true)
|
45
45
|
result.wtf.gsub(/0x\w+/, "").gsub(/@.+_test/, "").must_equal %{`-- TraceTest::Create
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
46
|
+
|-- Start.default
|
47
|
+
|-- Create.task.a
|
48
|
+
|-- MyNested
|
49
|
+
| |-- Start.default
|
50
|
+
| |-- B.task.b
|
51
|
+
| |-- B.task.e
|
52
|
+
| `-- End.success
|
53
|
+
|-- Create.task.c
|
54
|
+
|-- Create.task.params
|
55
|
+
`-- End.success}
|
56
56
|
end
|
57
57
|
end
|
@@ -59,7 +59,6 @@ require "test_helper"
|
|
59
59
|
# [ [:failure], Trailblazer::Operation::Railway::End::Failure.new(:failure), [] ],
|
60
60
|
# ]
|
61
61
|
|
62
|
-
|
63
62
|
# graph = Trailblazer::Activity::Schema.bla(steps + ends)
|
64
63
|
# circuit = Trailblazer::Activity.new(graph)
|
65
64
|
# # pp schema
|
@@ -79,67 +78,66 @@ require "test_helper"
|
|
79
78
|
class WireDefaultsEarlyExitSuccessTest < Minitest::Spec
|
80
79
|
class Create < Trailblazer::Operation
|
81
80
|
step :a
|
82
|
-
fail :b, Output(:success) => Track(:success) #{}"End.success"
|
81
|
+
fail :b, Output(:success) => Track(:success) # {}"End.success"
|
83
82
|
fail :c, Output(:success) => Track(:success)
|
84
83
|
|
85
84
|
Test.step(self, :a, :b, :c)
|
86
85
|
end
|
87
86
|
|
88
87
|
# a => true
|
89
|
-
it { Create.(
|
88
|
+
it { Create.(a_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a]] >} }
|
90
89
|
# b => true
|
91
|
-
it { Create.(
|
90
|
+
it { Create.(a_return: false, b_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :b]] >} }
|
92
91
|
# c => true
|
93
|
-
it { Create.(
|
92
|
+
it { Create.(a_return: false, b_return: false, c_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :b, :c]] >} }
|
94
93
|
# a => b => c => false
|
95
|
-
it { Create.(
|
94
|
+
it { Create.(a_return: false, b_return: false, c_return: false, data: []).inspect(:data).must_equal %{<Result:false [[:a, :b, :c]] >} }
|
96
95
|
|
97
96
|
# # require "trailblazer/developer"
|
98
97
|
# # it { Trailblazer::Developer::Client.push( operation: Create, name: "ushi" ) }
|
99
98
|
|
100
|
-
|
101
99
|
# #---
|
102
100
|
# # with => Track(:success), steps can still be added before End.success and they will be executed.
|
103
101
|
class Update < Create
|
104
102
|
pass :d
|
105
103
|
|
106
|
-
def d(
|
104
|
+
def d(_options, data:, **)
|
107
105
|
data << :d
|
108
106
|
end
|
109
107
|
end
|
110
108
|
|
111
109
|
# a => true
|
112
|
-
it { Update.(
|
110
|
+
it { Update.(a_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :d]] >} }
|
113
111
|
# b => true
|
114
|
-
it { Update.(
|
112
|
+
it { Update.(a_return: false, b_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :b, :d]] >} }
|
115
113
|
# c => true
|
116
|
-
it { Update.(
|
114
|
+
it { Update.(a_return: false, b_return: false, c_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :b, :c, :d]] >} }
|
117
115
|
# a => b => c => false
|
118
|
-
it { Update.(
|
116
|
+
it { Update.(a_return: false, b_return: false, c_return: false, data: []).inspect(:data).must_equal %{<Result:false [[:a, :b, :c]] >} }
|
119
117
|
|
120
118
|
#---
|
121
119
|
# failure steps reference End.success and not just the polarization. This won't call #d in failure=>success case.
|
122
120
|
class Delete < Trailblazer::Operation
|
123
121
|
step :a
|
124
|
-
fail :b, Output(:success) => "End.success"
|
125
|
-
fail :c, Output(:success) => "End.success"
|
122
|
+
fail :b, Output(:success) => Id("End.success")
|
123
|
+
fail :c, Output(:success) => Id("End.success")
|
126
124
|
pass :d
|
127
125
|
|
128
|
-
Test.step(self, :a, :b, :c)
|
126
|
+
Test.step(self, :a, :b, :c, :d)
|
129
127
|
|
130
|
-
def d(
|
128
|
+
def d(_options, data:, **)
|
131
129
|
data << :d
|
132
130
|
end
|
133
131
|
end
|
134
132
|
|
135
133
|
# a => true
|
136
|
-
it { Delete.(
|
134
|
+
it { Delete.(a_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :d]] >} }
|
137
135
|
# b => true
|
138
|
-
it { Delete.(
|
136
|
+
it { Delete.(a_return: false, b_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :b]] >} }
|
139
137
|
# c => true
|
140
|
-
it { Delete.(
|
138
|
+
it { Delete.(a_return: false, b_return: false, c_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :b, :c]] >} }
|
141
139
|
# a => b => c => false
|
142
|
-
it { Delete.(
|
140
|
+
it { Delete.(a_return: false, b_return: false, c_return: false, data: []).inspect(:data).must_equal %{<Result:false [[:a, :b, :c]] >} }
|
143
141
|
|
144
142
|
#---
|
145
143
|
# |----|
|
@@ -147,13 +145,13 @@ class WireDefaultsEarlyExitSuccessTest < Minitest::Spec
|
|
147
145
|
# |_____|_|_______ E.f
|
148
146
|
class Connect < Trailblazer::Operation
|
149
147
|
step :a
|
150
|
-
step :b, Output(:success) => "d"
|
148
|
+
step :b, Output(:success) => Id("d")
|
151
149
|
step :c, magnetic_to: [] # otherwise :success will be an open input!
|
152
150
|
pass :d, id: "d"
|
153
151
|
|
154
152
|
Test.step(self, :a, :b, :c)
|
155
153
|
|
156
|
-
def d(
|
154
|
+
def d(_options, data:, **)
|
157
155
|
data << :d
|
158
156
|
end
|
159
157
|
end
|
@@ -161,11 +159,11 @@ class WireDefaultsEarlyExitSuccessTest < Minitest::Spec
|
|
161
159
|
# it { puts Trailblazer::Activity::Magnetic::Introspect.seq( Connect.decompose.first ) }
|
162
160
|
|
163
161
|
# a => true
|
164
|
-
it { Connect.(
|
162
|
+
it { Connect.(a_return: true, b_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :b, :d]] >} }
|
165
163
|
# a => false
|
166
|
-
it { Connect.(
|
164
|
+
it { Connect.(a_return: false, data: []).inspect(:data).must_equal %{<Result:false [[:a]] >} }
|
167
165
|
# b => false
|
168
|
-
it { Connect.(
|
166
|
+
it { Connect.(a_return: true, b_return: false, data: []).inspect(:data).must_equal %{<Result:false [[:a, :b]] >} }
|
169
167
|
|
170
168
|
#---
|
171
169
|
# |---------|
|
@@ -175,8 +173,8 @@ class WireDefaultsEarlyExitSuccessTest < Minitest::Spec
|
|
175
173
|
# | \ / V
|
176
174
|
# |__f____g----E.f
|
177
175
|
class Post < Trailblazer::Operation
|
178
|
-
step :a, Output(:success) => "d", id: "a"
|
179
|
-
fail :f, Output(:success) => "c"
|
176
|
+
step :a, Output(:success) => Id("d"), id: "a"
|
177
|
+
fail :f, Output(:success) => Id("c")
|
180
178
|
step :c, magnetic_to: [], id: "c" # otherwise :success will be an open input!
|
181
179
|
fail :g
|
182
180
|
step :d, id: "d"
|
@@ -184,14 +182,12 @@ class WireDefaultsEarlyExitSuccessTest < Minitest::Spec
|
|
184
182
|
Test.step(self, :a, :f, :c, :g, :d)
|
185
183
|
end
|
186
184
|
|
187
|
-
pp Post["__sequence__"]
|
188
|
-
|
189
185
|
# a => true
|
190
|
-
it { Post.(
|
186
|
+
it { Post.(a_return: true, d_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :d]] >} }
|
191
187
|
# a => false
|
192
|
-
it { Post.(
|
188
|
+
it { Post.(a_return: false, f_return: false, g_return: nil, data: []).inspect(:data).must_equal %{<Result:false [[:a, :f, :g]] >} }
|
193
189
|
# a => false, f => true
|
194
|
-
it { Post.(
|
190
|
+
it { Post.(a_return: false, f_return: true, c_return: true, d_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :f, :c, :d]] >} }
|
195
191
|
# a => false, f => true, c => false
|
196
|
-
it { Post.(
|
192
|
+
it { Post.(a_return: false, f_return: true, c_return: false, g_return: true, data: []).inspect(:data).must_equal %{<Result:false [[:a, :f, :c, :g]] >} }
|
197
193
|
end
|