File tree Expand file tree Collapse file tree 4 files changed +20
-10
lines changed Expand file tree Collapse file tree 4 files changed +20
-10
lines changed Original file line number Diff line number Diff line change @@ -18,8 +18,7 @@ def initialize(*)
1818 def true? ( context , input )
1919 lhs = variable_value ( context , input )
2020 rhs = compare_value ( context , input )
21-
22- validate! ( lhs )
21+ return false unless valid? ( lhs )
2322
2423 case compare_key
2524 when "IsNull" then is_null? ( lhs )
@@ -58,8 +57,8 @@ def true?(context, input)
5857
5958 private
6059
61- def validate! ( value )
62- raise "No such variable [ #{ variable } ]" if value . nil? && ! %w[ IsNull IsPresent ] . include? ( compare_key )
60+ def valid? ( value )
61+ ! value . nil? || %w[ IsNull IsPresent ] . include? ( compare_key )
6362 end
6463
6564 def is_null? ( value ) # rubocop:disable Naming/PredicateName
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ def finish
2323 next_state = choices . detect { |choice | choice . true? ( context , output ) } &.next || default
2424
2525 context . next_state = next_state
26- context . output = output
26+ context . output = next_state . nil? ? { "Error" => "States.NoChoiceMatched" } : output
2727 super
2828 end
2929
Original file line number Diff line number Diff line change 7979 let ( :input ) { { } }
8080
8181 it "raises an exception" do
82- expect { subject } . to raise_exception ( RuntimeError , "No such variable [$.foo]" )
82+ expect ( subject ) . to eq ( false )
8383 end
8484 end
8585
Original file line number Diff line number Diff line change 22 let ( :input ) { { } }
33 let ( :ctx ) { Floe ::Workflow ::Context . new ( :input => input ) }
44 let ( :state ) { workflow . current_state }
5+ let ( :use_default ) { true }
56 let ( :workflow ) do
67 make_workflow (
78 ctx , {
1920 "Next" => "SecondMatchState"
2021 } ,
2122 ] ,
22- "Default" => "DefaultState"
23+ "Default" => ( use_default ? "DefaultState" : nil )
2324 } ,
2425 "FirstMatchState" => { "Type" => "Succeed" } ,
2526 "SecondMatchState" => { "Type" => "Succeed" } ,
5354 end
5455
5556 describe "#run_nonblock!" do
56- context "with a missing variable" do
57- it "raises an exception" do
58- expect { state . run_nonblock! } . to raise_error ( RuntimeError , "No such variable [$.foo]" )
57+ context "with a missing variable and no default" do
58+ let ( :use_default ) { false }
59+ it "returns an error" do
60+ state . run_nonblock!
61+ expect ( ctx . next_state ) . to be_nil
62+ expect ( ctx . output ) . to eq ( { "Error" => "States.NoChoiceMatched" } )
63+ end
64+ end
65+
66+ context "with a missing variable and a default" do
67+ it "uses the default" do
68+ state . run_nonblock!
69+ expect ( ctx . next_state ) . to eq ( "DefaultState" )
5970 end
6071 end
6172
You can’t perform that action at this time.
0 commit comments