summaryrefslogtreecommitdiffstats
path: root/spec/unit/application
diff options
context:
space:
mode:
authorDaniel Pittman <daniel@puppetlabs.com>2011-05-12 14:31:01 -0700
committerDaniel Pittman <daniel@puppetlabs.com>2011-05-12 14:31:01 -0700
commit82fb02ce27c95d8326335a8d52a9ab7e676fe8d3 (patch)
tree6706dc7afa05bf4bbffb2ab7e616717fb6af0c86 /spec/unit/application
parent7f9c9e1089c4bc36d52fcdd9751de559c658bf8d (diff)
parent704623cb95aacb0544609620994dc36f61a4b463 (diff)
downloadpuppet-82fb02ce27c95d8326335a8d52a9ab7e676fe8d3.tar.gz
puppet-82fb02ce27c95d8326335a8d52a9ab7e676fe8d3.tar.xz
puppet-82fb02ce27c95d8326335a8d52a9ab7e676fe8d3.zip
Merge branch 'next'
Diffstat (limited to 'spec/unit/application')
-rwxr-xr-xspec/unit/application/agent_spec.rb46
-rwxr-xr-xspec/unit/application/apply_spec.rb54
-rwxr-xr-xspec/unit/application/cert_spec.rb10
-rwxr-xr-xspec/unit/application/device_spec.rb3
-rwxr-xr-xspec/unit/application/doc_spec.rb16
-rwxr-xr-xspec/unit/application/face_base_spec.rb169
-rwxr-xr-xspec/unit/application/facts_spec.rb27
-rwxr-xr-xspec/unit/application/filebucket_spec.rb10
-rwxr-xr-xspec/unit/application/indirection_base_spec.rb10
-rwxr-xr-xspec/unit/application/inspect_spec.rb2
-rwxr-xr-xspec/unit/application/kick_spec.rb30
-rwxr-xr-xspec/unit/application/master_spec.rb23
-rwxr-xr-xspec/unit/application/queue_spec.rb10
-rwxr-xr-xspec/unit/application/resource_spec.rb4
-rwxr-xr-xspec/unit/application/secret_agent_spec.rb (renamed from spec/unit/application/configurer_spec.rb)6
15 files changed, 215 insertions, 205 deletions
diff --git a/spec/unit/application/agent_spec.rb b/spec/unit/application/agent_spec.rb
index b30a8cc6c..c4f8e7176 100755
--- a/spec/unit/application/agent_spec.rb
+++ b/spec/unit/application/agent_spec.rb
@@ -253,19 +253,16 @@ describe Puppet::Application::Agent do
end
it "should print puppet config if asked to in Puppet config" do
- @puppetd.stubs(:exit)
Puppet[:configprint] = "pluginsync"
-
- Puppet.settings.expects(:print_configs)
-
- @puppetd.setup
+ Puppet.settings.expects(:print_configs).returns true
+ expect { @puppetd.setup }.to exit_with 0
end
it "should exit after printing puppet config if asked to in Puppet config" do
Puppet[:modulepath] = '/my/path'
Puppet[:configprint] = "modulepath"
Puppet::Util::Settings.any_instance.expects(:puts).with('/my/path')
- lambda { @puppetd.setup }.should raise_error(SystemExit)
+ expect { @puppetd.setup }.to exit_with 0
end
it "should set a central log destination with --centrallogs" do
@@ -346,17 +343,14 @@ describe Puppet::Application::Agent do
describe "when enabling or disabling agent" do
[:enable, :disable].each do |action|
it "should call client.#{action}" do
- @puppetd.stubs(:exit)
@puppetd.options.stubs(:[]).with(action).returns(true)
-
@agent.expects(action)
-
- @puppetd.enable_disable_client(@agent)
+ expect { @puppetd.enable_disable_client(@agent) }.to exit_with 0
end
end
it "should finally exit" do
- lambda { @puppetd.enable_disable_client(@agent) }.should raise_error(SystemExit)
+ expect { @puppetd.enable_disable_client(@agent) }.to exit_with 0
end
end
@@ -410,7 +404,6 @@ describe Puppet::Application::Agent do
FileTest.stubs(:exists?).with('auth').returns(true)
File.stubs(:exist?).returns(true)
@puppetd.options.stubs(:[]).with(:serve).returns([])
- @puppetd.stubs(:exit)
@server = stub_everything 'server'
Puppet::Network::Server.stubs(:new).returns(@server)
end
@@ -418,11 +411,8 @@ describe Puppet::Application::Agent do
it "should exit if no authorization file" do
Puppet.stubs(:err)
- FileTest.stubs(:exists?).with(Puppet[:authconfig]).returns(false)
-
- @puppetd.expects(:exit)
-
- @puppetd.setup_listen
+ FileTest.stubs(:exists?).with(Puppet[:rest_authconfig]).returns(false)
+ expect { @puppetd.setup_listen }.to exit_with 14
end
it "should create a server to listen on at least the Runner handler" do
@@ -483,35 +473,27 @@ describe Puppet::Application::Agent do
@agent.stubs(:run).returns(:report)
@puppetd.options.stubs(:[]).with(:client).returns(:client)
@puppetd.options.stubs(:[]).with(:detailed_exitcodes).returns(false)
- @puppetd.stubs(:exit).with(0)
Puppet.stubs(:newservice)
end
it "should exit if no defined --client" do
$stderr.stubs(:puts)
@puppetd.options.stubs(:[]).with(:client).returns(nil)
-
- @puppetd.expects(:exit).with(43)
-
- @puppetd.onetime
+ expect { @puppetd.onetime }.to exit_with 43
end
it "should setup traps" do
@daemon.expects(:set_signal_traps)
-
- @puppetd.onetime
+ expect { @puppetd.onetime }.to exit_with 0
end
it "should let the agent run" do
@agent.expects(:run).returns(:report)
-
- @puppetd.onetime
+ expect { @puppetd.onetime }.to exit_with 0
end
it "should finish by exiting with 0 error code" do
- @puppetd.expects(:exit).with(0)
-
- @puppetd.onetime
+ expect { @puppetd.onetime }.to exit_with 0
end
describe "and --detailed-exitcodes" do
@@ -523,18 +505,16 @@ describe Puppet::Application::Agent do
Puppet[:noop] = false
report = stub 'report', :exit_status => 666
@agent.stubs(:run).returns(report)
- @puppetd.expects(:exit).with(666)
- @puppetd.onetime
+ expect { @puppetd.onetime }.to exit_with 666
end
it "should exit with the report's computer exit status, even if --noop is set." do
Puppet[:noop] = true
report = stub 'report', :exit_status => 666
@agent.stubs(:run).returns(report)
- @puppetd.expects(:exit).with(666)
- @puppetd.onetime
+ expect { @puppetd.onetime }.to exit_with 666
end
end
end
diff --git a/spec/unit/application/apply_spec.rb b/spec/unit/application/apply_spec.rb
index ec3f083db..74c883a3e 100755
--- a/spec/unit/application/apply_spec.rb
+++ b/spec/unit/application/apply_spec.rb
@@ -93,18 +93,14 @@ describe Puppet::Application::Apply do
end
it "should print puppet config if asked to in Puppet config" do
- @apply.stubs(:exit)
- Puppet.settings.stubs(:print_configs?).returns(true)
-
- Puppet.settings.expects(:print_configs)
-
- @apply.setup
+ Puppet.settings.stubs(:print_configs?).returns true
+ Puppet.settings.expects(:print_configs).returns true
+ expect { @apply.setup }.to exit_with 0
end
it "should exit after printing puppet config if asked to in Puppet config" do
Puppet.settings.stubs(:print_configs?).returns(true)
-
- lambda { @apply.setup }.should raise_error(SystemExit)
+ expect { @apply.setup }.to exit_with 1
end
it "should tell the report handler to cache locally as yaml" do
@@ -155,8 +151,6 @@ describe Puppet::Application::Apply do
@transaction = stub_everything 'transaction'
@catalog.stubs(:apply).returns(@transaction)
- @apply.stubs(:exit)
-
Puppet::Util::Storage.stubs(:load)
Puppet::Configurer.any_instance.stubs(:save_last_run_summary) # to prevent it from trying to write files
end
@@ -165,7 +159,7 @@ describe Puppet::Application::Apply do
@apply.options.stubs(:[]).with(:code).returns("code to run")
Puppet.expects(:[]=).with(:code,"code to run")
- @apply.main
+ expect { @apply.main }.to exit_with 0
end
it "should set the code to run from STDIN if no arguments" do
@@ -174,7 +168,7 @@ describe Puppet::Application::Apply do
Puppet.expects(:[]=).with(:code,"code to run")
- @apply.main
+ expect { @apply.main }.to exit_with 0
end
it "should set the manifest if a file is passed on command line and the file exists" do
@@ -183,7 +177,7 @@ describe Puppet::Application::Apply do
Puppet.expects(:[]=).with(:manifest,"site.pp")
- @apply.main
+ expect { @apply.main }.to exit_with 0
end
it "should raise an error if a file is passed on command line and the file does not exist" do
@@ -200,13 +194,13 @@ describe Puppet::Application::Apply do
Puppet.expects(:[]=).with(:manifest,"starwarsIV")
Puppet.expects(:warning).with('Only one file can be applied per run. Skipping starwarsI, starwarsII')
- @apply.main
+ expect { @apply.main }.to exit_with 0
end
it "should collect the node facts" do
Puppet::Node::Facts.indirection.expects(:find).returns(@facts)
- @apply.main
+ expect { @apply.main }.to exit_with 0
end
it "should raise an error if we can't find the node" do
@@ -218,7 +212,7 @@ describe Puppet::Application::Apply do
it "should look for the node" do
Puppet::Node.indirection.expects(:find).returns(@node)
- @apply.main
+ expect { @apply.main }.to exit_with 0
end
it "should raise an error if we can't find the node" do
@@ -232,7 +226,7 @@ describe Puppet::Application::Apply do
@node.expects(:merge).with("values")
- @apply.main
+ expect { @apply.main }.to exit_with 0
end
it "should load custom classes if loadclasses" do
@@ -244,39 +238,39 @@ describe Puppet::Application::Apply do
@node.expects(:classes=)
- @apply.main
+ expect { @apply.main }.to exit_with 0
end
it "should compile the catalog" do
Puppet::Resource::Catalog.indirection.expects(:find).returns(@catalog)
- @apply.main
+ expect { @apply.main }.to exit_with 0
end
it "should transform the catalog to ral" do
@catalog.expects(:to_ral).returns(@catalog)
- @apply.main
+ expect { @apply.main }.to exit_with 0
end
it "should finalize the catalog" do
@catalog.expects(:finalize)
- @apply.main
+ expect { @apply.main }.to exit_with 0
end
it "should call the prerun and postrun commands on a Configurer instance" do
Puppet::Configurer.any_instance.expects(:execute_prerun_command)
Puppet::Configurer.any_instance.expects(:execute_postrun_command)
- @apply.main
+ expect { @apply.main }.to exit_with 0
end
it "should apply the catalog" do
@catalog.expects(:apply).returns(stub_everything('transaction'))
- @apply.main
+ expect { @apply.main }.to exit_with 0
end
it "should save the last run summary" do
@@ -285,7 +279,7 @@ describe Puppet::Application::Apply do
Puppet::Transaction::Report.stubs(:new).returns(report)
Puppet::Configurer.any_instance.expects(:save_last_run_summary).with(report)
- @apply.main
+ expect { @apply.main }.to exit_with 0
end
describe "with detailed_exitcodes" do
@@ -293,18 +287,16 @@ describe Puppet::Application::Apply do
Puppet.stubs(:[]).with(:noop).returns(false)
@apply.options.stubs(:[]).with(:detailed_exitcodes).returns(true)
Puppet::Transaction::Report.any_instance.stubs(:exit_status).returns(666)
- @apply.expects(:exit).with(666)
- @apply.main
+ expect { @apply.main }.to exit_with 666
end
it "should exit with report's computed exit status, even if --noop is set" do
Puppet.stubs(:[]).with(:noop).returns(true)
@apply.options.stubs(:[]).with(:detailed_exitcodes).returns(true)
Puppet::Transaction::Report.any_instance.stubs(:exit_status).returns(666)
- @apply.expects(:exit).with(666)
- @apply.main
+ expect { @apply.main }.to exit_with 666
end
it "should always exit with 0 if option is disabled" do
@@ -312,9 +304,8 @@ describe Puppet::Application::Apply do
@apply.options.stubs(:[]).with(:detailed_exitcodes).returns(false)
report = stub 'report', :exit_status => 666
@transaction.stubs(:report).returns(report)
- @apply.expects(:exit).with(0)
- @apply.main
+ expect { @apply.main }.to exit_with 0
end
it "should always exit with 0 if --noop" do
@@ -322,9 +313,8 @@ describe Puppet::Application::Apply do
@apply.options.stubs(:[]).with(:detailed_exitcodes).returns(true)
report = stub 'report', :exit_status => 666
@transaction.stubs(:report).returns(report)
- @apply.expects(:exit).with(0)
- @apply.main
+ expect { @apply.main }.to exit_with 0
end
end
end
diff --git a/spec/unit/application/cert_spec.rb b/spec/unit/application/cert_spec.rb
index 4a91c1e6c..1b1c61ab4 100755
--- a/spec/unit/application/cert_spec.rb
+++ b/spec/unit/application/cert_spec.rb
@@ -79,18 +79,14 @@ describe Puppet::Application::Cert do
end
it "should print puppet config if asked to in Puppet config" do
- @cert_app.stubs(:exit)
Puppet.settings.stubs(:print_configs?).returns(true)
-
- Puppet.settings.expects(:print_configs)
-
- @cert_app.setup
+ Puppet.settings.expects(:print_configs).returns true
+ expect { @cert_app.setup }.to exit_with 0
end
it "should exit after printing puppet config if asked to in Puppet config" do
Puppet.settings.stubs(:print_configs?).returns(true)
-
- lambda { @cert_app.setup }.should raise_error(SystemExit)
+ expect { @cert_app.setup }.to exit_with 1
end
it "should set the CA location to 'only'" do
diff --git a/spec/unit/application/device_spec.rb b/spec/unit/application/device_spec.rb
index 832b7e55b..df8cd3eaf 100755
--- a/spec/unit/application/device_spec.rb
+++ b/spec/unit/application/device_spec.rb
@@ -260,8 +260,7 @@ describe Puppet::Application::Device do
end
it "should exit if the device list is empty" do
- @device.expects(:exit).with(1)
- @device.main
+ expect { @device.main }.to exit_with 1
end
describe "for each device" do
diff --git a/spec/unit/application/doc_spec.rb b/spec/unit/application/doc_spec.rb
index 43a4b9849..971378cd4 100755
--- a/spec/unit/application/doc_spec.rb
+++ b/spec/unit/application/doc_spec.rb
@@ -106,9 +106,8 @@ describe Puppet::Application::Doc do
Puppet::Util::Reference.expects(:reference).with(reference).returns(ref)
ref.expects(:doc)
- @doc.expects(:exit)
- @doc.handle_list(nil)
+ expect { @doc.handle_list(nil) }.to exit_with 0
end
it "should add reference to references list with --reference" do
@@ -279,7 +278,6 @@ describe Puppet::Application::Doc do
Puppet.settings.stubs(:[]=).with(:document_all, false)
Puppet.settings.stubs(:setdefaults)
Puppet::Util::RDoc.stubs(:rdoc)
- @doc.stubs(:exit)
File.stubs(:expand_path).with('modules').returns('modules')
File.stubs(:expand_path).with('manifests').returns('manifests')
@doc.command_line.stubs(:args).returns([])
@@ -289,30 +287,30 @@ describe Puppet::Application::Doc do
@doc.options.expects(:[]).with(:all).returns(true)
Puppet.settings.expects(:[]=).with(:document_all, true)
- @doc.rdoc
+ expect { @doc.rdoc }.to exit_with 0
end
it "should call Puppet::Util::RDoc.rdoc in full mode" do
Puppet::Util::RDoc.expects(:rdoc).with('doc', ['modules','manifests'], nil)
- @doc.rdoc
+ expect { @doc.rdoc }.to exit_with 0
end
it "should call Puppet::Util::RDoc.rdoc with a charset if --charset has been provided" do
@doc.options.expects(:[]).with(:charset).returns("utf-8")
Puppet::Util::RDoc.expects(:rdoc).with('doc', ['modules','manifests'], "utf-8")
- @doc.rdoc
+ expect { @doc.rdoc }.to exit_with 0
end
it "should call Puppet::Util::RDoc.rdoc in full mode with outputdir set to doc if no --outputdir" do
@doc.options.expects(:[]).with(:outputdir).returns(false)
Puppet::Util::RDoc.expects(:rdoc).with('doc', ['modules','manifests'], nil)
- @doc.rdoc
+ expect { @doc.rdoc }.to exit_with 0
end
it "should call Puppet::Util::RDoc.manifestdoc in manifest mode" do
@doc.manifest = true
Puppet::Util::RDoc.expects(:manifestdoc)
- @doc.rdoc
+ expect { @doc.rdoc }.to exit_with 0
end
it "should get modulepath and manifestdir values from the environment" do
@@ -321,7 +319,7 @@ describe Puppet::Application::Doc do
Puppet::Util::RDoc.expects(:rdoc).with('doc', ['envmodules1','envmodules2','envmanifests'], nil)
- @doc.rdoc
+ expect { @doc.rdoc }.to exit_with 0
end
end
diff --git a/spec/unit/application/face_base_spec.rb b/spec/unit/application/face_base_spec.rb
index f7c55c556..2a9a22356 100755
--- a/spec/unit/application/face_base_spec.rb
+++ b/spec/unit/application/face_base_spec.rb
@@ -7,18 +7,6 @@ class Puppet::Application::FaceBase::Basetest < Puppet::Application::FaceBase
end
describe Puppet::Application::FaceBase do
- before :all do
- Puppet::Face.define(:basetest, '0.0.1') do
- option("--[no-]boolean")
- option("--mandatory MANDATORY")
-
- action :foo do
- option("--action")
- when_invoked { |*args| args.length }
- end
- end
- end
-
let :app do
app = Puppet::Application::FaceBase::Basetest.new
app.command_line.stubs(:subcommand_name).returns('subcommand')
@@ -66,7 +54,7 @@ describe Puppet::Application::FaceBase do
it "should use the default action if not given any arguments" do
app.command_line.stubs(:args).returns []
- action = stub(:options => [])
+ action = stub(:options => [], :render_as => nil)
Puppet::Face[:basetest, '0.0.1'].expects(:get_default_action).returns(action)
app.stubs(:main)
app.run
@@ -76,7 +64,7 @@ describe Puppet::Application::FaceBase do
it "should use the default action if not given a valid one" do
app.command_line.stubs(:args).returns %w{bar}
- action = stub(:options => [])
+ action = stub(:options => [], :render_as => nil)
Puppet::Face[:basetest, '0.0.1'].expects(:get_default_action).returns(action)
app.stubs(:main)
app.run
@@ -88,9 +76,8 @@ describe Puppet::Application::FaceBase do
app.command_line.stubs(:args).returns %w{bar}
Puppet::Face[:basetest, '0.0.1'].expects(:get_default_action).returns(nil)
app.stubs(:main)
- app.run
- app.action.should be_nil
- app.arguments.should == [ 'bar', { } ]
+ expect { app.run }.to exit_with 1
+ @logs.first.message.should =~ /does not have a default action/
end
it "should report a sensible error when options with = fail" do
@@ -162,7 +149,7 @@ describe Puppet::Application::FaceBase do
end
it "should handle application-level options" do
- app.command_line.stubs(:args).returns %w{help --verbose help}
+ app.command_line.stubs(:args).returns %w{basetest --verbose return_true}
app.preinit
app.parse_options
app.face.name.should == :basetest
@@ -189,7 +176,7 @@ describe Puppet::Application::FaceBase do
describe "#main" do
before :each do
- app.expects(:exit).with(0)
+ app.stubs(:puts) # don't dump text to screen.
app.face = Puppet::Face[:basetest, '0.0.1']
app.action = app.face.get_action(:foo)
@@ -198,69 +185,101 @@ describe Puppet::Application::FaceBase do
it "should send the specified verb and name to the face" do
app.face.expects(:foo).with(*app.arguments)
- app.main
+ expect { app.main }.to exit_with 0
end
it "should lookup help when it cannot do anything else" do
app.action = nil
- Puppet::Face[:help, :current].expects(:help).with(:basetest, *app.arguments)
- app.stubs(:puts) # meh. Don't print nil, thanks. --daniel 2011-04-12
- app.main
+ Puppet::Face[:help, :current].expects(:help).with(:basetest)
+ expect { app.main }.to exit_with 1
end
it "should use its render method to render any result" do
app.expects(:render).with(app.arguments.length + 1)
- app.stubs(:puts) # meh. Don't print nil, thanks. --daniel 2011-04-12
- app.main
+ expect { app.main }.to exit_with 0
end
end
- describe "#render" do
+ describe "error reporting" do
before :each do
- app.face = Puppet::Face[:basetest, '0.0.1']
- app.action = app.face.get_action(:foo)
+ app.stubs(:puts) # don't dump text to screen.
+
+ app.render_as = :json
+ app.face = Puppet::Face[:basetest, '0.0.1']
+ app.arguments = [{}] # we always have options in there...
end
- ["hello", 1, 1.0].each do |input|
- it "should just return a #{input.class.name}" do
- app.render(input).should == input
- end
+ it "should exit 0 when the action returns true" do
+ app.action = app.face.get_action :return_true
+ expect { app.main }.to exit_with 0
end
- [[1, 2], ["one"], [{ 1 => 1 }]].each do |input|
- it "should render #{input.class} using the 'pp' library" do
- app.render(input).should == input.pretty_inspect
- end
+ it "should exit 0 when the action returns false" do
+ app.action = app.face.get_action :return_false
+ expect { app.main }.to exit_with 0
+ end
+
+ it "should exit 0 when the action returns nil" do
+ app.action = app.face.get_action :return_nil
+ expect { app.main }.to exit_with 0
+ end
+
+ it "should exit non-0 when the action raises" do
+ app.action = app.face.get_action :return_raise
+ expect { app.main }.not_to exit_with 0
end
+ end
- it "should render a non-trivially-keyed Hash with the 'pp' library" do
- hash = { [1,2] => 3, [2,3] => 5, [3,4] => 7 }
- app.render(hash).should == hash.pretty_inspect
+ describe "#render" do
+ before :each do
+ app.face = Puppet::Face[:basetest, '0.0.1']
+ app.action = app.face.get_action(:foo)
end
- it "should render a {String,Numeric}-keyed Hash into a table" do
- object = Object.new
- hash = { "one" => 1, "two" => [], "three" => {}, "four" => object,
- 5 => 5, 6.0 => 6 }
+ context "default rendering" do
+ before :each do app.setup end
- # Gotta love ASCII-betical sort order. Hope your objects are better
- # structured for display than my test one is. --daniel 2011-04-18
- app.render(hash).should == <<EOT
+ ["hello", 1, 1.0].each do |input|
+ it "should just return a #{input.class.name}" do
+ app.render(input).should == input
+ end
+ end
+
+ [[1, 2], ["one"], [{ 1 => 1 }]].each do |input|
+ it "should render #{input.class} using JSON" do
+ app.render(input).should == input.to_pson.chomp
+ end
+ end
+
+ it "should render a non-trivially-keyed Hash with using JSON" do
+ hash = { [1,2] => 3, [2,3] => 5, [3,4] => 7 }
+ app.render(hash).should == hash.to_pson.chomp
+ end
+
+ it "should render a {String,Numeric}-keyed Hash into a table" do
+ object = Object.new
+ hash = { "one" => 1, "two" => [], "three" => {}, "four" => object,
+ 5 => 5, 6.0 => 6 }
+
+ # Gotta love ASCII-betical sort order. Hope your objects are better
+ # structured for display than my test one is. --daniel 2011-04-18
+ app.render(hash).should == <<EOT
5 5
6.0 6
-four #{object.pretty_inspect.chomp}
+four #{object.to_pson.chomp}
one 1
three {}
two []
EOT
- end
+ end
- it "should render a hash nicely with a multi-line value" do
- hash = {
- "number" => { "1" => '1' * 40, "2" => '2' * 40, '3' => '3' * 40 },
- "text" => { "a" => 'a' * 40, 'b' => 'b' * 40, 'c' => 'c' * 40 }
- }
- app.render(hash).should == <<EOT
+ it "should render a hash nicely with a multi-line value" do
+ pending "Moving to PSON rather than PP makes this unsupportable."
+ hash = {
+ "number" => { "1" => '1' * 40, "2" => '2' * 40, '3' => '3' * 40 },
+ "text" => { "a" => 'a' * 40, 'b' => 'b' * 40, 'c' => 'c' * 40 }
+ }
+ app.render(hash).should == <<EOT
number {"1"=>"1111111111111111111111111111111111111111",
"2"=>"2222222222222222222222222222222222222222",
"3"=>"3333333333333333333333333333333333333333"}
@@ -268,12 +287,46 @@ text {"a"=>"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"b"=>"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"c"=>"cccccccccccccccccccccccccccccccccccccccc"}
EOT
+ end
+
+ it "should invoke the action rendering hook while rendering" do
+ app.action.set_rendering_method_for(:console, proc { |value| "bi-winning!" })
+ app.render("bi-polar?").should == "bi-winning!"
+ end
+
+ it "should render JSON when asked for json" do
+ app.render_as = :json
+ json = app.render({ :one => 1, :two => 2 })
+ json.should =~ /"one":\s*1\b/
+ json.should =~ /"two":\s*2\b/
+ PSON.parse(json).should == { "one" => 1, "two" => 2 }
+ end
+ end
+
+ it "should fail early if asked to render an invalid format" do
+ app.command_line.stubs(:args).returns %w{--render-as interpretive-dance help help}
+ # We shouldn't get here, thanks to the exception, and our expectation on
+ # it, but this helps us fail if that slips up and all. --daniel 2011-04-27
+ Puppet::Face[:help, :current].expects(:help).never
+
+ expect {
+ expect { app.run }.to exit_with 1
+ }.to have_printed(/I don't know how to render 'interpretive-dance'/)
+ end
+
+ it "should work if asked to render a NetworkHandler format" do
+ app.command_line.stubs(:args).returns %w{dummy find dummy --render-as yaml}
+ expect {
+ expect { app.run }.to exit_with 0
+ }.to have_printed(/--- 3/)
end
- it "should invoke the action rendering hook while rendering" do
- app.action.set_rendering_method_for(:for_humans, proc { |value| "bi-winning!" })
- app.action.render_as = :for_humans
- app.render("bi-polar?").should == "bi-winning!"
+ it "should invoke when_rendering hook 's' when asked to render-as 's'" do
+ app.command_line.stubs(:args).returns %w{with_s_rendering_hook --render-as s}
+ app.action = app.face.get_action(:with_s_rendering_hook)
+ expect {
+ expect { app.run }.to exit_with 0
+ }.to have_printed(/you invoked the 's' rendering hook/)
end
end
end
diff --git a/spec/unit/application/facts_spec.rb b/spec/unit/application/facts_spec.rb
new file mode 100755
index 000000000..2981dc805
--- /dev/null
+++ b/spec/unit/application/facts_spec.rb
@@ -0,0 +1,27 @@
+#!/usr/bin/env rspec
+require 'spec_helper'
+require 'puppet/application/facts'
+
+describe Puppet::Application::Facts do
+ before :each do
+ subject.command_line.stubs(:subcommand_name).returns 'facts'
+ end
+
+ it "should fail if no key is given to find" do
+ subject.command_line.stubs(:args).returns %w{find}
+ expect {
+ expect { subject.run }.to exit_with 1
+ }.to have_printed /err: puppet facts find takes 1 argument, but you gave 0/
+ @logs.first.to_s.should =~ /puppet facts find takes 1 argument, but you gave 0/
+ end
+
+ it "should return facts if a key is given to find" do
+ subject.command_line.stubs(:args).returns %w{find whatever --render-as yaml}
+
+ expect {
+ expect { subject.run }.to exit_with 0
+ }.should have_printed(/object:Puppet::Node::Facts/)
+
+ @logs.should be_empty
+ end
+end
diff --git a/spec/unit/application/filebucket_spec.rb b/spec/unit/application/filebucket_spec.rb
index 92bc0410a..ee30e7d12 100755
--- a/spec/unit/application/filebucket_spec.rb
+++ b/spec/unit/application/filebucket_spec.rb
@@ -78,18 +78,14 @@ describe Puppet::Application::Filebucket do
end
it "should print puppet config if asked to in Puppet config" do
- @filebucket.stubs(:exit)
Puppet.settings.stubs(:print_configs?).returns(true)
-
- Puppet.settings.expects(:print_configs)
-
- @filebucket.setup
+ Puppet.settings.expects(:print_configs).returns(true)
+ expect { @filebucket.setup }.to exit_with 0
end
it "should exit after printing puppet config if asked to in Puppet config" do
Puppet.settings.stubs(:print_configs?).returns(true)
-
- lambda { @filebucket.setup }.should raise_error(SystemExit)
+ expect { @filebucket.setup }.to exit_with 1
end
describe "with local bucket" do
diff --git a/spec/unit/application/indirection_base_spec.rb b/spec/unit/application/indirection_base_spec.rb
index 57740384a..910774c14 100755
--- a/spec/unit/application/indirection_base_spec.rb
+++ b/spec/unit/application/indirection_base_spec.rb
@@ -1,14 +1,15 @@
#!/usr/bin/env rspec
require 'spec_helper'
require 'puppet/application/indirection_base'
-require 'puppet/face/indirector'
+require 'puppet/indirector/face'
########################################################################
# Stub for testing; the names are critical, sadly. --daniel 2011-03-30
class Puppet::Application::TestIndirection < Puppet::Application::IndirectionBase
end
-face = Puppet::Face::Indirector.define(:testindirection, '0.0.1') do
+face = Puppet::Indirector::Face.define(:testindirection, '0.0.1') do
+ summary "fake summary"
end
# REVISIT: This horror is required because we don't allow anything to be
# :current except for if it lives on, and is loaded from, disk. --daniel 2011-03-29
@@ -27,11 +28,12 @@ describe Puppet::Application::IndirectionBase do
Puppet::Indirector::Indirection.expects(:instance).
with(:testindirection).returns(terminus)
- subject.command_line.instance_variable_set('@args', %w{--terminus foo save})
+ subject.command_line.instance_variable_set('@args', %w{--terminus foo save bar})
# Not a very nice thing. :(
$stderr.stubs(:puts)
+ Puppet.stubs(:err)
- expect { subject.run }.should raise_error SystemExit
+ expect { subject.run }.to exit_with 0
end
end
diff --git a/spec/unit/application/inspect_spec.rb b/spec/unit/application/inspect_spec.rb
index fda61c6e4..571683f37 100755
--- a/spec/unit/application/inspect_spec.rb
+++ b/spec/unit/application/inspect_spec.rb
@@ -19,7 +19,7 @@ describe Puppet::Application::Inspect do
Puppet[:configprint] = "all"
Puppet.settings.expects(:print_configs).returns(true)
- lambda { @inspect.setup }.should raise_error(SystemExit)
+ expect { @inspect.setup }.to exit_with 0
end
it "should fail if reporting is turned off" do
diff --git a/spec/unit/application/kick_spec.rb b/spec/unit/application/kick_spec.rb
index 742c0fff6..b24e78452 100755
--- a/spec/unit/application/kick_spec.rb
+++ b/spec/unit/application/kick_spec.rb
@@ -184,9 +184,7 @@ describe Puppet::Application::Kick, :if => Puppet.features.posix? do
$stderr.stubs(:puts)
@kick.classes = ['class']
- @kick.expects(:exit).with(24)
-
- @kick.setup
+ expect { @kick.setup }.to exit_with 24
end
end
end
@@ -212,9 +210,7 @@ describe Puppet::Application::Kick, :if => Puppet.features.posix? do
describe "the test command" do
it "should exit with exit code 0 " do
- @kick.expects(:exit).with(0)
-
- @kick.test
+ expect { @kick.test }.to exit_with 0
end
end
@@ -226,7 +222,6 @@ describe Puppet::Application::Kick, :if => Puppet.features.posix? do
@kick.options.stubs(:[]).with(:foreground).returns(false)
@kick.options.stubs(:[]).with(:debug).returns(false)
@kick.stubs(:print)
- @kick.stubs(:exit)
@kick.preinit
@kick.stubs(:parse_options)
@kick.setup
@@ -236,17 +231,15 @@ describe Puppet::Application::Kick, :if => Puppet.features.posix? do
it "should create as much childs as --parallel" do
@kick.options.stubs(:[]).with(:parallel).returns(3)
@kick.hosts = ['host1', 'host2', 'host3']
- @kick.stubs(:exit).raises(SystemExit)
Process.stubs(:wait).returns(1).then.returns(2).then.returns(3).then.raises(Errno::ECHILD)
@kick.expects(:fork).times(3).returns(1).then.returns(2).then.returns(3)
- lambda { @kick.main }.should raise_error
+ expect { @kick.main }.to raise_error SystemExit
end
it "should delegate to run_for_host per host" do
@kick.hosts = ['host1', 'host2']
- @kick.stubs(:exit).raises(SystemExit)
@kick.stubs(:fork).returns(1).yields
Process.stubs(:wait).returns(1).then.raises(Errno::ECHILD)
@@ -272,31 +265,22 @@ describe Puppet::Application::Kick, :if => Puppet.features.posix? do
it "should call run on a Puppet::Run for the given host" do
Puppet::Run.indirection.expects(:save).with(@agent_run, 'https://host:8139/production/run/host').returns(@agent_run)
- @kick.run_for_host('host')
+ expect { @kick.run_for_host('host') }.to exit_with 0
end
it "should exit the child with 0 on success" do
@agent_run.stubs(:status).returns("success")
-
- @kick.expects(:exit).with(0)
-
- @kick.run_for_host('host')
+ expect { @kick.run_for_host('host') }.to exit_with 0
end
it "should exit the child with 3 on running" do
@agent_run.stubs(:status).returns("running")
-
- @kick.expects(:exit).with(3)
-
- @kick.run_for_host('host')
+ expect { @kick.run_for_host('host') }.to exit_with 3
end
it "should exit the child with 12 on unknown answer" do
@agent_run.stubs(:status).returns("whatever")
-
- @kick.expects(:exit).with(12)
-
- @kick.run_for_host('host')
+ expect { @kick.run_for_host('host') }.to exit_with 12
end
end
end
diff --git a/spec/unit/application/master_spec.rb b/spec/unit/application/master_spec.rb
index 2a24086f3..2f6a328e2 100755
--- a/spec/unit/application/master_spec.rb
+++ b/spec/unit/application/master_spec.rb
@@ -152,18 +152,14 @@ describe Puppet::Application::Master do
end
it "should print puppet config if asked to in Puppet config" do
- @master.stubs(:exit)
Puppet.settings.stubs(:print_configs?).returns(true)
-
- Puppet.settings.expects(:print_configs)
-
- @master.setup
+ Puppet.settings.expects(:print_configs).returns(true)
+ expect { @master.setup }.to exit_with 0
end
it "should exit after printing puppet config if asked to in Puppet config" do
Puppet.settings.stubs(:print_configs?).returns(true)
-
- lambda { @master.setup }.should raise_error(SystemExit)
+ expect { @master.setup }.to exit_with 1
end
it "should tell Puppet.settings to use :main,:ssl,:master and :metrics category" do
@@ -241,7 +237,6 @@ describe Puppet::Application::Master do
Puppet.stubs(:[]).with(:manifest).returns("site.pp")
Puppet.stubs(:err)
@master.stubs(:jj)
- @master.stubs(:exit)
Puppet.features.stubs(:pson?).returns true
end
@@ -255,7 +250,7 @@ describe Puppet::Application::Master do
Puppet::Resource::Catalog.indirection.expects(:find).with("foo").returns Puppet::Resource::Catalog.new
$stdout.stubs(:puts)
- @master.compile
+ expect { @master.compile }.to exit_with 0
end
it "should convert the catalog to a pure-resource catalog and use 'jj' to pretty-print the catalog" do
@@ -267,25 +262,21 @@ describe Puppet::Application::Master do
@master.options[:node] = "foo"
@master.expects(:jj).with("rescat")
- @master.compile
+ expect { @master.compile }.to exit_with 0
end
it "should exit with error code 30 if no catalog can be found" do
@master.options[:node] = "foo"
Puppet::Resource::Catalog.indirection.expects(:find).returns nil
- @master.expects(:exit).with(30)
$stderr.expects(:puts)
-
- @master.compile
+ expect { @master.compile }.to exit_with 30
end
it "should exit with error code 30 if there's a failure" do
@master.options[:node] = "foo"
Puppet::Resource::Catalog.indirection.expects(:find).raises ArgumentError
- @master.expects(:exit).with(30)
$stderr.expects(:puts)
-
- @master.compile
+ expect { @master.compile }.to exit_with 30
end
end
diff --git a/spec/unit/application/queue_spec.rb b/spec/unit/application/queue_spec.rb
index d71c879a9..15e3927a1 100755
--- a/spec/unit/application/queue_spec.rb
+++ b/spec/unit/application/queue_spec.rb
@@ -86,18 +86,14 @@ describe Puppet::Application::Queue do
end
it "should print puppet config if asked to in Puppet config" do
- @queue.stubs(:exit)
Puppet.settings.stubs(:print_configs?).returns(true)
-
- Puppet.settings.expects(:print_configs)
-
- @queue.setup
+ Puppet.settings.expects(:print_configs).returns(true)
+ expect { @queue.setup }.to exit_with 0
end
it "should exit after printing puppet config if asked to in Puppet config" do
Puppet.settings.stubs(:print_configs?).returns(true)
-
- lambda { @queue.setup }.should raise_error(SystemExit)
+ expect { @queue.setup }.to exit_with 1
end
it "should call setup_logs" do
diff --git a/spec/unit/application/resource_spec.rb b/spec/unit/application/resource_spec.rb
index af60f12c1..9ee6dd71b 100755
--- a/spec/unit/application/resource_spec.rb
+++ b/spec/unit/application/resource_spec.rb
@@ -77,10 +77,8 @@ describe Puppet::Application::Resource do
type2 = stub_everything 'type2', :name => :type2
Puppet::Type.stubs(:loadall)
Puppet::Type.stubs(:eachtype).multiple_yields(type1,type2)
- @resource.stubs(:exit)
-
@resource.expects(:puts).with(['type1','type2'])
- @resource.handle_types(nil)
+ expect { @resource.handle_types(nil) }.to exit_with 0
end
it "should add param to extra_params list" do
diff --git a/spec/unit/application/configurer_spec.rb b/spec/unit/application/secret_agent_spec.rb
index 791a367ea..eba936447 100755
--- a/spec/unit/application/configurer_spec.rb
+++ b/spec/unit/application/secret_agent_spec.rb
@@ -1,11 +1,11 @@
#!/usr/bin/env rspec
require 'spec_helper'
-require 'puppet/application/configurer'
+require 'puppet/application/secret_agent'
require 'puppet/indirector/catalog/rest'
require 'puppet/indirector/report/rest'
require 'tempfile'
-describe "Puppet::Application::Configurer" do
+describe "Puppet::Application::Secret_agent" do
it "should retrieve and apply a catalog and submit a report" do
pending "REVISIT: 2.7 changes broke this, and we want the merge published"
@@ -25,7 +25,7 @@ describe "Puppet::Application::Configurer" do
Puppet::Util::Log.stubs(:newdestination)
- Puppet::Application::Configurer.new.run
+ Puppet::Application::Secret_agent.new.run
@report.status.should == "changed"
end