Browse files

Prefer Slushy::Error to SystemExit

  • Loading branch information...
1 parent 4027943 commit 27e8d3f1ade6b83b022c83e1bea703af6fa77ee5 Sam Umbach and Larry Karnowski committed Apr 30, 2012
Showing with 14 additions and 17 deletions.
  1. +1 −0 lib/slushy.rb
  2. +2 −0 lib/slushy/error.rb
  3. +6 −12 lib/slushy/instance.rb
  4. +5 −5 spec/lib/instance_spec.rb
View
1 lib/slushy.rb
@@ -1,4 +1,5 @@
module Slushy; end
require 'slushy/version'
+require 'slushy/error'
require 'slushy/instance'
View
2 lib/slushy/error.rb
@@ -0,0 +1,2 @@
+class Slushy::Error < StandardError
+end
View
18 lib/slushy/instance.rb
@@ -1,8 +1,6 @@
require 'timeout'
class Slushy::Instance
- class AptInstallError < StandardError; end
-
attr_reader :connection, :instance_id
def self.launch(connection, config)
@@ -65,21 +63,17 @@ def run_command(command)
end
def run_command!(command)
- exit 1 unless run_command(command)
- end
-
- def run_apt_command!(command)
- raise AptInstallError unless run_command(command)
+ raise Slushy::Error.new("Failed running '#{command}'") unless run_command(command)
end
def apt_installs
- retry_block(5, [AptInstallError], "Command 'apt-get' failed") do
+ retry_block(5, [Slushy::Error], "Command 'apt-get' failed") do
puts "Updating apt cache..."
- run_apt_command!('sudo apt-get update')
+ run_command!('sudo apt-get update')
puts "Installing ruby..."
- run_apt_command!('sudo apt-get -y install ruby')
+ run_command!('sudo apt-get -y install ruby')
puts "Installing rubygems..."
- run_apt_command!('sudo apt-get -y install rubygems1.8')
+ run_command!('sudo apt-get -y install rubygems1.8')
end
end
@@ -114,7 +108,7 @@ def retry_block(times, errors, failure)
last_error = e
end
end
- exit 1 if !succeeded
+ raise Slushy::Error.new(failure) unless succeeded
retval
end
View
10 spec/lib/instance_spec.rb
@@ -91,12 +91,12 @@ def mock_job(options={})
stdout.should include 'Attempting retry 3...'
end
- it 'retries up to five times, then aborts' do
+ it 'retries up to five times, then fails' do
instance.should_receive(:ssh).exactly(5).times.and_raise(Errno::ECONNREFUSED)
instance.stub(:sleep).and_return(10)
expect do
capture_stdout { instance.wait_for_connectivity }
- end.to raise_error SystemExit
+ end.to raise_error Slushy::Error
end
end
@@ -107,7 +107,7 @@ def mock_job(options={})
capture_stdout do
expect do
instance.run_command!("ls")
- end.to raise_error SystemExit
+ end.to raise_error Slushy::Error
end.should =~ /STDERR: FAIL WHALE/
end
end
@@ -124,11 +124,11 @@ def mock_job(options={})
end.to_not raise_error
end
- it 'retries up to five times, then aborts' do
+ it 'retries up to five times, then fails' do
instance.should_receive(:ssh).exactly(5).times.with('sudo apt-get update').and_return([mock_job(:status => 1)])
expect do
capture_stdout { instance.apt_installs }
- end.to raise_error SystemExit
+ end.to raise_error Slushy::Error
end
end

0 comments on commit 27e8d3f

Please sign in to comment.