Implement action arguments logging

This commit is contained in:
Thibault Jouan 2014-09-17 00:22:05 +00:00
parent 3cb195c9a0
commit 563bf9cccf
4 changed files with 39 additions and 8 deletions

View File

@ -16,8 +16,8 @@ Feature: CLI verbose option
Scenario: prints tasks name Scenario: prints tasks name
When I successfully execute the recipe with option -v When I successfully execute the recipe with option -v
Then the output must match /^Task:.+`task_ok'/ Then the output must match /Task:.+`task_ok'/
And the output must match /^Task:.+`task_ko'/ And the output must match /Task:.+`task_ko'/
Scenario: appends `applying' or `skipped' after tasks name Scenario: appends `applying' or `skipped' after tasks name
When I successfully execute the recipe with option -v 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 When I successfully execute the recipe with option -v
Then the output must match /^ action: echo/ 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 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}$/

View File

@ -1,6 +1,8 @@
module Producer module Producer
module Core module Core
class Action class Action
INSPECT_ARGUMENTS_SUM_LEN = 68.freeze
extend Forwardable extend Forwardable
def_delegators :@env, :input, :output, :error_output, :remote def_delegators :@env, :input, :output, :error_output, :remote
def_delegators :remote, :fs def_delegators :remote, :fs
@ -17,7 +19,14 @@ module Producer
end end
def to_s 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 end
end end

View File

@ -20,7 +20,7 @@ module Producer
if task.condition_met? if task.condition_met?
env.log "Task: `#{task}' applying..." env.log "Task: `#{task}' applying..."
task.actions.each do |e| task.actions.each do |e|
env.log " action: #{e} applying" env.log " action: #{e}"
e.apply unless env.dry_run? e.apply unless env.dry_run?
end end
else else

View File

@ -54,8 +54,20 @@ module Producer::Core
end end
describe '#to_s' do describe '#to_s' do
it 'returns a word' do it 'includes action name' do
expect(action.to_s).to eq action.name 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 end
end end