diff --git a/features/cli_verbose.feature b/features/cli_verbose.feature index 261edd6..ab3cd26 100644 --- a/features/cli_verbose.feature +++ b/features/cli_verbose.feature @@ -16,8 +16,8 @@ Feature: CLI verbose option Scenario: prints tasks name When I successfully execute the recipe with option -v - Then the output must match /^Task:.+`task_ok'/ - And the output must match /^Task:.+`task_ko'/ + Then the output must match /Task:.+`task_ok'/ + And the output must match /Task:.+`task_ko'/ Scenario: appends `applying' or `skipped' after tasks name When I successfully execute the recipe with option -v @@ -28,6 +28,16 @@ Feature: CLI verbose option When I successfully execute the recipe with option -v Then the output must match /^ action: echo/ - Scenario: formats message with our simple logger + Scenario: prints actions arguments When I successfully execute the recipe with option -v - Then the output must match /\ATask:/ + Then the output must match /echo \["some message"\]/ + + Scenario: summarizes printed actions arguments + Given a recipe with: + """ + task :some_task do + echo 'long message ' * 32 + end + """ + When I successfully execute the recipe with option -v + Then the output must match /action: .{,70}$/ diff --git a/lib/producer/core/action.rb b/lib/producer/core/action.rb index f8167c8..af2f59b 100644 --- a/lib/producer/core/action.rb +++ b/lib/producer/core/action.rb @@ -1,6 +1,8 @@ module Producer module Core class Action + INSPECT_ARGUMENTS_SUM_LEN = 68.freeze + extend Forwardable def_delegators :@env, :input, :output, :error_output, :remote def_delegators :remote, :fs @@ -17,7 +19,14 @@ module Producer end def to_s - name + [name, inspect_arguments].join ' ' + end + + + private + + def inspect_arguments + @arguments.inspect[0, INSPECT_ARGUMENTS_SUM_LEN - name.length] end end end diff --git a/lib/producer/core/worker.rb b/lib/producer/core/worker.rb index dfcc374..62c6869 100644 --- a/lib/producer/core/worker.rb +++ b/lib/producer/core/worker.rb @@ -20,7 +20,7 @@ module Producer if task.condition_met? env.log "Task: `#{task}' applying..." task.actions.each do |e| - env.log " action: #{e} applying" + env.log " action: #{e}" e.apply unless env.dry_run? end else diff --git a/spec/support/shared_action.rb b/spec/support/shared_action.rb index be65106..f8d2577 100644 --- a/spec/support/shared_action.rb +++ b/spec/support/shared_action.rb @@ -54,8 +54,20 @@ module Producer::Core end describe '#to_s' do - it 'returns a word' do - expect(action.to_s).to eq action.name + it 'includes action name' do + expect(action.to_s).to match /\A#{action.name}/ + end + + it 'includes arguments inspection' do + expect(action.to_s).to match /#{Regexp.quote(arguments.inspect)}\z/ + end + + context 'when arguments inspection is very long' do + let(:arguments) { [:some, :arguments] * 32 } + + it 'summarizes arguments inspection' do + expect(action.to_s.length).to be < 70 + end end end end