2013-11-29 01:54:10 +00:00
|
|
|
require File.expand_path("../../../../base", __FILE__)
|
|
|
|
|
|
|
|
describe "VagrantPlugins::Shell::Config" do
|
|
|
|
let(:described_class) do
|
|
|
|
VagrantPlugins::Shell::Plugin.components.configs[:provisioner][:shell]
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:machine) { double('machine', env: Vagrant::Environment.new) }
|
|
|
|
let(:file_that_exists) { File.expand_path(__FILE__) }
|
|
|
|
|
|
|
|
subject { described_class.new }
|
|
|
|
|
|
|
|
describe "validate" do
|
|
|
|
it "passes with no args" do
|
|
|
|
subject.path = file_that_exists
|
|
|
|
subject.finalize!
|
|
|
|
|
|
|
|
result = subject.validate(machine)
|
|
|
|
|
2014-03-14 15:02:07 +00:00
|
|
|
expect(result["shell provisioner"]).to eq([])
|
2013-11-29 01:54:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "passes with string args" do
|
|
|
|
subject.path = file_that_exists
|
|
|
|
subject.args = "a string"
|
|
|
|
subject.finalize!
|
|
|
|
|
|
|
|
result = subject.validate(machine)
|
|
|
|
|
2014-03-14 15:02:07 +00:00
|
|
|
expect(result["shell provisioner"]).to eq([])
|
2013-11-29 01:54:10 +00:00
|
|
|
end
|
|
|
|
|
2014-02-14 19:53:17 +00:00
|
|
|
it "passes with fixnum args" do
|
|
|
|
subject.path = file_that_exists
|
|
|
|
subject.args = 1
|
|
|
|
subject.finalize!
|
|
|
|
|
|
|
|
result = subject.validate(machine)
|
|
|
|
|
2014-03-14 15:02:07 +00:00
|
|
|
expect(result["shell provisioner"]).to eq([])
|
2014-02-14 19:53:17 +00:00
|
|
|
end
|
|
|
|
|
2013-11-29 01:54:10 +00:00
|
|
|
it "passes with array args" do
|
|
|
|
subject.path = file_that_exists
|
|
|
|
subject.args = ["an", "array"]
|
|
|
|
subject.finalize!
|
|
|
|
|
|
|
|
result = subject.validate(machine)
|
|
|
|
|
2014-03-14 15:02:07 +00:00
|
|
|
expect(result["shell provisioner"]).to eq([])
|
2013-11-29 01:54:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns an error if args is neither a string nor an array" do
|
|
|
|
neither_array_nor_string = Object.new
|
|
|
|
|
|
|
|
subject.path = file_that_exists
|
|
|
|
subject.args = neither_array_nor_string
|
|
|
|
subject.finalize!
|
|
|
|
|
|
|
|
result = subject.validate(machine)
|
|
|
|
|
2014-03-14 15:02:07 +00:00
|
|
|
expect(result["shell provisioner"]).to eq([
|
2013-11-29 01:54:10 +00:00
|
|
|
I18n.t("vagrant.provisioners.shell.args_bad_type")
|
2014-03-14 15:02:07 +00:00
|
|
|
])
|
2013-11-29 01:54:10 +00:00
|
|
|
end
|
2014-02-14 19:47:36 +00:00
|
|
|
|
|
|
|
it "handles scalar array args" do
|
|
|
|
subject.path = file_that_exists
|
|
|
|
subject.args = ["string", 1, 2]
|
|
|
|
subject.finalize!
|
|
|
|
|
|
|
|
result = subject.validate(machine)
|
|
|
|
|
2014-03-14 15:02:07 +00:00
|
|
|
expect(result["shell provisioner"]).to eq([])
|
2014-02-14 19:47:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns an error if args is an array with non-scalar types" do
|
|
|
|
subject.path = file_that_exists
|
|
|
|
subject.args = [[1]]
|
|
|
|
subject.finalize!
|
|
|
|
|
|
|
|
result = subject.validate(machine)
|
|
|
|
|
2014-03-14 15:02:07 +00:00
|
|
|
expect(result["shell provisioner"]).to eq([
|
2014-02-14 19:47:36 +00:00
|
|
|
I18n.t("vagrant.provisioners.shell.args_bad_type")
|
2014-03-14 15:02:07 +00:00
|
|
|
])
|
2014-02-14 19:47:36 +00:00
|
|
|
end
|
2013-11-29 01:54:10 +00:00
|
|
|
end
|
2014-07-11 21:08:07 +00:00
|
|
|
|
|
|
|
describe 'finalize!' do
|
|
|
|
it 'changes fixnum args into strings' do
|
|
|
|
subject.path = file_that_exists
|
|
|
|
subject.args = 1
|
|
|
|
subject.finalize!
|
|
|
|
|
|
|
|
expect(subject.args).to eq '1'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'changes fixnum args in arrays into strings' do
|
|
|
|
subject.path = file_that_exists
|
|
|
|
subject.args = ["string", 1, 2]
|
|
|
|
subject.finalize!
|
|
|
|
|
|
|
|
expect(subject.args).to eq ["string", '1', '2']
|
|
|
|
end
|
|
|
|
end
|
2013-11-29 01:54:10 +00:00
|
|
|
end
|