Skip to content

Instantly share code, notes, and snippets.

@goblin
Created October 8, 2012 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goblin/3852382 to your computer and use it in GitHub Desktop.
Save goblin/3852382 to your computer and use it in GitHub Desktop.
require 'eventmachine'
def check_checksum
# some checksum processing here... let's say it fails
raise Exception.new("invalid checksum: 28fad31")
end
def notify(ev)
if ev == :download_complete then
check_checksum
end
end
def exception_handler
yield
rescue Exception => e
puts "handling exception #{e.message} by logging it"
# send an email etc
end
def start_deployment
exception_handler do
# wait for some special events (that prevent EventMachine from returning)
EventMachine.add_timer(10) do
puts "slow wait ending"
end
# start "fake" download
EventMachine.add_timer(1) do
# "fake download" complete
notify(:download_complete)
end
end
end
require './app'
require 'eventmachine'
describe 'the app' do
it 'should raise exception' do
stub!(:exception_handler) do
# 1. check that the exception message matches "invalid checksum"
# how?
# 2. call EM.stop
EM.stop
end
EM.run do
start_deployment
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment