From 435c826ead5c81c3eb7c47efe9c52e2e77c14666 Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Fri, 22 Apr 2011 14:40:56 -0700 Subject: maint: use the exit_with helper everywhere... Now we have the exit_with matcher, we should use it everywhere that we previously stubbed, expected, or caught the exit status in an ad-hoc way. Reviewed-By: Jesse Wolf --- spec/integration/application/doc_spec.rb | 4 +- spec/integration/transaction_spec.rb | 4 +- spec/unit/application/agent_spec.rb | 44 ++++++--------------- spec/unit/application/apply_spec.rb | 54 +++++++++++--------------- spec/unit/application/cert_spec.rb | 10 ++--- spec/unit/application/device_spec.rb | 3 +- spec/unit/application/doc_spec.rb | 16 ++++---- spec/unit/application/face_base_spec.rb | 22 ++--------- spec/unit/application/filebucket_spec.rb | 10 ++--- spec/unit/application/indirection_base_spec.rb | 2 +- spec/unit/application/inspect_spec.rb | 2 +- spec/unit/application/kick_spec.rb | 30 ++++---------- spec/unit/application/master_spec.rb | 23 ++++------- spec/unit/application/queue_spec.rb | 10 ++--- spec/unit/application/resource_spec.rb | 4 +- spec/unit/application_spec.rb | 20 ++++------ spec/unit/daemon_spec.rb | 16 +++----- spec/unit/ssl/host_spec.rb | 6 +-- 18 files changed, 90 insertions(+), 190 deletions(-) diff --git a/spec/integration/application/doc_spec.rb b/spec/integration/application/doc_spec.rb index df9b91608..c1e463033 100755 --- a/spec/integration/application/doc_spec.rb +++ b/spec/integration/application/doc_spec.rb @@ -36,8 +36,8 @@ describe Puppet::Application::Doc do Puppet[:modulepath] = modules_dir Puppet[:manifest] = site_file puppet.options[:mode] = :rdoc - puppet.expects(:exit).with(0) - puppet.run_command + + expect { puppet.run_command }.to exit_with 0 File.should be_exist('doc') ensure diff --git a/spec/integration/transaction_spec.rb b/spec/integration/transaction_spec.rb index 78d62fc51..0ff50f47c 100755 --- a/spec/integration/transaction_spec.rb +++ b/spec/integration/transaction_spec.rb @@ -275,7 +275,7 @@ describe Puppet::Transaction do it "should not attempt to evaluate resources with failed dependencies" do exec = Puppet::Type.type(:exec).new( - :command => "/bin/mkdir /this/path/cannot/possibly/exit", + :command => "/bin/mkdir /this/path/cannot/possibly/exist", :title => "mkdir" ) @@ -309,7 +309,7 @@ describe Puppet::Transaction do ) exec = Puppet::Type.type(:exec).new( - :command => "/bin/mkdir /this/path/cannot/possibly/exit", + :command => "/bin/mkdir /this/path/cannot/possibly/exist", :title => "mkdir", :notify => create_file1 ) diff --git a/spec/unit/application/agent_spec.rb b/spec/unit/application/agent_spec.rb index b30a8cc6c..2e946e6bb 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 @@ -419,10 +412,7 @@ 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 + 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..e6e598430 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') @@ -189,7 +177,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,20 +186,18 @@ 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 + 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 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 0d7554aae..833fb424e 100755 --- a/spec/unit/application/indirection_base_spec.rb +++ b/spec/unit/application/indirection_base_spec.rb @@ -33,6 +33,6 @@ describe Puppet::Application::IndirectionBase do # Not a very nice thing. :( $stderr.stubs(:puts) - 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_spec.rb b/spec/unit/application_spec.rb index de1ca1257..fc1bbceb6 100755 --- a/spec/unit/application_spec.rb +++ b/spec/unit/application_spec.rb @@ -27,11 +27,11 @@ describe Puppet::Application do end it "should not find classes outside the namespace" do - lambda { @klass.find("String") }.should raise_error(SystemExit) + expect { @klass.find("String") }.to exit_with 1 end it "should exit if it can't find a class" do - lambda { @klass.find("ThisShallNeverEverEverExistAsdf") }.should raise_error(SystemExit) + expect { @klass.find("ThisShallNeverEverEverExist") }.to exit_with 1 end end @@ -286,10 +286,8 @@ describe Puppet::Application do describe "when using --help" do it "should call exit" do - @app.expects(:exit) @app.stubs(:puts) - - @app.handle_help(nil) + expect { @app.handle_help(nil) }.to exit_with 0 end end @@ -301,8 +299,7 @@ describe Puppet::Application do it "should exit after printing the version" do @app.stubs(:puts) - - lambda { @app.handle_version(nil) }.should raise_error(SystemExit) + expect { @app.handle_version(nil) }.to exit_with 0 end end @@ -505,22 +502,19 @@ describe Puppet::Application do it "should warn and exit if no command can be called" do $stderr.expects(:puts) - @app.expects(:exit).with(1) - @app.run + expect { @app.run }.to exit_with 1 end it "should raise an error if dispatch returns no command" do @app.stubs(:get_command).returns(nil) $stderr.expects(:puts) - @app.expects(:exit).with(1) - @app.run + expect { @app.run }.to exit_with 1 end it "should raise an error if dispatch returns an invalid command" do @app.stubs(:get_command).returns(:this_function_doesnt_exist) $stderr.expects(:puts) - @app.expects(:exit).with(1) - @app.run + expect { @app.run }.to exit_with 1 end end diff --git a/spec/unit/daemon_spec.rb b/spec/unit/daemon_spec.rb index ed8dec2a3..e2679a966 100755 --- a/spec/unit/daemon_spec.rb +++ b/spec/unit/daemon_spec.rb @@ -86,7 +86,6 @@ describe Puppet::Daemon do describe "when stopping" do before do @daemon.stubs(:remove_pidfile) - @daemon.stubs(:exit) Puppet::Util::Log.stubs(:close_all) # to make the global safe to mock, set it to a subclass of itself, # then restore it in an after pass @@ -102,34 +101,29 @@ describe Puppet::Daemon do server = mock 'server' server.expects(:stop) @daemon.stubs(:server).returns server - - @daemon.stop + expect { @daemon.stop }.to exit_with 0 end it 'should request a stop from Puppet::Application' do Puppet::Application.expects(:stop!) - @daemon.stop + expect { @daemon.stop }.to exit_with 0 end it "should remove its pidfile" do @daemon.expects(:remove_pidfile) - - @daemon.stop + expect { @daemon.stop }.to exit_with 0 end it "should close all logs" do Puppet::Util::Log.expects(:close_all) - - @daemon.stop + expect { @daemon.stop }.to exit_with 0 end it "should exit unless called with ':exit => false'" do - @daemon.expects(:exit) - @daemon.stop + expect { @daemon.stop }.to exit_with 0 end it "should not exit if called with ':exit => false'" do - @daemon.expects(:exit).never @daemon.stop :exit => false end end diff --git a/spec/unit/ssl/host_spec.rb b/spec/unit/ssl/host_spec.rb index 2624c2234..d14da538e 100755 --- a/spec/unit/ssl/host_spec.rb +++ b/spec/unit/ssl/host_spec.rb @@ -681,16 +681,14 @@ describe Puppet::SSL::Host do @host.expects(:certificate).returns(nil) @host.expects(:generate).raises(RuntimeError) @host.expects(:puts) - @host.expects(:exit).with(1).raises(SystemExit) - lambda { @host.wait_for_cert(0) }.should raise_error(SystemExit) + expect { @host.wait_for_cert(0) }.to exit_with 1 end it "should exit if the wait time is 0 and it can neither find nor retrieve a certificate" do @host.stubs(:certificate).returns nil @host.expects(:generate) @host.expects(:puts) - @host.expects(:exit).with(1).raises(SystemExit) - lambda { @host.wait_for_cert(0) }.should raise_error(SystemExit) + expect { @host.wait_for_cert(0) }.to exit_with 1 end it "should sleep for the specified amount of time if no certificate is found after generating its certificate request" do -- cgit