diff --git a/lib/trailblazer/rails/controller.rb b/lib/trailblazer/rails/controller.rb index b29d090..d694338 100644 --- a/lib/trailblazer/rails/controller.rb +++ b/lib/trailblazer/rails/controller.rb @@ -3,7 +3,7 @@ module Controller # TODO: deprecate {*dependencies}. def run_v21(operation, *dependencies, **variables, &block) result = if Rails.application.config.trailblazer.enable_tracing - _run_operation_v21(operation, :trace, *dependencies, **variables).tap { |r| _operation_trace(r) } + _run_operation_v21(operation, :wtf?, *dependencies, **variables) else _run_operation_v21(operation, :call, *dependencies, **variables) end @@ -53,10 +53,6 @@ def _run_operation_v21(operation, call_method, *dependencies, **variables) ) end - def _operation_trace(result) - puts result.wtf? - end - def _assign_trb_ivars(result) @model = result[:model] @form = _wrap_with_trb_form(result["contract.default"], @model.class) diff --git a/test/integration/songs_controller_test.rb b/test/integration/songs_controller_test.rb index 72b8c0c..1942194 100644 --- a/test/integration/songs_controller_test.rb +++ b/test/integration/songs_controller_test.rb @@ -2,6 +2,22 @@ require 'minitest/capybara' class SongsControllerTest < Minitest::Capybara::Spec + it 'can trace' do + # Capture the standard output + stdout = StringIO.new + original_stdout = $stdout + $stdout = stdout + Rails.application.config.trailblazer.enable_tracing = true + visit "/songs/new" + # Assert that the output contains the expected string + assert_equal "Song::Operation::New\n|-- \e[32mStart.default\e[0m\n|-- \e[32mmodel.build\e[0m\n|-- \e[32mcontract.build\e[0m\n`-- End.success\n", + stdout.string + + ensure + $stdout = original_stdout + Rails.application.config.trailblazer.enable_tracing = false + end + it "new" do visit "/songs/new" assert page.has_css? "form.new_song[action='/songs']"