spec/unit/puppetfile_spec.rb in r10k-2.6.9 vs spec/unit/puppetfile_spec.rb in r10k-3.0.0
- old
+ new
@@ -3,20 +3,46 @@
describe R10K::Puppetfile do
subject do
described_class.new(
+ '/some/nonexistent/basedir',
+ nil,
+ nil,
+ 'Puppetfile.r10k'
+ )
+ end
+
+ describe "a custom puppetfile Puppetfile.r10k" do
+ it "is the basedir joined with '/Puppetfile.r10k' path" do
+ expect(subject.puppetfile_path).to eq '/some/nonexistent/basedir/Puppetfile.r10k'
+ end
+ end
+
+end
+
+describe R10K::Puppetfile do
+
+ subject do
+ described_class.new(
'/some/nonexistent/basedir'
)
end
describe "the default moduledir" do
it "is the basedir joined with '/modules' path" do
expect(subject.moduledir).to eq '/some/nonexistent/basedir/modules'
end
end
+ describe "the default puppetfile" do
+ it "is the basedir joined with '/Puppetfile' path" do
+ expect(subject.puppetfile_path).to eq '/some/nonexistent/basedir/Puppetfile'
+ end
+ end
+
+
describe "setting moduledir" do
it "changes to given moduledir if it is an absolute path" do
subject.set_moduledir('/absolute/path/moduledir')
expect(subject.moduledir).to eq '/absolute/path/moduledir'
end
@@ -126,30 +152,10 @@
expect(subject.purge_exclusions).to match_array(managed_dirs + env_contents)
end
end
end
- describe '#managed_directories' do
- it 'returns an array of paths that can be purged' do
- allow(R10K::Module).to receive(:new).with('puppet/test_module', subject.moduledir, '1.2.3', anything).and_call_original
-
- subject.add_module('puppet/test_module', '1.2.3')
- expect(subject.managed_directories).to match_array(["/some/nonexistent/basedir/modules"])
- end
-
- context 'with a module with install_path == \'\'' do
- it 'basedir isn\'t in the list of paths to purge' do
- module_opts = { install_path: '', git: 'git@example.com:puppet/test_module.git' }
-
- allow(R10K::Module).to receive(:new).with('puppet/test_module', subject.basedir, module_opts, anything).and_call_original
-
- subject.add_module('puppet/test_module', module_opts)
- expect(subject.managed_directories).to be_empty
- end
- end
- end
-
describe "evaluating a Puppetfile" do
def expect_wrapped_error(orig, pf_path, wrapped_error)
expect(orig).to be_a_kind_of(R10K::Error)
expect(orig.message).to eq("Failed to evaluate #{pf_path}")
expect(orig.original).to be_a_kind_of(wrapped_error)
@@ -186,40 +192,41 @@
}.to raise_error do |e|
expect_wrapped_error(e, pf_path, ArgumentError)
end
end
- it "accepts a forge module with a version" do
- path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'valid-forge-with-version')
+ it "rejects Puppetfiles with duplicate module names" do
+ path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'duplicate-module-error')
pf_path = File.join(path, 'Puppetfile')
subject = described_class.new(path)
- expect { subject.load! }.not_to raise_error
+ expect {
+ subject.load!
+ }.to raise_error(R10K::Error, /Puppetfiles cannot contain duplicate module names/i)
end
- it "accepts a forge module without a version" do
- path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'valid-forge-without-version')
+ it "wraps and re-raises name errors" do
+ path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'name-error')
pf_path = File.join(path, 'Puppetfile')
subject = described_class.new(path)
- expect { subject.load! }.not_to raise_error
+ expect {
+ subject.load!
+ }.to raise_error do |e|
+ expect_wrapped_error(e, pf_path, NameError)
+ end
end
- it "creates a git module and applies the default branch sepcified in the Puppetfile" do
- path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'default-branch-override')
+ it "accepts a forge module with a version" do
+ path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'valid-forge-with-version')
pf_path = File.join(path, 'Puppetfile')
subject = described_class.new(path)
expect { subject.load! }.not_to raise_error
- git_module = subject.modules[0]
- expect(git_module.default_ref).to eq 'here_lies_the_default_branch'
end
- it "creates a git module and applies the provided default_branch_override" do
- path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'default-branch-override')
+ it "accepts a forge module without a version" do
+ path = File.join(PROJECT_ROOT, 'spec', 'fixtures', 'unit', 'puppetfile', 'valid-forge-without-version')
pf_path = File.join(path, 'Puppetfile')
subject = described_class.new(path)
- default_branch_override = 'default_branch_override_name'
- expect { subject.load!(default_branch_override) }.not_to raise_error
- git_module = subject.modules[0]
- expect(git_module.default_ref).to eq default_branch_override
+ expect { subject.load! }.not_to raise_error
end
end
describe "accepting a visitor" do
it "passes itself to the visitor" do