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