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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +8 -0
  3. data/.rubocop_todo.yml +223 -0
  4. data/.travis.yml +6 -7
  5. data/CHANGES.md +16 -12
  6. data/Gemfile +5 -3
  7. data/README.md +13 -2
  8. data/Rakefile +2 -2
  9. data/lib/trailblazer/operation.rb +52 -67
  10. data/lib/trailblazer/operation/class_dependencies.rb +1 -1
  11. data/lib/trailblazer/operation/container.rb +14 -0
  12. data/lib/trailblazer/operation/deprecated_macro.rb +2 -2
  13. data/lib/trailblazer/operation/public_call.rb +23 -20
  14. data/lib/trailblazer/operation/railway.rb +2 -3
  15. data/lib/trailblazer/operation/railway/macaroni.rb +2 -2
  16. data/lib/trailblazer/operation/result.rb +14 -1
  17. data/lib/trailblazer/operation/trace.rb +9 -12
  18. data/lib/trailblazer/operation/version.rb +4 -2
  19. data/test/benchmark/skill_resolver_benchmark.rb +8 -9
  20. data/test/call_test.rb +57 -31
  21. data/test/callable_test.rb +147 -147
  22. data/test/class_dependencies_test.rb +6 -7
  23. data/test/docs/doormat_test.rb +13 -12
  24. data/test/docs/macaroni_test.rb +7 -9
  25. data/test/docs/operation_test.rb +69 -4
  26. data/test/docs/wiring_test.rb +85 -153
  27. data/test/dry_container_test.rb +4 -3
  28. data/test/fast_track_test.rb +24 -44
  29. data/test/inheritance_test.rb +13 -12
  30. data/test/introspect_test.rb +6 -6
  31. data/test/operation_test.rb +17 -25
  32. data/test/result_test.rb +4 -4
  33. data/test/ruby-2.0.0/operation_test.rb +9 -9
  34. data/test/ruby-2.0.0/step_test.rb +17 -16
  35. data/test/step_test.rb +55 -50
  36. data/test/test_helper.rb +7 -13
  37. data/test/trace_test.rb +27 -27
  38. data/test/wiring/defaults_test.rb +29 -33
  39. data/trailblazer-operation.gemspec +9 -7
  40. metadata +46 -27
  41. data/lib/trailblazer/operation/heritage.rb +0 -30
  42. data/lib/trailblazer/operation/inject.rb +0 -36
  43. data/lib/trailblazer/operation/inspect.rb +0 -79
  44. data/lib/trailblazer/operation/railway/fast_track.rb +0 -13
  45. data/lib/trailblazer/operation/railway/normalizer.rb +0 -58
  46. data/lib/trailblazer/operation/railway/task_builder.rb +0 -37
  47. data/test/inspect_test.rb +0 -43
  48. data/test/macro_test.rb +0 -60
  49. data/test/task_wrap_test.rb +0 -97
@@ -9,6 +9,7 @@ class DryContainerTest < Minitest::Spec
9
9
  end
10
10
 
11
11
  class Create < Trailblazer::Operation
12
+ extend Trailblazer::Operation::Container
12
13
  end
13
14
 
14
15
  it "allows 2.2 call style" do
@@ -18,7 +19,7 @@ class DryContainerTest < Minitest::Spec
18
19
  it { Create.({}, {}, my_container)["user_repository"].must_equal Object }
19
20
  it { Create.({}, {}, my_container)["contract.create"].must_equal Array }
20
21
  # also allows our own options PLUS containers.
21
- it { Create.({}, { "model" => String }, my_container)["model"].must_equal String }
22
- it { Create.({}, { "model" => String }, my_container)["user_repository"].must_equal Object }
23
- it { Create.({}, { "user_repository" => Fixnum }, my_container)["user_repository"].must_equal Fixnum }
22
+ it { Create.({}, {"model" => String}, my_container)["model"].must_equal String }
23
+ it { Create.({}, {"model" => String}, my_container)["user_repository"].must_equal Object }
24
+ it { Create.({}, {"user_repository" => Integer}, my_container)["user_repository"].must_equal Integer }
24
25
  end
@@ -1,42 +1,25 @@
1
1
  require "test_helper"
2
2
 
3
3
  class FastTrackTest < Minitest::Spec
4
- # #failure fails fast.
5
- # class Create < Trailblazer::Operation
6
- # step ->(options, *) { options["x"] = options["dont_fail"] }
7
- # failure ->(options, *) { options["a"] = true; options["fail_fast"] }, fail_fast: true
8
- # failure ->(options, *) { options["b"] = true }
9
- # step ->(options, *) { options["y"] = true }
10
- # end
11
-
12
- # puts Create["pipetree"].inspect
13
-
14
- # require "trailblazer/diagram/bpmn"
15
- # puts Trailblazer::Diagram::BPMN.to_xml(Create["pipetree"])
16
-
17
- # it { Create.("fail_fast" => true, "dont_fail" => true ).inspect("x", "a", "b", "y").must_equal %{<Result:true [true, nil, nil, true] >} }
18
- # it { Create.("fail_fast" => true ).inspect("x", "a", "b", "y").must_equal %{<Result:false [nil, true, nil, nil] >} }
19
- # it { Create.("fail_fast" => false ).inspect("x", "a", "b", "y").must_equal %{<Result:false [nil, true, nil, nil] >} }
20
-
21
4
  # #success passes fast.
22
5
  class Retrieve < Trailblazer::Operation
23
6
  pass ->(options, **) { options["x"] = options["dont_fail"] }, pass_fast: true
24
7
  fail ->(options, **) { options["b"] = true }
25
8
  step ->(options, **) { options["y"] = true }
26
9
  end
27
- it { Retrieve.("dont_fail" => true ).inspect("x", "b", "y").must_equal %{<Result:true [true, nil, nil] >} }
28
- it { Retrieve.("dont_fail" => false ).inspect("x", "b", "y").must_equal %{<Result:true [false, nil, nil] >} }
10
+ it { Retrieve.("dont_fail" => true).inspect("x", "b", "y").must_equal %{<Result:true [true, nil, nil] >} }
11
+ it { Retrieve.("dont_fail" => false).inspect("x", "b", "y").must_equal %{<Result:true [false, nil, nil] >} }
29
12
 
30
13
  # #step fails fast if option set and returns false.
31
14
  class Update < Trailblazer::Operation
32
15
  step ->(options, *) { options["x"] = true }
33
16
  step ->(options, *) { options["a"] = options["dont_fail"] }, fail_fast: true # only on false.
34
- failure ->(options, *) { options["b"] = true }
17
+ fail ->(options, *) { options["b"] = true }
35
18
  step ->(options, *) { options["y"] = true }
36
19
  end
37
20
 
38
21
  it { Update.("dont_fail" => true).inspect("x", "a", "b", "y").must_equal %{<Result:true [true, true, nil, true] >} }
39
- it { Update.({} ).inspect("x", "a", "b", "y").must_equal %{<Result:false [true, nil, nil, nil] >} }
22
+ it { Update.({}).inspect("x", "a", "b", "y").must_equal %{<Result:false [true, nil, nil, nil] >} }
40
23
 
41
24
  # #step passes fast if option set and returns true.
42
25
  class Delete < Trailblazer::Operation
@@ -47,14 +30,14 @@ class FastTrackTest < Minitest::Spec
47
30
  end
48
31
 
49
32
  it { Delete.("dont_fail" => true).inspect("x", "a", "b", "y").must_equal %{<Result:true [true, true, nil, nil] >} }
50
- it { Delete.({} ).inspect("x", "a", "b", "y").must_equal %{<Result:false [true, nil, true, nil] >} }
33
+ it { Delete.({}).inspect("x", "a", "b", "y").must_equal %{<Result:false [true, nil, true, nil] >} }
51
34
  end
52
35
 
53
36
  class FailBangTest < Minitest::Spec
54
37
  class Create < Trailblazer::Operation
55
38
  step ->(options, *) { options["x"] = true; Railway.fail! }
56
39
  step ->(options, *) { options["y"] = true }
57
- failure ->(options, *) { options["a"] = true }
40
+ fail ->(options, *) { options["a"] = true }
58
41
  end
59
42
 
60
43
  it { Create.().inspect("x", "y", "a").must_equal %{<Result:false [true, nil, true] >} }
@@ -64,7 +47,7 @@ class PassBangTest < Minitest::Spec
64
47
  class Create < Trailblazer::Operation
65
48
  step ->(options, *) { options["x"] = true; Railway.pass! }
66
49
  step ->(options, *) { options["y"] = true }
67
- failure ->(options, *) { options["a"] = true }
50
+ fail ->(options, *) { options["a"] = true }
68
51
  end
69
52
 
70
53
  it { Create.().inspect("x", "y", "a").must_equal %{<Result:true [true, true, nil] >} }
@@ -74,16 +57,16 @@ class FailFastBangTest < Minitest::Spec
74
57
  class Create < Trailblazer::Operation
75
58
  step ->(options, *) { options["x"] = true; Railway.fail_fast! }
76
59
  step ->(options, *) { options["y"] = true }
77
- failure ->(options, *) { options["a"] = true }
60
+ fail ->(options, *) { options["a"] = true }
78
61
  end
79
62
 
80
63
  # without proper configuration, emitting a FastTrack signal is illegal.
81
- it { assert_raises(Trailblazer::Circuit::IllegalSignalError) { Create.().inspect("x", "y", "a").must_equal %{<Result:false [true, nil, nil] >} } }
64
+ it { assert_raises(Trailblazer::Activity::Circuit::IllegalSignalError) { Create.().inspect("x", "y", "a").must_equal %{<Result:false [true, nil, nil] >} } }
82
65
 
83
66
  class Update < Trailblazer::Operation
84
67
  step ->(options, *) { options["x"] = true; Railway.fail_fast! }, fast_track: true
85
68
  step ->(options, *) { options["y"] = true }
86
- failure ->(options, *) { options["a"] = true }
69
+ fail ->(options, *) { options["a"] = true }
87
70
  end
88
71
 
89
72
  it { Update.().inspect("x", "y", "a").must_equal %{<Result:false [true, nil, nil] >} }
@@ -93,7 +76,7 @@ class PassFastBangTest < Minitest::Spec
93
76
  class Create < Trailblazer::Operation
94
77
  step ->(options, *) { options["x"] = true; Railway.pass_fast! }, fast_track: true
95
78
  step ->(options, *) { options["y"] = true }
96
- failure ->(options, *) { options["a"] = true }
79
+ fail ->(options, *) { options["a"] = true }
97
80
  end
98
81
 
99
82
  it { Create.().inspect("x", "y", "a").must_equal %{<Result:true [true, nil, nil] >} }
@@ -103,7 +86,7 @@ end
103
86
  class NestedFastTrackTest < Minitest::Spec
104
87
  #- The ::step DSL method automatically connects the nested's End.fail_fast/End.pass_fast to Update's End.fail_fast/End.pass_fast.
105
88
  #
106
- # Edit has fast-tracked steps, so it has outputs :success/:failure/:pass_fast/:fail_fast.
89
+ # Edit has fast-tracked steps, so it has outputs :success/:fail/:pass_fast/:fail_fast.
107
90
  class Edit < Trailblazer::Operation
108
91
  step :a, fast_track: true # task is connected to End.pass_fast and End.fail_fast.
109
92
 
@@ -115,7 +98,7 @@ class NestedFastTrackTest < Minitest::Spec
115
98
 
116
99
  module Steps
117
100
  def b(options, a:, **)
118
- options["b"] = a+1
101
+ options["b"] = a + 1
119
102
  end
120
103
 
121
104
  def f(options, **)
@@ -126,9 +109,7 @@ class NestedFastTrackTest < Minitest::Spec
126
109
  describe "Nested, fast_track: true and all its outputs given" do
127
110
  let(:update) do
128
111
  Class.new(Trailblazer::Operation) do
129
- step task: Trailblazer::Operation::Callable( Edit, call: :call_with_circuit_interface ), id: "Callable/",
130
- outputs: Edit.outputs ,
131
- fast_track: true
112
+ step Subprocess(Edit), fast_track: true
132
113
  step :b
133
114
  fail :f
134
115
 
@@ -138,7 +119,7 @@ class NestedFastTrackTest < Minitest::Spec
138
119
 
139
120
  # Edit returns End.success
140
121
  it { update.(edit_return: true).inspect("a", "b", "f").must_equal %{<Result:true [1, 2, nil] >} }
141
- # Edit returns End.failure
122
+ # Edit returns End.fail
142
123
  it { update.(edit_return: false).inspect("a", "b", "f").must_equal %{<Result:false [1, nil, 3] >} }
143
124
  # Edit returns End.pass_fast
144
125
  it { update.(edit_return: Trailblazer::Operation::Railway.pass_fast!).inspect("a", "b", "f").must_equal %{<Result:true [1, nil, nil] >} }
@@ -151,8 +132,7 @@ class NestedFastTrackTest < Minitest::Spec
151
132
  Class.new(Trailblazer::Operation) do
152
133
  include Steps
153
134
 
154
- step task: Trailblazer::Operation::Callable( Edit, call: :call_with_circuit_interface ), id: "Callable/",
155
- outputs: Edit.outputs # all outputs given means it "works"
135
+ step Subprocess(Edit), Output(:pass_fast) => Track(:pass_fast), Output(:fail_fast) => Track(:fail_fast)
156
136
  step :b
157
137
  fail :f
158
138
  end
@@ -160,7 +140,7 @@ class NestedFastTrackTest < Minitest::Spec
160
140
 
161
141
  # Edit returns End.success
162
142
  it { update.(edit_return: true).inspect("a", "b", "f").must_equal %{<Result:true [1, 2, nil] >} }
163
- # Edit returns End.failure
143
+ # Edit returns End.fail
164
144
  it { update.(edit_return: false).inspect("a", "b", "f").must_equal %{<Result:false [1, nil, 3] >} }
165
145
  # Edit returns End.pass_fast
166
146
  it { update.(edit_return: Trailblazer::Operation::Railway.pass_fast!).inspect("a", "b", "f").must_equal %{<Result:true [1, nil, nil] >} }
@@ -173,9 +153,10 @@ class NestedFastTrackTest < Minitest::Spec
173
153
  Class.new(Trailblazer::Operation) do
174
154
  include Steps
175
155
 
176
- step({task: Trailblazer::Operation::Callable( Edit, call: :call_with_circuit_interface ), id: "Callable/",
177
- outputs: Edit.outputs },
178
- {Output(:pass_fast) => Track(:success), Output(:fail_fast) => Track(:failure)} )# manually rewire the fast-track outputs to "conventional" railway ends.
156
+ step Subprocess(Edit),
157
+ # manually rewire the fast-track outputs to "conventional" railway ends.
158
+ Output(:pass_fast) => Track(:success),
159
+ Output(:fail_fast) => Track(:failure)
179
160
 
180
161
  step :b
181
162
  fail :f
@@ -183,15 +164,14 @@ class NestedFastTrackTest < Minitest::Spec
183
164
  end
184
165
 
185
166
  # it { puts Trailblazer::Activity::Introspect.Cct(update.instance_variable_get(:@process)) }
186
- it { update.to_h }
167
+ it { update.to_h }
187
168
  # Edit returns End.success
188
169
  it { update.(edit_return: true).inspect("a", "b", "f").must_equal %{<Result:true [1, 2, nil] >} }
189
- # Edit returns End.failure
170
+ # Edit returns End.fail
190
171
  it { update.(edit_return: false).inspect("a", "b", "f").must_equal %{<Result:false [1, nil, 3] >} }
191
172
  # Edit returns End.pass_fast, but behaves like :success.
192
173
  it { update.(edit_return: Trailblazer::Operation::Railway.pass_fast!).inspect("a", "b", "f").must_equal %{<Result:true [1, 2, nil] >} }
193
- # Edit returns End.fail_fast, but behaves like :failure.
174
+ # Edit returns End.fail_fast, but behaves like :fail.
194
175
  it { update.(edit_return: Trailblazer::Operation::Railway.fail_fast!).inspect("a", "b", "f").must_equal %{<Result:false [1, nil, 3] >} }
195
176
  end
196
177
  end
197
-
@@ -5,22 +5,23 @@ class InheritanceTest < Minitest::Spec
5
5
  def self.find_by(options); options[:id].nil? ? nil : new(options[:id]) end
6
6
  end
7
7
 
8
- class Create < Trailblazer::Operation
9
- self["a"] = "A"
10
- self["b"] = "B"
11
- self["c"] = "D"
8
+ # class Create < Trailblazer::Operation
9
+ # self["a"] = "A"
10
+ # self["b"] = "B"
11
+ # self["c"] = "D"
12
12
 
13
- def self.class(*skills)
14
- Class.new(Trailblazer::Operation). tap do |klass|
15
- skills.each { |skill| klass.heritage.record(:[]=, skill, self[skill]) }
16
- end
17
- end
18
- end
13
+ # def self.class(*skills)
14
+ # Class.new(Trailblazer::Operation). tap do |klass|
15
+ # skills.each { |skill| klass.heritage.record(:[]=, skill, self[skill]) }
16
+ # end
17
+ # end
18
+ # end
19
19
 
20
- class Update < Create.class("a", "b")
21
- end
20
+ # class Update < Create.class("a", "b")
21
+ # end
22
22
 
23
23
  it do
24
+ skip "https://trello.com/c/t8bUJlqb/25-op-class-dependencies"
24
25
  Update["a"].must_equal "A"
25
26
  Update["b"].must_equal "B"
26
27
  Update["c"].must_be_nil
@@ -1,10 +1,10 @@
1
1
  require "test_helper"
2
2
 
3
3
  class IntrospectTest < Minitest::Spec
4
- A = ->(*args) { [ Activity::Right, *args ] }
5
- B = ->(*args) { [ Activity::Right, *args ] }
6
- C = ->(*args) { [ Activity::Right, *args ] }
7
- D = ->(*args) { [ Activity::Right, *args ] }
4
+ A = ->(*args) { [Activity::Right, *args] }
5
+ B = ->(*args) { [Activity::Right, *args] }
6
+ C = ->(*args) { [Activity::Right, *args] }
7
+ D = ->(*args) { [Activity::Right, *args] }
8
8
 
9
9
  let(:activity) do
10
10
  nested = bc
@@ -26,7 +26,7 @@ class IntrospectTest < Minitest::Spec
26
26
  describe "#collect" do
27
27
  it "iterates over each task element in the top activity" do
28
28
  skip
29
- all_tasks = Activity::Introspect.collect(activity) do |task, connections|
29
+ all_tasks = Activity::Introspect.collect(activity) do |task, _connections|
30
30
  task
31
31
  end
32
32
 
@@ -39,7 +39,7 @@ class IntrospectTest < Minitest::Spec
39
39
 
40
40
  it "iterates over all task elements recursively" do
41
41
  skip
42
- all_tasks = Activity::Introspect.collect(activity, recursive: true) do |task, connections|
42
+ all_tasks = Activity::Introspect.collect(activity, recursive: true) do |task, _connections|
43
43
  task
44
44
  end
45
45
 
@@ -13,7 +13,14 @@ class DeclarativeApiTest < Minitest::Spec
13
13
  fail :return_true!
14
14
  fail :return_false!
15
15
 
16
- def decide!(options, decide:raise, **)
16
+ step :bla, input: ->(ctx, *) { {id: ctx.inspect} }, output: ->(scope, ctx) { ctx["hello"] = scope["1"]; ctx }
17
+
18
+ def bla(ctx, id:1, **)
19
+ puts id
20
+ true
21
+ end
22
+
23
+ def decide!(options, decide: raise, **)
17
24
  options["a"] = true
18
25
  decide
19
26
  end
@@ -26,18 +33,19 @@ class DeclarativeApiTest < Minitest::Spec
26
33
  options["x"] = true
27
34
  end
28
35
 
29
- def return_true! (options, **); options["b"] = true end
36
+ def return_true!(options, **); options["b"] = true end
37
+
30
38
  def return_false!(options, **); options["c"] = false end
31
39
  end
32
40
 
33
41
  it { Create.(decide: true).inspect("a", "x", "y", "b", "c").must_equal %{<Result:true [true, true, false, nil, nil] >} }
34
42
  it { Create.(decide: false).inspect("a", "x", "y", "b", "c").must_equal %{<Result:false [true, nil, nil, true, false] >} }
35
-
43
+ it { Create.(decide: nil).keys.must_equal(%i(decide a b c)) }
44
+ it { Create.(decide: nil).to_hash.must_equal(decide: nil, a: true, b: true, c: false) }
36
45
  #---
37
46
  #- trace
38
47
 
39
48
  it do
40
-
41
49
  end
42
50
 
43
51
  #---
@@ -46,14 +54,16 @@ class DeclarativeApiTest < Minitest::Spec
46
54
  end
47
55
 
48
56
  it { Noop.().inspect("params").must_equal %{<Result:true [nil] >} }
57
+ it { Noop.().keys.must_equal([]) }
58
+ it { Noop.().to_hash.must_equal({}) }
49
59
 
50
60
  #---
51
61
  #- pass
52
62
  #- fail
53
63
  class Update < Trailblazer::Operation
54
- pass ->(options, **) { options["a"] = false }
55
- step ->(options, params:raise, **) { options["b"] = params[:decide] }
56
- fail ->(options, **) { options["c"] = true }
64
+ pass ->(options, **) { options["a"] = false }
65
+ step ->(options, params: raise, **) { options["b"] = params[:decide] }
66
+ fail ->(options, **) { options["c"] = true }
57
67
  end
58
68
 
59
69
  it { Update.("params" => {decide: true}).inspect("a", "b", "c").must_equal %{<Result:true [false, true, nil] >} }
@@ -73,22 +83,4 @@ class DeclarativeApiTest < Minitest::Spec
73
83
  Upsert.("params" => {decide: true}).inspect("a", "b", "c", "d", "e").must_equal %{<Result:true [false, true, nil, 1, nil] >}
74
84
  Unset. ("params" => {decide: true}).inspect("a", "b", "c", "d", "e").must_equal %{<Result:true [false, true, nil, 1, 2] >}
75
85
  end
76
-
77
- describe "Activity::Interface" do
78
- class Edit < Trailblazer::Operation
79
- step :a
80
- step :b, fast_track: true
81
- end
82
-
83
- it "provides #outputs" do
84
- Activity::Introspect.Outputs(Edit.outputs).must_equal %{success=> (#<Trailblazer::Operation::Railway::End::Success semantic=:success>, success)
85
- failure=> (#<Trailblazer::Operation::Railway::End::Failure semantic=:failure>, failure)
86
- pass_fast=> (#<Trailblazer::Operation::Railway::End::PassFast semantic=:pass_fast>, pass_fast)
87
- fail_fast=> (#<Trailblazer::Operation::Railway::End::FailFast semantic=:fail_fast>, fail_fast)}
88
- end
89
-
90
- it "is an Interface" do
91
- Edit.is_a?( Activity::Interface ).must_equal true
92
- end
93
- end
94
86
  end
@@ -1,11 +1,11 @@
1
- require "test_helper"
1
+ require "test_helper"
2
2
 
3
3
  class RailwayResultTest < Minitest::Spec
4
4
  Result = Trailblazer::Operation::Railway::Result
5
5
  Success = Trailblazer::Operation::Railway::End::Success
6
6
 
7
7
  let(:event) { Success.new(semantic: nil) }
8
- let (:success) { Result.new(true, { "x"=> String }, event) }
8
+ let(:success) { Result.new(true, {"x" => String}, event) }
9
9
 
10
10
  it { success.success?.must_equal true }
11
11
  it { success.failure?.must_equal false }
@@ -20,10 +20,10 @@ class RailwayResultTest < Minitest::Spec
20
20
  #---
21
21
  # inspect
22
22
  it { success.inspect.must_equal %{<Result:true {\"x\"=>String} >} }
23
- it { Result.new(true, { "x"=> true, "y"=>1, "z"=>2 }, event).inspect("z", "y").must_equal %{<Result:true [2, 1] >} }
23
+ it { Result.new(true, {"x" => true, "y" => 1, "z" => 2}, event).inspect("z", "y").must_equal %{<Result:true [2, 1] >} }
24
24
 
25
25
  class Create < Trailblazer::Operation
26
- success :call
26
+ pass :call
27
27
 
28
28
  def call(options, **)
29
29
  options[:message] = "Result objects are actually quite handy!"
@@ -13,21 +13,22 @@ class DeclarativeApiTest < Minitest::Spec
13
13
  failure :return_true!
14
14
  failure :return_false!
15
15
 
16
- def decide!(options, decide:raise, **o)
16
+ def decide!(options, decide: raise, **_o)
17
17
  options["a"] = true
18
18
  decide
19
19
  end
20
20
 
21
- def wasnt_ok!(options, **o)
21
+ def wasnt_ok!(options, **_o)
22
22
  options["y"] = false
23
23
  end
24
24
 
25
- def was_ok!(options, **o)
25
+ def was_ok!(options, **_o)
26
26
  options["x"] = true
27
27
  end
28
28
 
29
- def return_true! (options, **o); options["b"] = true end
30
- def return_false!(options, **o); options["c"] = false end
29
+ def return_true!(options, **_o); options["b"] = true end
30
+
31
+ def return_false!(options, **_o); options["c"] = false end
31
32
  end
32
33
 
33
34
  it { Create.({}, decide: true).inspect("a", "x", "y", "b", "c").must_equal %{<Result:true [true, true, false, nil, nil] >} }
@@ -37,7 +38,6 @@ class DeclarativeApiTest < Minitest::Spec
37
38
  #- trace
38
39
 
39
40
  it do
40
-
41
41
  end
42
42
 
43
43
  #---
@@ -51,9 +51,9 @@ class DeclarativeApiTest < Minitest::Spec
51
51
  #- pass
52
52
  #- fail
53
53
  class Update < Trailblazer::Operation
54
- pass ->(options, **o) { options["a"] = false }
55
- step ->(options, params:raise, **o) { options["b"] = params[:decide] }
56
- fail ->(options, **o) { options["c"] = true }
54
+ pass ->(options, **_o) { options["a"] = false }
55
+ step ->(options, params: raise, **_o) { options["b"] = params[:decide] }
56
+ fail ->(options, **_o) { options["c"] = true }
57
57
  end
58
58
 
59
59
  it { Update.(decide: true).inspect("a", "b", "c").must_equal %{<Result:true [false, true, nil] >} }
@@ -7,32 +7,33 @@ require "test_helper"
7
7
  # --- step MyMacro
8
8
  class StepTest < Minitest::Spec
9
9
  class Callable
10
- def self.call(options, b:nil, **o)
10
+ def self.call(options, b: nil, **_o)
11
11
  options["b"] = b
12
12
  end
13
13
  end
14
14
 
15
15
  module Implementation
16
16
  module_function
17
- def c(options, c:nil, **o)
17
+
18
+ def c(options, c: nil, **_o)
18
19
  options["c"] = c
19
20
  end
20
21
  end
21
22
 
22
- MyMacro = ->( direction, options, flow_options ) do
23
+ MyMacro = ->(direction, options, flow_options) do
23
24
  options["e"] = options[:e]
24
25
 
25
- [ direction, options, flow_options ]
26
+ [direction, options, flow_options]
26
27
  end
27
28
 
28
29
  class Create < Trailblazer::Operation
29
- step ->(options, a:nil, **o) { options["a"] = a }
30
+ step ->(options, a: nil, **_o) { options["a"] = a }
30
31
  step Callable
31
32
  step Implementation.method(:c)
32
33
  step :d
33
- step [ MyMacro, {} ] # doesn't provide runner_options.
34
+ step [MyMacro, {}] # doesn't provide runner_options.
34
35
 
35
- def d(options, d:nil, **o)
36
+ def d(options, d: nil, **_o)
36
37
  options["d"] = d
37
38
  end
38
39
  end
@@ -47,8 +48,8 @@ class StepTest < Minitest::Spec
47
48
  #- :before, :after, :replace, :delete, :override
48
49
  class A < Trailblazer::Operation
49
50
  step :a!
50
- def a!(options, **o); options["a"] = 1; end
51
- def a!(options, **o); options["a"] = 1; end if RUBY_VERSION == "2.0.0"
51
+ def a!(options, **_o); options["a"] = 1; end
52
+ def a!(options, **_o); options["a"] = 1; end if RUBY_VERSION == "2.0.0"
52
53
  end
53
54
 
54
55
  class B < A
@@ -76,7 +77,7 @@ class StepTest < Minitest::Spec
76
77
 
77
78
  # not existent :name
78
79
  it do
79
- err = assert_raises Trailblazer::Operation::Railway::Sequence::IndexError do
80
+ err = assert_raises Trailblazer::Operation::Railway::Sequence::IndexError do
80
81
  class E < Trailblazer::Operation
81
82
  step :a, before: "I don't exist!"
82
83
  end
@@ -91,8 +92,8 @@ class StepTest < Minitest::Spec
91
92
  class Index < Trailblazer::Operation
92
93
  step :validate!, name: "my validate"
93
94
  step :persist!
94
- step [ MyMacro, name: "I win!" ]
95
- step [ MyMacro, name: "I win!" ], name: "No, I do!"
95
+ step [MyMacro, name: "I win!"]
96
+ step [MyMacro, name: "I win!"], name: "No, I do!"
96
97
  end
97
98
 
98
99
  it { Trailblazer::Operation::Inspect.(Index).must_equal %{[>my validate,>persist!,>I win!,>No, I do!]} }
@@ -114,7 +115,8 @@ end
114
115
  #---
115
116
  #- Macros with the old `input` arg.
116
117
  # step [ ->(input, options) { } ]
117
- class StepWithDeprecatedMacroTest < Minitest::Spec # TODO: remove me in 2.2.
118
+ # TODO: remove me in 2.2.
119
+ class StepWithDeprecatedMacroTest < Minitest::Spec
118
120
  class Create < Trailblazer::Operation
119
121
  MyOutdatedMacro = ->(input, options) {
120
122
  options["x"] = input.class
@@ -126,11 +128,10 @@ class StepWithDeprecatedMacroTest < Minitest::Spec # TODO: remove me in 2.2.
126
128
  end
127
129
  end
128
130
 
129
- step [ MyOutdatedMacro, name: :outdated ]
130
- step [ AnotherOldMacro, name: :oldie ]
131
+ step [MyOutdatedMacro, name: :outdated]
132
+ step [AnotherOldMacro, name: :oldie]
131
133
  end
132
134
 
133
135
  it { Trailblazer::Operation::Inspect.(Create).gsub(/0x.+?step_test.rb/, "").must_equal %{[>outdated,>oldie]} }
134
136
  it { Create.().inspect("x", "y").must_equal %{<Result:true [StepWithDeprecatedMacroTest::Create, StepWithDeprecatedMacroTest::Create] >} }
135
137
  end
136
-