puppet 2.7.1 → 2.7.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (171) hide show
  1. data/CHANGELOG +225 -1
  2. data/CONTRIBUTING.md +299 -0
  3. data/README.md +0 -1
  4. data/conf/redhat/puppet.spec +132 -25
  5. data/conf/solaris/pkginfo +1 -1
  6. data/conf/suse/puppet.spec +5 -2
  7. data/ext/envpuppet +56 -3
  8. data/ext/vim/README +2 -1
  9. data/ext/vim/ftplugin/puppet.vim +94 -0
  10. data/ext/vim/indent/puppet.vim +76 -0
  11. data/lib/puppet.rb +2 -3
  12. data/lib/puppet/application/agent.rb +7 -7
  13. data/lib/puppet/application/apply.rb +20 -8
  14. data/lib/puppet/application/ca.rb +5 -0
  15. data/lib/puppet/application/cert.rb +2 -1
  16. data/lib/puppet/application/certificate.rb +0 -5
  17. data/lib/puppet/application/device.rb +4 -4
  18. data/lib/puppet/application/doc.rb +23 -12
  19. data/lib/puppet/application/face_base.rb +2 -1
  20. data/lib/puppet/application/inspect.rb +5 -2
  21. data/lib/puppet/configurer.rb +60 -56
  22. data/lib/puppet/configurer/fact_handler.rb +6 -1
  23. data/lib/puppet/defaults.rb +20 -1
  24. data/lib/puppet/face/ca.rb +233 -0
  25. data/lib/puppet/face/certificate.rb +15 -11
  26. data/lib/puppet/face/certificate_request.rb +9 -11
  27. data/lib/puppet/face/certificate_revocation_list.rb +5 -7
  28. data/lib/puppet/face/node/clean.rb +154 -0
  29. data/lib/puppet/face/status.rb +1 -0
  30. data/lib/puppet/file_serving/configuration/parser.rb +6 -13
  31. data/lib/puppet/indirector/exec.rb +3 -3
  32. data/lib/puppet/indirector/face.rb +17 -7
  33. data/lib/puppet/indirector/report/processor.rb +29 -16
  34. data/lib/puppet/indirector/rest.rb +42 -7
  35. data/lib/puppet/indirector/yaml.rb +5 -0
  36. data/lib/puppet/interface.rb +7 -2
  37. data/lib/puppet/interface/action.rb +57 -23
  38. data/lib/puppet/interface/action_manager.rb +10 -5
  39. data/lib/puppet/interface/face_collection.rb +43 -52
  40. data/lib/puppet/interface/option.rb +19 -0
  41. data/lib/puppet/interface/option_builder.rb +13 -0
  42. data/lib/puppet/interface/option_manager.rb +2 -1
  43. data/lib/puppet/metatype/manager.rb +7 -20
  44. data/lib/puppet/module.rb +4 -1
  45. data/lib/puppet/network/authconfig.rb +3 -1
  46. data/lib/puppet/network/authstore.rb +14 -5
  47. data/lib/puppet/network/handler/fileserver.rb +3 -0
  48. data/lib/puppet/network/http/webrick.rb +1 -1
  49. data/lib/puppet/network/rest_authconfig.rb +6 -1
  50. data/lib/puppet/network/rest_authorization.rb +1 -1
  51. data/lib/puppet/parser/compiler.rb +8 -11
  52. data/lib/puppet/parser/functions.rb +1 -6
  53. data/lib/puppet/parser/functions/create_resources.rb +6 -5
  54. data/lib/puppet/parser/functions/regsubst.rb +26 -0
  55. data/lib/puppet/parser/functions/shellquote.rb +26 -0
  56. data/lib/puppet/parser/functions/sprintf.rb +26 -0
  57. data/lib/puppet/parser/grammar.ra +34 -60
  58. data/lib/puppet/parser/lexer.rb +5 -5
  59. data/lib/puppet/parser/parser.rb +913 -1196
  60. data/lib/puppet/parser/resource.rb +18 -1
  61. data/lib/puppet/parser/scope.rb +2 -2
  62. data/lib/puppet/provider/augeas/augeas.rb +42 -17
  63. data/lib/puppet/provider/mount/parsed.rb +19 -1
  64. data/lib/puppet/provider/naginator.rb +9 -1
  65. data/lib/puppet/provider/nameservice/directoryservice.rb +11 -8
  66. data/lib/puppet/provider/network_device.rb +1 -1
  67. data/lib/puppet/provider/package/aptitude.rb +1 -0
  68. data/lib/puppet/provider/package/pacman.rb +94 -0
  69. data/lib/puppet/provider/ssh_authorized_key/parsed.rb +0 -6
  70. data/lib/puppet/rails/host.rb +7 -0
  71. data/lib/puppet/reports/store.rb +15 -0
  72. data/lib/puppet/resource/catalog.rb +15 -6
  73. data/lib/puppet/ssl/certificate.rb +6 -0
  74. data/lib/puppet/ssl/inventory.rb +2 -0
  75. data/lib/puppet/transaction.rb +9 -17
  76. data/lib/puppet/transaction/report.rb +3 -3
  77. data/lib/puppet/type.rb +13 -24
  78. data/lib/puppet/type/file.rb +8 -2
  79. data/lib/puppet/type/file/source.rb +2 -2
  80. data/lib/puppet/type/service.rb +20 -24
  81. data/lib/puppet/type/ssh_authorized_key.rb +12 -0
  82. data/lib/puppet/type/user.rb +8 -0
  83. data/lib/puppet/util.rb +0 -1
  84. data/lib/puppet/util/network_device.rb +3 -3
  85. data/lib/puppet/util/settings.rb +1 -1
  86. data/lib/puppet/util/settings/file_setting.rb +1 -0
  87. data/lib/semver.rb +65 -0
  88. data/spec/integration/defaults_spec.rb +23 -1
  89. data/spec/integration/network/rest_authconfig_spec.rb +145 -0
  90. data/spec/integration/node/facts_spec.rb +1 -1
  91. data/spec/integration/parser/functions_spec.rb +1 -1
  92. data/spec/integration/parser/parser_spec.rb +31 -0
  93. data/spec/integration/provider/ssh_authorized_key_spec.rb +207 -0
  94. data/spec/integration/type_spec.rb +11 -0
  95. data/spec/lib/puppet/face/1.0.0/huzzah.rb +8 -0
  96. data/spec/lib/puppet/face/huzzah.rb +1 -0
  97. data/spec/lib/puppet/face/huzzah/obsolete.rb +6 -0
  98. data/spec/shared_behaviours/things_that_declare_options.rb +115 -3
  99. data/spec/unit/application/agent_spec.rb +2 -2
  100. data/spec/unit/application/apply_spec.rb +74 -56
  101. data/spec/unit/application/cert_spec.rb +10 -0
  102. data/spec/unit/application/device_spec.rb +2 -3
  103. data/spec/unit/application/face_base_spec.rb +1 -0
  104. data/spec/unit/application/facts_spec.rb +1 -0
  105. data/spec/unit/application/inspect_spec.rb +5 -0
  106. data/spec/unit/configurer/fact_handler_spec.rb +45 -37
  107. data/spec/unit/configurer_spec.rb +405 -327
  108. data/spec/unit/face/ca_spec.rb +355 -0
  109. data/spec/unit/face/certificate_spec.rb +16 -4
  110. data/spec/unit/face/node_spec.rb +261 -1
  111. data/spec/unit/file_serving/configuration/parser_spec.rb +8 -0
  112. data/spec/unit/indirector/certificate/rest_spec.rb +1 -0
  113. data/spec/unit/indirector/certificate_status/file_spec.rb +4 -0
  114. data/spec/unit/indirector/exec_spec.rb +4 -4
  115. data/spec/unit/indirector/face_spec.rb +3 -1
  116. data/spec/unit/indirector/facts/couch_spec.rb +2 -2
  117. data/spec/unit/indirector/facts/network_device_spec.rb +2 -6
  118. data/spec/unit/indirector/node/exec_spec.rb +1 -1
  119. data/spec/unit/indirector/report/processor_spec.rb +31 -8
  120. data/spec/unit/indirector/rest_spec.rb +53 -5
  121. data/spec/unit/indirector/yaml_spec.rb +18 -0
  122. data/spec/unit/interface/action_spec.rb +112 -8
  123. data/spec/unit/interface/face_collection_spec.rb +46 -36
  124. data/spec/unit/interface/option_spec.rb +44 -0
  125. data/spec/unit/interface_spec.rb +11 -6
  126. data/spec/unit/module_spec.rb +38 -9
  127. data/spec/unit/network/authconfig_spec.rb +23 -0
  128. data/spec/unit/network/authstore_spec.rb +36 -4
  129. data/spec/unit/network/handler/fileserver_spec.rb +32 -0
  130. data/spec/unit/network/rest_authconfig_spec.rb +1 -1
  131. data/spec/unit/node_spec.rb +1 -0
  132. data/spec/unit/parser/compiler_spec.rb +8 -46
  133. data/spec/unit/parser/lexer_spec.rb +27 -17
  134. data/spec/unit/parser/resource_spec.rb +61 -3
  135. data/spec/unit/parser/scope_spec.rb +5 -1
  136. data/spec/unit/provider/augeas/augeas_spec.rb +106 -1
  137. data/spec/unit/provider/cisco_spec.rb +3 -4
  138. data/spec/unit/provider/interface/cisco_spec.rb +1 -2
  139. data/spec/unit/provider/mount/parsed_spec.rb +41 -0
  140. data/spec/unit/provider/nameservice/directoryservice_spec.rb +60 -0
  141. data/spec/unit/provider/network_device_spec.rb +1 -2
  142. data/spec/unit/provider/package/pacman_spec.rb +237 -0
  143. data/spec/unit/provider/package/pkgutil_spec.rb +2 -3
  144. data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +21 -32
  145. data/spec/unit/provider/vlan/cisco_spec.rb +1 -2
  146. data/spec/unit/rails/host_spec.rb +8 -0
  147. data/spec/unit/resource/catalog_spec.rb +55 -8
  148. data/spec/unit/semver_spec.rb +187 -0
  149. data/spec/unit/ssl/certificate_spec.rb +25 -0
  150. data/spec/unit/transaction/report_spec.rb +3 -3
  151. data/spec/unit/transaction_spec.rb +8 -2
  152. data/spec/unit/type/file_spec.rb +57 -0
  153. data/spec/unit/type/interface_spec.rb +1 -2
  154. data/spec/unit/type/schedule_spec.rb +73 -42
  155. data/spec/unit/type/ssh_authorized_key_spec.rb +180 -70
  156. data/spec/unit/type/user_spec.rb +8 -0
  157. data/spec/unit/type/vlan_spec.rb +1 -2
  158. data/spec/unit/type_spec.rb +66 -0
  159. data/spec/unit/util/network_device/cisco/device_spec.rb +1 -2
  160. data/spec/unit/util/network_device/cisco/facts_spec.rb +2 -3
  161. data/spec/unit/util/network_device/cisco/interface_spec.rb +1 -2
  162. data/spec/unit/util/network_device/config_spec.rb +3 -4
  163. data/spec/unit/util/network_device/ipcalc_spec.rb +1 -2
  164. data/spec/unit/util/network_device/transport/base_spec.rb +1 -2
  165. data/spec/unit/util/network_device/transport/ssh_spec.rb +1 -2
  166. data/spec/unit/util/network_device/transport/telnet_spec.rb +1 -2
  167. data/spec/unit/util/network_device_spec.rb +2 -2
  168. data/spec/unit/util/settings/file_setting_spec.rb +4 -0
  169. data/spec/unit/util/settings_spec.rb +11 -0
  170. data/test/lib/puppettest/railstesting.rb +0 -34
  171. metadata +19 -4
@@ -27,13 +27,12 @@ shared_examples_for "things that declare options" do
27
27
 
28
28
  thing = add_options_to do
29
29
  option "--foo" do
30
- desc text
31
30
  description text
32
31
  summary text
33
32
  end
34
33
  end
35
34
 
36
- thing.get_option(:foo).desc.should == text
35
+ thing.get_option(:foo).description.should == text
37
36
  end
38
37
 
39
38
  it "should list all the options" do
@@ -44,7 +43,7 @@ shared_examples_for "things that declare options" do
44
43
  option "-f"
45
44
  option "--baz"
46
45
  end
47
- thing.options.should == [:foo, :bar, :b, :q, :quux, :f, :baz]
46
+ thing.options.should == [:foo, :bar, :quux, :f, :baz]
48
47
  end
49
48
 
50
49
  it "should detect conflicts in long options" do
@@ -147,4 +146,117 @@ shared_examples_for "things that declare options" do
147
146
  end
148
147
  end
149
148
  end
149
+
150
+ describe "#default_to" do
151
+ it "should not have a default value by default" do
152
+ option = add_options_to do option "--foo" end.get_option(:foo)
153
+ option.should_not be_has_default
154
+ end
155
+
156
+ it "should accept a block for the default value" do
157
+ option = add_options_to do
158
+ option "--foo" do
159
+ default_to do
160
+ 12
161
+ end
162
+ end
163
+ end.get_option(:foo)
164
+
165
+ option.should be_has_default
166
+ end
167
+
168
+ it "should invoke the block when asked for the default value" do
169
+ invoked = false
170
+ option = add_options_to do
171
+ option "--foo" do
172
+ default_to do
173
+ invoked = true
174
+ end
175
+ end
176
+ end.get_option(:foo)
177
+
178
+ option.should be_has_default
179
+ option.default.should be_true
180
+ invoked.should be_true
181
+ end
182
+
183
+ it "should return the value of the block when asked for the default" do
184
+ option = add_options_to do
185
+ option "--foo" do
186
+ default_to do
187
+ 12
188
+ end
189
+ end
190
+ end.get_option(:foo)
191
+
192
+ option.should be_has_default
193
+ option.default.should == 12
194
+ end
195
+
196
+ it "should invoke the block every time the default is requested" do
197
+ option = add_options_to do
198
+ option "--foo" do
199
+ default_to do
200
+ {}
201
+ end
202
+ end
203
+ end.get_option(:foo)
204
+
205
+ first = option.default.object_id
206
+ second = option.default.object_id
207
+ third = option.default.object_id
208
+
209
+ first.should_not == second
210
+ first.should_not == third
211
+ second.should_not == third
212
+ end
213
+
214
+ it "should fail if the option has a default and is required" do
215
+ expect {
216
+ add_options_to do
217
+ option "--foo" do
218
+ required
219
+ default_to do 12 end
220
+ end
221
+ end
222
+ }.to raise_error ArgumentError, /can't be optional and have a default value/
223
+
224
+ expect {
225
+ add_options_to do
226
+ option "--foo" do
227
+ default_to do 12 end
228
+ required
229
+ end
230
+ end
231
+ }.to raise_error ArgumentError, /can't be optional and have a default value/
232
+ end
233
+
234
+ it "should fail if default_to has no block" do
235
+ expect { add_options_to do option "--foo" do default_to end end }.
236
+ to raise_error ArgumentError, /default_to requires a block/
237
+ end
238
+
239
+ it "should fail if default_to is invoked twice" do
240
+ expect {
241
+ add_options_to do
242
+ option "--foo" do
243
+ default_to do 12 end
244
+ default_to do "fun" end
245
+ end
246
+ end
247
+ }.to raise_error ArgumentError, /already has a default value/
248
+ end
249
+
250
+ [ "one", "one, two", "one, *two" ].each do |input|
251
+ it "should fail if the block has the wrong arity (#{input})" do
252
+ expect {
253
+ add_options_to do
254
+ option "--foo" do
255
+ eval "default_to do |#{input}| 12 end"
256
+ end
257
+ end
258
+ }.to raise_error ArgumentError, /should not take any arguments/
259
+ end
260
+ end
261
+ end
150
262
  end
@@ -411,7 +411,7 @@ describe Puppet::Application::Agent do
411
411
 
412
412
  it "should exit if no authorization file" do
413
413
  Puppet.stubs(:err)
414
- FileTest.stubs(:exists?).with(Puppet[:authconfig]).returns(false)
414
+ FileTest.stubs(:exists?).with(Puppet[:rest_authconfig]).returns(false)
415
415
  expect { @puppetd.setup_listen }.to exit_with 14
416
416
  end
417
417
 
@@ -545,7 +545,7 @@ describe Puppet::Application::Agent do
545
545
  @host.stubs(:certificate).returns(@cert)
546
546
  @cert.stubs(:fingerprint).with(:MD5).returns("DIGEST")
547
547
 
548
- Puppet.expects(:notice).with("DIGEST")
548
+ @puppetd.expects(:puts).with "DIGEST"
549
549
 
550
550
  @puppetd.fingerprint
551
551
  end
@@ -4,6 +4,7 @@ require 'spec_helper'
4
4
  require 'puppet/application/apply'
5
5
  require 'puppet/file_bucket/dipper'
6
6
  require 'puppet/configurer'
7
+ require 'fileutils'
7
8
 
8
9
  describe Puppet::Application::Apply do
9
10
  before :each do
@@ -59,13 +60,12 @@ describe Puppet::Application::Apply do
59
60
  end
60
61
 
61
62
  it "should set show_diff on --noop" do
62
- Puppet.stubs(:[]=)
63
- Puppet.stubs(:[]).with(:config)
64
- Puppet.stubs(:[]).with(:noop).returns(true)
65
-
66
- Puppet.expects(:[]=).with(:show_diff, true)
63
+ Puppet[:noop] = true
64
+ Puppet[:show_diff] = false
67
65
 
68
66
  @apply.setup
67
+
68
+ Puppet[:show_diff].should == true
69
69
  end
70
70
 
71
71
  it "should set console as the log destination if logdest option wasn't provided" do
@@ -127,28 +127,31 @@ describe Puppet::Application::Apply do
127
127
  end
128
128
 
129
129
  describe "the main command" do
130
+ include PuppetSpec::Files
131
+
130
132
  before :each do
131
- Puppet.stubs(:[])
132
- Puppet.settings.stubs(:use)
133
- Puppet.stubs(:[]).with(:prerun_command).returns ""
134
- Puppet.stubs(:[]).with(:postrun_command).returns ""
135
- Puppet.stubs(:[]).with(:trace).returns(true)
133
+ Puppet[:prerun_command] = ''
134
+ Puppet[:postrun_command] = ''
136
135
 
137
- @apply.options.stubs(:[])
136
+ Puppet::Node::Facts.indirection.terminus_class = :memory
137
+ Puppet::Node::Facts.indirection.cache_class = :memory
138
+ Puppet::Node.indirection.terminus_class = :memory
139
+ Puppet::Node.indirection.cache_class = :memory
138
140
 
139
- @facts = stub_everything 'facts'
140
- Puppet::Node::Facts.indirection.stubs(:find).returns(@facts)
141
+ @facts = Puppet::Node::Facts.new(Puppet[:node_name_value])
142
+ Puppet::Node::Facts.indirection.save(@facts)
141
143
 
142
- @node = stub_everything 'node'
143
- Puppet::Node.indirection.stubs(:find).returns(@node)
144
+ @node = Puppet::Node.new(Puppet[:node_name_value])
145
+ Puppet::Node.indirection.save(@node)
144
146
 
145
- @catalog = stub_everything 'catalog'
147
+ @catalog = Puppet::Resource::Catalog.new
146
148
  @catalog.stubs(:to_ral).returns(@catalog)
149
+
147
150
  Puppet::Resource::Catalog.indirection.stubs(:find).returns(@catalog)
148
151
 
149
152
  STDIN.stubs(:read)
150
153
 
151
- @transaction = stub_everything 'transaction'
154
+ @transaction = Puppet::Transaction.new(@catalog)
152
155
  @catalog.stubs(:apply).returns(@transaction)
153
156
 
154
157
  Puppet::Util::Storage.stubs(:load)
@@ -156,7 +159,7 @@ describe Puppet::Application::Apply do
156
159
  end
157
160
 
158
161
  it "should set the code to run from --code" do
159
- @apply.options.stubs(:[]).with(:code).returns("code to run")
162
+ @apply.options[:code] = "code to run"
160
163
  Puppet.expects(:[]=).with(:code,"code to run")
161
164
 
162
165
  expect { @apply.main }.to exit_with 0
@@ -172,47 +175,63 @@ describe Puppet::Application::Apply do
172
175
  end
173
176
 
174
177
  it "should set the manifest if a file is passed on command line and the file exists" do
175
- File.stubs(:exist?).with('site.pp').returns true
176
- @apply.command_line.stubs(:args).returns(['site.pp'])
178
+ manifest = tmpfile('site.pp')
179
+ FileUtils.touch(manifest)
180
+ @apply.command_line.stubs(:args).returns([manifest])
177
181
 
178
- Puppet.expects(:[]=).with(:manifest,"site.pp")
182
+ Puppet.expects(:[]=).with(:manifest,manifest)
179
183
 
180
184
  expect { @apply.main }.to exit_with 0
181
185
  end
182
186
 
183
187
  it "should raise an error if a file is passed on command line and the file does not exist" do
184
- File.stubs(:exist?).with('noexist.pp').returns false
185
- @apply.command_line.stubs(:args).returns(['noexist.pp'])
186
- lambda { @apply.main }.should raise_error(RuntimeError, 'Could not find file noexist.pp')
188
+ noexist = tmpfile('noexist.pp')
189
+ @apply.command_line.stubs(:args).returns([noexist])
190
+ lambda { @apply.main }.should raise_error(RuntimeError, "Could not find file #{noexist}")
187
191
  end
188
192
 
189
193
  it "should set the manifest to the first file and warn other files will be skipped" do
190
- File.stubs(:exist?).with('starwarsIV').returns true
191
- File.expects(:exist?).with('starwarsI').never
192
- @apply.command_line.stubs(:args).returns(['starwarsIV', 'starwarsI', 'starwarsII'])
194
+ manifest = tmpfile('starwarsIV')
195
+ FileUtils.touch(manifest)
196
+
197
+ @apply.command_line.stubs(:args).returns([manifest, 'starwarsI', 'starwarsII'])
193
198
 
194
- Puppet.expects(:[]=).with(:manifest,"starwarsIV")
199
+ Puppet.expects(:[]=).with(:manifest,manifest)
195
200
  Puppet.expects(:warning).with('Only one file can be applied per run. Skipping starwarsI, starwarsII')
196
201
 
197
202
  expect { @apply.main }.to exit_with 0
198
203
  end
199
204
 
200
- it "should collect the node facts" do
201
- Puppet::Node::Facts.indirection.expects(:find).returns(@facts)
205
+ it "should set the facts name based on the node_name_fact" do
206
+ @facts = Puppet::Node::Facts.new(Puppet[:node_name_value], 'my_name_fact' => 'other_node_name')
207
+ Puppet::Node::Facts.indirection.save(@facts)
208
+
209
+ node = Puppet::Node.new('other_node_name')
210
+ Puppet::Node.indirection.save(node)
211
+
212
+ Puppet[:node_name_fact] = 'my_name_fact'
202
213
 
203
214
  expect { @apply.main }.to exit_with 0
215
+
216
+ @facts.name.should == 'other_node_name'
204
217
  end
205
218
 
206
- it "should raise an error if we can't find the node" do
207
- Puppet::Node::Facts.indirection.expects(:find).returns(nil)
219
+ it "should set the node_name_value based on the node_name_fact" do
220
+ facts = Puppet::Node::Facts.new(Puppet[:node_name_value], 'my_name_fact' => 'other_node_name')
221
+ Puppet::Node::Facts.indirection.save(facts)
222
+ node = Puppet::Node.new('other_node_name')
223
+ Puppet::Node.indirection.save(node)
224
+ Puppet[:node_name_fact] = 'my_name_fact'
208
225
 
209
- lambda { @apply.main }.should raise_error
226
+ expect { @apply.main }.to exit_with 0
227
+
228
+ Puppet[:node_name_value].should == 'other_node_name'
210
229
  end
211
230
 
212
- it "should look for the node" do
213
- Puppet::Node.indirection.expects(:find).returns(@node)
231
+ it "should raise an error if we can't find the facts" do
232
+ Puppet::Node::Facts.indirection.expects(:find).returns(nil)
214
233
 
215
- expect { @apply.main }.to exit_with 0
234
+ lambda { @apply.main }.should raise_error
216
235
  end
217
236
 
218
237
  it "should raise an error if we can't find the node" do
@@ -222,21 +241,20 @@ describe Puppet::Application::Apply do
222
241
  end
223
242
 
224
243
  it "should merge in our node the loaded facts" do
225
- @facts.stubs(:values).returns("values")
226
-
227
- @node.expects(:merge).with("values")
244
+ @facts.values = {'key' => 'value'}
228
245
 
229
246
  expect { @apply.main }.to exit_with 0
247
+
248
+ @node.parameters['key'].should == 'value'
230
249
  end
231
250
 
232
251
  it "should load custom classes if loadclasses" do
233
- @apply.options.stubs(:[]).with(:loadclasses).returns(true)
234
- Puppet.stubs(:[]).with(:classfile).returns("/etc/puppet/classes.txt")
235
- FileTest.stubs(:exists?).with("/etc/puppet/classes.txt").returns(true)
236
- FileTest.stubs(:readable?).with("/etc/puppet/classes.txt").returns(true)
237
- File.stubs(:read).with("/etc/puppet/classes.txt").returns("class")
252
+ @apply.options[:loadclasses] = true
253
+ classfile = tmpfile('classfile')
254
+ File.open(classfile, 'w') { |c| c.puts 'class' }
255
+ Puppet[:classfile] = classfile
238
256
 
239
- @node.expects(:classes=)
257
+ @node.expects(:classes=).with(['class'])
240
258
 
241
259
  expect { @apply.main }.to exit_with 0
242
260
  end
@@ -261,8 +279,8 @@ describe Puppet::Application::Apply do
261
279
  end
262
280
 
263
281
  it "should call the prerun and postrun commands on a Configurer instance" do
264
- Puppet::Configurer.any_instance.expects(:execute_prerun_command)
265
- Puppet::Configurer.any_instance.expects(:execute_postrun_command)
282
+ Puppet::Configurer.any_instance.expects(:execute_prerun_command).returns(true)
283
+ Puppet::Configurer.any_instance.expects(:execute_postrun_command).returns(true)
266
284
 
267
285
  expect { @apply.main }.to exit_with 0
268
286
  end
@@ -274,7 +292,7 @@ describe Puppet::Application::Apply do
274
292
  end
275
293
 
276
294
  it "should save the last run summary" do
277
- Puppet.stubs(:[]).with(:noop).returns(false)
295
+ Puppet[:noop] = false
278
296
  report = Puppet::Transaction::Report.new("apply")
279
297
  Puppet::Transaction::Report.stubs(:new).returns(report)
280
298
 
@@ -283,25 +301,26 @@ describe Puppet::Application::Apply do
283
301
  end
284
302
 
285
303
  describe "with detailed_exitcodes" do
304
+ before :each do
305
+ @apply.options[:detailed_exitcodes] = true
306
+ end
307
+
286
308
  it "should exit with report's computed exit status" do
287
- Puppet.stubs(:[]).with(:noop).returns(false)
288
- @apply.options.stubs(:[]).with(:detailed_exitcodes).returns(true)
309
+ Puppet[:noop] = false
289
310
  Puppet::Transaction::Report.any_instance.stubs(:exit_status).returns(666)
290
311
 
291
312
  expect { @apply.main }.to exit_with 666
292
313
  end
293
314
 
294
315
  it "should exit with report's computed exit status, even if --noop is set" do
295
- Puppet.stubs(:[]).with(:noop).returns(true)
296
- @apply.options.stubs(:[]).with(:detailed_exitcodes).returns(true)
316
+ Puppet[:noop] = true
297
317
  Puppet::Transaction::Report.any_instance.stubs(:exit_status).returns(666)
298
318
 
299
319
  expect { @apply.main }.to exit_with 666
300
320
  end
301
321
 
302
322
  it "should always exit with 0 if option is disabled" do
303
- Puppet.stubs(:[]).with(:noop).returns(false)
304
- @apply.options.stubs(:[]).with(:detailed_exitcodes).returns(false)
323
+ Puppet[:noop] = false
305
324
  report = stub 'report', :exit_status => 666
306
325
  @transaction.stubs(:report).returns(report)
307
326
 
@@ -309,8 +328,7 @@ describe Puppet::Application::Apply do
309
328
  end
310
329
 
311
330
  it "should always exit with 0 if --noop" do
312
- Puppet.stubs(:[]).with(:noop).returns(true)
313
- @apply.options.stubs(:[]).with(:detailed_exitcodes).returns(true)
331
+ Puppet[:noop] = true
314
332
  report = stub 'report', :exit_status => 666
315
333
  @transaction.stubs(:report).returns(report)
316
334
 
@@ -208,5 +208,15 @@ describe Puppet::Application::Cert, :'fails_on_ruby_1.9.2' => true do
208
208
  args.should == ["fun.example.com"]
209
209
  end
210
210
  end
211
+
212
+ it "should print help and exit if there is no subcommand" do
213
+ args = []
214
+ @cert_app.command_line.stubs(:args).returns(args)
215
+ @cert_app.stubs(:help).returns("I called for help!")
216
+ @cert_app.expects(:puts).with("I called for help!")
217
+
218
+ expect { @cert_app.parse_options }.to exit_with 0
219
+ @cert_app.subcommand.should be_nil
220
+ end
211
221
  end
212
222
  end
@@ -1,6 +1,5 @@
1
- #!/usr/bin/env ruby
2
-
3
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ #!/usr/bin/env rspec
2
+ require 'spec_helper'
4
3
 
5
4
  require 'puppet/application/device'
6
5
  require 'puppet/util/network_device/config'
@@ -55,6 +55,7 @@ describe Puppet::Application::FaceBase do
55
55
  it "should stop if the first thing found is not an action" do
56
56
  app.command_line.stubs(:args).returns %w{banana count_args}
57
57
  expect { app.run }.to exit_with 1
58
+ @logs.first.should_not be_nil
58
59
  @logs.first.message.should =~ /has no 'banana' action/
59
60
  end
60
61
 
@@ -16,6 +16,7 @@ describe Puppet::Application::Facts do
16
16
  end
17
17
 
18
18
  it "should return facts if a key is given to find", :'fails_on_ruby_1.9.2' => true do
19
+ Puppet::Node::Facts.indirection.reset_terminus_class
19
20
  subject.command_line.stubs(:args).returns %w{find whatever --render-as yaml}
20
21
 
21
22
  expect {