test/docs/wrap_test.rb in trailblazer-macro-2.1.15 vs test/docs/wrap_test.rb in trailblazer-macro-2.1.16

- old
+ new

@@ -202,12 +202,12 @@ include T.def_steps(:model, :update, :notify, :log_error) include Rehash #~methods end end - it { Memo::Create.( { seq: [] } ).inspect(:seq).must_equal %{<Result:true [[:model, :update, :rehash, :notify]] >} } - it { Memo::Create.( { seq: [], rehash_raise: RuntimeError } ).inspect(:seq).must_equal %{<Result:false [[:model, :update, :rehash]] >} } + it { assert_equal Memo::Create.( { seq: [] } ).inspect(:seq), %{<Result:true [[:model, :update, :rehash, :notify]] >} } + it { assert_equal Memo::Create.( { seq: [], rehash_raise: RuntimeError } ).inspect(:seq), %{<Result:false [[:model, :update, :rehash]] >} } end =begin When success: return the block's returns When raise: return {Railway.fail_fast!} and configure Wrap() to {fast_track: true} @@ -239,12 +239,12 @@ include Rehash #~methods end end #:fail-fast end - it { Memo::Create.( { seq: [] } ).inspect(:seq).must_equal %{<Result:true [[:model, :update, :rehash, :notify]] >} } - it { Memo::Create.( { seq: [], rehash_raise: RuntimeError } ).inspect(:seq).must_equal %{<Result:false [[:model, :update, :rehash]] >} } + it { assert_equal Memo::Create.( { seq: [] } ).inspect(:seq), %{<Result:true [[:model, :update, :rehash, :notify]] >} } + it { assert_equal Memo::Create.( { seq: [], rehash_raise: RuntimeError } ).inspect(:seq), %{<Result:false [[:model, :update, :rehash]] >} } end =begin When success: return the block's returns When raise: return {Railway.fail!} or {Railway.pass!} @@ -282,18 +282,20 @@ end #:custom end it do result = Memo::Create.( { seq: [] } ) - result.inspect(:seq).must_equal %{<Result:false [[:model, :update, :rehash]] >} - result.event.inspect.must_equal %{#<Trailblazer::Activity::End semantic=:transaction_worked>} + + assert_equal result.inspect(:seq), %{<Result:false [[:model, :update, :rehash]] >} + assert_equal result.event.inspect, %{#<Trailblazer::Activity::End semantic=:transaction_worked>} end it do result = Memo::Create.( { seq: [], rehash_raise: RuntimeError } ) - result.inspect(:seq).must_equal %{<Result:false [[:model, :update, :rehash]] >} - result.event.inspect.must_equal %{#<Trailblazer::Activity::End semantic=:transaction_failed>} + + assert_equal result.inspect(:seq), %{<Result:false [[:model, :update, :rehash]] >} + assert_equal result.event.inspect, %{#<Trailblazer::Activity::End semantic=:transaction_failed>} end end =begin When success: return the block's returns @@ -323,12 +325,12 @@ include T.def_steps(:model, :update, :notify, :log_error) include Rehash #~methods end end - it { Memo::Create.( { seq: [] } ).inspect(:seq).must_equal %{<Result:true [[:model, :update, :rehash, :notify]] >} } - it { Memo::Create.( { seq: [], rehash_raise: RuntimeError } ).inspect(:seq).must_equal %{<Result:true [[:model, :update, :rehash, :notify]] >} } + it { assert_equal Memo::Create.( { seq: [] } ).inspect(:seq), %{<Result:true [[:model, :update, :rehash, :notify]] >} } + it { assert_equal Memo::Create.( { seq: [], rehash_raise: RuntimeError } ).inspect(:seq), %{<Result:true [[:model, :update, :rehash, :notify]] >} } end =begin When success: return the block's returns When raise: return {true} and go "successful" @@ -360,12 +362,13 @@ #~methods end end it "translates true returned form a wrap to a signal with a `success` semantic" do result = Memo::Create.( { seq: [], rehash_raise: RuntimeError } ) - result.inspect(:seq).must_equal %{<Result:true [[:model, :update, :rehash, :notify]] >} - result.event.inspect.must_equal %{#<Trailblazer::Activity::Railway::End::Success semantic=:success>} + + assert_equal result.inspect(:seq), %{<Result:true [[:model, :update, :rehash, :notify]] >} + assert_equal result.event.inspect, %{#<Trailblazer::Activity::Railway::End::Success semantic=:success>} end end =begin When success: return the block's returns @@ -398,12 +401,13 @@ #~methods end end it "translates false returned form a wrap to a signal with a `failure` semantic" do result = Memo::Create.( { seq: [], rehash_raise: RuntimeError } ) - result.inspect(:seq).must_equal %{<Result:false [[:model, :update, :rehash, :log_error]] >} - result.event.inspect.must_equal %{#<Trailblazer::Activity::Railway::End::Failure semantic=:failure>} + + assert_equal result.inspect(:seq), %{<Result:false [[:model, :update, :rehash, :log_error]] >} + assert_equal result.event.inspect, %{#<Trailblazer::Activity::Railway::End::Failure semantic=:failure>} end end =begin When success: return the block's returns @@ -436,12 +440,13 @@ #~methods end end it "translates nil returned form a wrap to a signal with a `failure` semantic" do result = Memo::Create.( { seq: [], rehash_raise: RuntimeError } ) - result.inspect(:seq).must_equal %{<Result:false [[:model, :update, :rehash, :log_error]] >} - result.event.inspect.must_equal %{#<Trailblazer::Activity::Railway::End::Failure semantic=:failure>} + + assert_equal result.inspect(:seq), %{<Result:false [[:model, :update, :rehash, :log_error]] >} + assert_equal result.event.inspect, %{#<Trailblazer::Activity::Railway::End::Failure semantic=:failure>} end end =begin When success: return the block's returns @@ -451,11 +456,11 @@ class WrapWithTransactionTest < Minitest::Spec Memo = Module.new module Sequel def self.transaction - end_event, (ctx, flow_options) = yield + _end_event, (_ctx, _flow_options) = yield end end #:transaction-handler class MyTransaction @@ -481,12 +486,12 @@ include Rehash #~methods end end #:transaction end - it { Memo::Create.( { seq: [] } ).inspect(:seq).must_equal %{<Result:true [[:model, :update, :rehash, :notify]] >} } - it { Memo::Create.( { seq: [], rehash_raise: RuntimeError } ).inspect(:seq).must_equal %{<Result:false [[:model, :update, :rehash, :log_error]] >} } + it { assert_equal Memo::Create.( { seq: [] } ).inspect(:seq), %{<Result:true [[:model, :update, :rehash, :notify]] >} } + it { assert_equal Memo::Create.( { seq: [], rehash_raise: RuntimeError } ).inspect(:seq), %{<Result:false [[:model, :update, :rehash, :log_error]] >} } end =begin When success: return {Railway.pass_fast!} When failure: return {Railway.fail!} @@ -521,12 +526,12 @@ include T.def_steps(:model, :update, :notify, :log_error) #~methods end end #:transaction end - it { Memo::Create.( { seq: [] } ).inspect(:seq).must_equal %{<Result:true [[:model, :update]] >} } - it { Memo::Create.( { seq: [], update: false } ).inspect(:seq).must_equal %{<Result:false [[:model, :update, :log_error]] >} } + it { assert_equal Memo::Create.( { seq: [] } ).inspect(:seq), %{<Result:true [[:model, :update]] >} } + it { assert_equal Memo::Create.( { seq: [], update: false } ).inspect(:seq), %{<Result:false [[:model, :update, :log_error]] >} } end class WrapOperationWithCustomTerminus < Minitest::Spec Song = Module.new @@ -659,9 +664,22 @@ #@ the original activity with Wrap is unchanged. assert_invoke activity, seq: %{[:validate]} #@ the patched version only runs {mock_validation}. assert_invoke patched_activity, seq: %{[:mock_validation]} + + # Patch Wrap/Subprocess/step, put step after {validate} + patched_activity = Trailblazer::Activity::DSL::Linear::Patch.call( + activity, + ["Wrap/WrapUnitTest::HandleUnsafeProcess", :validation], + -> { step mock_validation } + ) + + #@ the original activity with Wrap is unchanged. + assert_invoke activity, seq: %{[:validate]} + + #@ the patched version only runs {mock_validation}. + assert_invoke patched_activity, seq: %{[:validate, :mock_validation]} end end class WrapStrategyComplianceTest < Minitest::Spec Song = WrapSimpleHandlerTest::Song