Implement dry run mode
This commit is contained in:
@@ -6,7 +6,8 @@ module Producer::Core
|
||||
include FixturesHelpers
|
||||
|
||||
let(:recipe_file) { fixture_path_for 'recipes/some_recipe.rb' }
|
||||
let(:arguments) { [recipe_file] }
|
||||
let(:options) { [] }
|
||||
let(:arguments) { [*options, recipe_file] }
|
||||
let(:stdout) { StringIO.new }
|
||||
|
||||
subject(:cli) { CLI.new(arguments, stdout: stdout) }
|
||||
@@ -36,7 +37,7 @@ module Producer::Core
|
||||
|
||||
context 'when an argument error is raised' do
|
||||
before do
|
||||
allow(CLI).to receive(:new) { cli }
|
||||
allow(described_class).to receive(:new) { cli }
|
||||
allow(cli).to receive(:parse_arguments!)
|
||||
.and_raise described_class::ArgumentError
|
||||
end
|
||||
@@ -60,7 +61,7 @@ module Producer::Core
|
||||
end
|
||||
|
||||
context 'without options' do
|
||||
subject(:cli) { CLI.new(arguments) }
|
||||
subject(:cli) { described_class.new(arguments) }
|
||||
|
||||
it 'assigns $stdout as the default standard output' do
|
||||
expect(cli.stdout).to be $stdout
|
||||
@@ -82,7 +83,7 @@ module Producer::Core
|
||||
|
||||
describe '#parse_arguments!' do
|
||||
context 'with options' do
|
||||
let(:arguments) { ['-v', recipe_file] }
|
||||
let(:options) { %w[-v] }
|
||||
|
||||
before { cli.parse_arguments! }
|
||||
|
||||
@@ -95,6 +96,14 @@ module Producer::Core
|
||||
expect(cli.env.log_level).to eq Logger::INFO
|
||||
end
|
||||
end
|
||||
|
||||
context 'dry run' do
|
||||
let(:options) { %w[-n] }
|
||||
|
||||
it 'enables env dry run' do
|
||||
expect(cli.env).to be_dry_run
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'without arguments' do
|
||||
|
@@ -18,6 +18,10 @@ module Producer::Core
|
||||
expect(env.registry).to be_empty
|
||||
end
|
||||
|
||||
it 'assigns dry run as false' do
|
||||
expect(env.dry_run).to be false
|
||||
end
|
||||
|
||||
context 'when output is not given as argument' do
|
||||
subject(:env) { Env.new }
|
||||
|
||||
@@ -133,5 +137,13 @@ module Producer::Core
|
||||
expect(env.logger.level).to eq Logger::DEBUG
|
||||
end
|
||||
end
|
||||
|
||||
describe '#dry_run?' do
|
||||
before { env.dry_run = true }
|
||||
|
||||
it 'returns true when dry run is enabled' do
|
||||
expect(env.dry_run?).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
||||
|
||||
module Producer::Core
|
||||
describe Worker do
|
||||
let(:env) { double 'env', log: nil }
|
||||
let(:env) { double 'env', log: nil, dry_run?: false }
|
||||
subject(:worker) { described_class.new(env) }
|
||||
|
||||
describe '#process' do
|
||||
@@ -37,6 +37,15 @@ module Producer::Core
|
||||
expect(env).to receive(:log).with /\A action: echo/
|
||||
worker.process_task task
|
||||
end
|
||||
|
||||
context 'when dry run is enabled' do
|
||||
before { allow(env).to receive(:dry_run?) { true } }
|
||||
|
||||
it 'does not apply the actions' do
|
||||
expect(action).not_to receive :apply
|
||||
worker.process_task task
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when task condition is not met' do
|
||||
|
Reference in New Issue
Block a user