Created
October 8, 2012 12:57
-
-
Save goblin/3852382 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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