summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielsdeleo <dan@getchef.com>2014-04-22 19:20:47 -0700
committerdanielsdeleo <dan@getchef.com>2014-04-24 09:49:52 -0700
commitbfc0b5a5f5e7cc5255a2bc20b50cc2599ec4d7f6 (patch)
tree675a7deadde55166f332fdc8ed84fff964e1a848
parenta84653e5f57109e3ac153ef686c9230da19da21d (diff)
downloadchef-bfc0b5a5f5e7cc5255a2bc20b50cc2599ec4d7f6.tar.gz
Prevent tests from overriding rspec's trap handler
Otherwise you cannot ctrl-C the tests.
-rw-r--r--lib/chef/application.rb33
-rw-r--r--spec/unit/application/client_spec.rb3
-rw-r--r--spec/unit/application/knife_spec.rb1
-rw-r--r--spec/unit/application/solo_spec.rb2
-rw-r--r--spec/unit/application_spec.rb1
5 files changed, 26 insertions, 14 deletions
diff --git a/lib/chef/application.rb b/lib/chef/application.rb
index a943326d95..1683ed8861 100644
--- a/lib/chef/application.rb
+++ b/lib/chef/application.rb
@@ -35,20 +35,6 @@ class Chef::Application
@chef_client = nil
@chef_client_json = nil
- trap("INT") do
- Chef::Application.fatal!("SIGINT received, stopping", 2)
- end
-
- unless Chef::Platform.windows?
- trap("QUIT") do
- Chef::Log.info("SIGQUIT received, call stack:\n " + caller.join("\n "))
- end
-
- trap("HUP") do
- Chef::Log.info("SIGHUP received, reconfiguring")
- reconfigure
- end
- end
# Always switch to a readable directory. Keeps subsequent Dir.chdir() {}
# from failing due to permissions when launched as a less privileged user.
@@ -62,11 +48,30 @@ class Chef::Application
# Get this party started
def run
+ setup_signal_handlers
reconfigure
setup_application
run_application
end
+ def setup_signal_handlers
+ trap("INT") do
+ Chef::Application.fatal!("SIGINT received, stopping", 2)
+ end
+
+ unless Chef::Platform.windows?
+ trap("QUIT") do
+ Chef::Log.info("SIGQUIT received, call stack:\n " + caller.join("\n "))
+ end
+
+ trap("HUP") do
+ Chef::Log.info("SIGHUP received, reconfiguring")
+ reconfigure
+ end
+ end
+ end
+
+
# Parse configuration (options and config file)
def configure_chef
parse_options
diff --git a/spec/unit/application/client_spec.rb b/spec/unit/application/client_spec.rb
index 90a468b0a2..b3e9858a64 100644
--- a/spec/unit/application/client_spec.rb
+++ b/spec/unit/application/client_spec.rb
@@ -19,10 +19,13 @@ require 'spec_helper'
describe Chef::Application::Client, "reconfigure" do
before do
+ Kernel.stub(:trap).and_return(:ok)
+
@original_argv = ARGV.dup
ARGV.clear
@app = Chef::Application::Client.new
+ @app.stub(:trap)
@app.stub(:configure_opt_parser).and_return(true)
@app.stub(:configure_chef).and_return(true)
@app.stub(:configure_logging).and_return(true)
diff --git a/spec/unit/application/knife_spec.rb b/spec/unit/application/knife_spec.rb
index 1baaad110d..12dc0ff940 100644
--- a/spec/unit/application/knife_spec.rb
+++ b/spec/unit/application/knife_spec.rb
@@ -36,6 +36,7 @@ describe Chef::Application::Knife do
before(:each) do
@knife = Chef::Application::Knife.new
@knife.stub(:puts)
+ @knife.stub(:trap)
Chef::Knife.stub(:list_commands)
end
diff --git a/spec/unit/application/solo_spec.rb b/spec/unit/application/solo_spec.rb
index d2f8b93169..dfc54db4b0 100644
--- a/spec/unit/application/solo_spec.rb
+++ b/spec/unit/application/solo_spec.rb
@@ -19,10 +19,12 @@ require 'spec_helper'
describe Chef::Application::Solo do
before do
+ Kernel.stub(:trap).and_return(:ok)
@app = Chef::Application::Solo.new
@app.stub(:configure_opt_parser).and_return(true)
@app.stub(:configure_chef).and_return(true)
@app.stub(:configure_logging).and_return(true)
+ @app.stub(:trap)
Chef::Config[:recipe_url] = false
Chef::Config[:json_attribs] = false
Chef::Config[:solo] = true
diff --git a/spec/unit/application_spec.rb b/spec/unit/application_spec.rb
index 6110a8a3c5..90e855e889 100644
--- a/spec/unit/application_spec.rb
+++ b/spec/unit/application_spec.rb
@@ -24,6 +24,7 @@ describe Chef::Application do
ARGV.clear
Chef::Log.logger = Logger.new(StringIO.new)
@app = Chef::Application.new
+ @app.stub(:trap)
Dir.stub(:chdir).and_return(0)
@app.stub(:reconfigure)
Chef::Log.init(STDERR)