3
require 'puppet/module_tool'
5
describe "puppet module install" do
6
include PuppetSpec::Files
8
subject { Puppet::Face[:module, :current] }
14
describe "option validation" do
16
Puppet.settings[:modulepath] = fakemodpath
19
let(:expected_options) do
21
:target_dir => fakefirstpath,
22
:modulepath => fakemodpath,
23
:environment => 'production'
27
let(:sep) { File::PATH_SEPARATOR }
28
let(:fakefirstpath) { make_absolute("/my/fake/modpath") }
29
let(:fakesecondpath) { make_absolute("/other/fake/path") }
30
let(:fakemodpath) { "#{fakefirstpath}#{sep}#{fakesecondpath}" }
31
let(:fakedirpath) { make_absolute("/my/fake/path") }
33
context "without any options" do
34
it "should require a name" do
35
pattern = /wrong number of arguments/
36
expect { subject.install }.to raise_error ArgumentError, pattern
39
it "should not require any options" do
40
Puppet::ModuleTool::Applications::Installer.expects(:run).with("puppetlabs-apache", expected_options).once
41
subject.install("puppetlabs-apache")
45
it "should accept the --force option" do
46
options[:force] = true
47
expected_options.merge!(options)
48
Puppet::ModuleTool::Applications::Installer.expects(:run).with("puppetlabs-apache", expected_options).once
49
subject.install("puppetlabs-apache", options)
52
it "should accept the --target-dir option" do
53
options[:target_dir] = make_absolute("/foo/puppet/modules")
54
expected_options.merge!(options)
55
expected_options[:modulepath] = "#{options[:target_dir]}#{sep}#{fakemodpath}"
57
Puppet::ModuleTool::Applications::Installer.expects(:run).with("puppetlabs-apache", expected_options).once
58
subject.install("puppetlabs-apache", options)
61
it "should accept the --version option" do
62
options[:version] = "0.0.1"
63
expected_options.merge!(options)
64
Puppet::ModuleTool::Applications::Installer.expects(:run).with("puppetlabs-apache", expected_options).once
65
subject.install("puppetlabs-apache", options)
68
it "should accept the --ignore-dependencies option" do
69
options[:ignore_dependencies] = true
70
expected_options.merge!(options)
71
Puppet::ModuleTool::Applications::Installer.expects(:run).with("puppetlabs-apache", expected_options).once
72
subject.install("puppetlabs-apache", options)
75
describe "when modulepath option is passed" do
76
let(:expected_options) { { :modulepath => fakemodpath, :environment => 'production' } }
77
let(:options) { { :modulepath => fakemodpath } }
79
describe "when target-dir option is not passed" do
80
it "should set target-dir to be first path from modulepath" do
81
expected_options[:target_dir] = fakefirstpath
83
Puppet::ModuleTool::Applications::Installer.
85
with("puppetlabs-apache", expected_options)
87
Puppet::Face[:module, :current].install("puppetlabs-apache", options)
89
Puppet.settings[:modulepath].should == fakemodpath
93
describe "when target-dir option is passed" do
94
it "should expand the target directory" do
95
options[:target_dir] = "modules"
96
expanded_path = File.expand_path("modules")
97
expected_options.merge!(options)
98
expected_options[:target_dir] = expanded_path
99
expected_options[:modulepath] = "#{expanded_path}#{sep}#{fakemodpath}"
101
Puppet::ModuleTool::Applications::Installer.expects(:run).with("puppetlabs-apache", expected_options).once
102
subject.install("puppetlabs-apache", options)
105
it "should set target-dir to be first path of modulepath" do
106
options[:target_dir] = fakedirpath
107
expected_options[:target_dir] = fakedirpath
108
expected_options[:modulepath] = "#{fakedirpath}#{sep}#{fakemodpath}"
110
Puppet::ModuleTool::Applications::Installer.
112
with("puppetlabs-apache", expected_options)
114
Puppet::Face[:module, :current].install("puppetlabs-apache", options)
116
Puppet.settings[:modulepath].should == "#{fakedirpath}#{sep}#{fakemodpath}"
121
describe "when modulepath option is not passed" do
123
Puppet.settings[:modulepath] = fakemodpath
126
describe "when target-dir option is not passed" do
127
it "should set target-dir to be first path of default mod path" do
128
expected_options[:target_dir] = fakefirstpath
129
expected_options[:modulepath] = fakemodpath
131
Puppet::ModuleTool::Applications::Installer.
133
with("puppetlabs-apache", expected_options)
135
Puppet::Face[:module, :current].install("puppetlabs-apache", options)
139
describe "when target-dir option is passed" do
140
it "should prepend target-dir to modulepath" do
141
options[:target_dir] = fakedirpath
142
expected_options[:target_dir] = fakedirpath
143
expected_options[:modulepath] = "#{options[:target_dir]}#{sep}#{fakemodpath}"
145
Puppet::ModuleTool::Applications::Installer.
147
with("puppetlabs-apache", expected_options)
149
Puppet::Face[:module, :current].install("puppetlabs-apache", options)
150
Puppet.settings[:modulepath].should == expected_options[:modulepath]
156
describe "inline documentation" do
157
subject { Puppet::Face[:module, :current].get_action :install }
159
its(:summary) { should =~ /install.*module/im }
160
its(:description) { should =~ /install.*module/im }
161
its(:returns) { should =~ /pathname/i }
162
its(:examples) { should_not be_empty }
164
%w{ license copyright summary description returns examples }.each do |doc|
166
its(doc.to_sym) { should_not =~ /(FIXME|REVISIT|TODO)/ }