Implement verbose mode

This commit is contained in:
Thibault Jouan
2014-05-19 22:22:42 +00:00
parent 2b86bbf112
commit 8291f1bcfd
16 changed files with 183 additions and 20 deletions

View File

@@ -3,5 +3,13 @@ require 'spec_helper'
module Producer::Core
describe Action do
it_behaves_like 'action'
describe '#name' do
subject(:action) { described_class.new(double 'env') }
it 'infers action name from class name' do
expect(action.name).to eq 'action'
end
end
end
end

View File

@@ -12,23 +12,34 @@ module Producer::Core
subject(:cli) { CLI.new(arguments, stdout: stdout) }
describe '.run!' do
let(:cli) { double('cli').as_null_object }
let(:output) { StringIO.new }
subject(:run) { described_class.run! arguments, output: output }
it 'builds a new CLI with given arguments' do
expect(CLI).to receive(:new).with(arguments).and_call_original
expect(described_class)
.to receive(:new).with(arguments).and_call_original
run
end
it 'runs the CLI' do
cli = double 'cli'
allow(CLI).to receive(:new) { cli }
allow(described_class).to receive(:new) { cli }
expect(cli).to receive :run
run
end
context 'when recipe argument is missing' do
let(:arguments) { [] }
it 'parses CLI arguments' do
allow(described_class).to receive(:new) { cli }
expect(cli).to receive :parse_arguments!
run
end
context 'when an argument error is raised' do
before do
allow(CLI).to receive(:new) { cli }
allow(cli).to receive(:parse_arguments!)
.and_raise described_class::ArgumentError
end
it 'exits with a return status of 64' do
expect { run }.to raise_error(SystemExit) { |e|
@@ -55,14 +66,6 @@ module Producer::Core
expect(cli.stdout).to be $stdout
end
end
context 'without arguments' do
let(:arguments) { [] }
it 'raises our ArgumentError exception' do
expect { cli }.to raise_error described_class::ArgumentError
end
end
end
describe '#arguments' do
@@ -77,6 +80,32 @@ module Producer::Core
end
end
describe '#parse_arguments!' do
context 'with options' do
let(:arguments) { ['-v', recipe_file] }
before { cli.parse_arguments! }
it 'removes options from arguments' do
expect(cli.arguments).to eq [recipe_file]
end
context 'verbose' do
it 'sets env logger level to INFO' do
expect(cli.env.log_level).to eq Logger::INFO
end
end
end
context 'without arguments' do
let(:arguments) { [] }
it 'raises the argument error exception' do
expect { cli.parse_arguments! }.to raise_error described_class::ArgumentError
end
end
end
describe '#run' do
it 'loads the recipe' do
cli.run

View File

@@ -2,7 +2,7 @@ require 'spec_helper'
module Producer::Core
describe Worker do
let(:env) { Env.new }
let(:env) { double 'env', log: nil }
subject(:worker) { described_class.new(env) }
describe '#process' do
@@ -13,23 +13,44 @@ module Producer::Core
end
describe '#process_task' do
let(:action) { double 'action' }
let(:task) { double('task', actions: [action]).as_null_object }
let(:action) { double('action', to_s: 'echo').as_null_object }
let(:task_name) { 'some_task' }
let(:task) { Task.new(task_name, [action]) }
it 'logs task info' do
expect(env).to receive(:log).with /\ATask: #{task_name}/
worker.process_task task
end
context 'when task condition is met' do
it 'applies the actions' do
expect(action).to receive :apply
worker.process_task task
end
it 'logs condition info' do
expect(env).to receive(:log).with(' condition: met')
worker.process_task task
end
it 'logs action info' do
expect(env).to receive(:log).with /\A action: echo/
worker.process_task task
end
end
context 'when task condition is not met' do
before { allow(task).to receive(:condition_met?) { false } }
let(:task) { Task.new(task_name, [action], false) }
it 'does not apply the actions' do
expect(action).not_to receive :apply
worker.process_task task
end
it 'logs condition info' do
expect(env).to receive(:log).with(' condition: NOT met')
worker.process_task task
end
end
end

View File

@@ -40,5 +40,17 @@ module Producer::Core
expect(action.fs).to be env.remote.fs
end
end
describe '#name' do
it 'returns a word' do
expect(action.name).to match /\A\w+\z/
end
end
describe '#to_s' do
it 'returns a word' do
expect(action.to_s).to eq action.name
end
end
end
end