Fail when `file_write' misses some arguments

This commit is contained in:
Thibault Jouan 2014-10-09 19:11:16 +00:00
parent ef7259fab2
commit 61c262a9f1
3 changed files with 13 additions and 0 deletions

View File

@ -3,6 +3,10 @@ module Producer
module Actions
class FileWriter < Action
def setup
if arguments.compact.size != 2
fail ArgumentError, '`%s\' action requires 2 arguments' % name
end
@path, @content = arguments
@options[:permissions] = @options.delete :mode if options.key? :mode
@options[:owner] = @options.delete :user if options.key? :user

View File

@ -2,6 +2,7 @@ module Producer
module Core
Error = Class.new(StandardError)
RuntimeError = Class.new(RuntimeError)
ArgumentError = Class.new(Error)
ConditionNotMetError = Class.new(Error)
RemoteCommandExecutionError = Class.new(RuntimeError)
RegistryKeyError = Class.new(RuntimeError)

View File

@ -20,6 +20,14 @@ module Producer::Core
it 'translates user option as owner' do
expect(writer.options[:owner]).to eq 'root'
end
context 'when content is missing' do
let(:content) { nil }
it 'raises ArgumentError' do
expect { writer }.to raise_error ArgumentError
end
end
end
describe '#apply' do