Fail when `mkdir' misses arguments
This commit is contained in:
parent
fdfd5df26f
commit
3f82b923b7
@ -3,6 +3,8 @@ module Producer
|
||||
module Actions
|
||||
class Mkdir < Action
|
||||
def setup
|
||||
check_arguments_size! 1
|
||||
@path = Pathname.new(arguments.first)
|
||||
@options[:permissions] = @options.delete :mode if @options.key? :mode
|
||||
@options[:owner] = @options.delete :user if @options.key? :user
|
||||
end
|
||||
@ -12,19 +14,12 @@ module Producer
|
||||
end
|
||||
|
||||
def apply
|
||||
path.descend do |p|
|
||||
@path.descend do |p|
|
||||
next if fs.dir? p
|
||||
fs.mkdir p.to_s
|
||||
fs.setstat p.to_s, @options unless @options.empty?
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def path
|
||||
Pathname.new(arguments.first)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -5,8 +5,8 @@ module Producer::Core
|
||||
describe Mkdir, :env do
|
||||
let(:path) { 'some_path' }
|
||||
let(:options) { { } }
|
||||
let(:arguments) { [path, options] }
|
||||
subject(:mkdir) { described_class.new(env, *arguments) }
|
||||
let(:arguments) { [path] }
|
||||
subject(:mkdir) { described_class.new(env, *arguments, options) }
|
||||
|
||||
it_behaves_like 'action'
|
||||
|
||||
@ -20,6 +20,14 @@ module Producer::Core
|
||||
it 'translates user option as owner' do
|
||||
expect(mkdir.options[:owner]).to eq 'root'
|
||||
end
|
||||
|
||||
context 'when path is missing' do
|
||||
let(:path) { nil }
|
||||
|
||||
it 'raises ArgumentError' do
|
||||
expect { mkdir }.to raise_error ArgumentError
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#apply' do
|
||||
|
Loading…
x
Reference in New Issue
Block a user