Skip to content

Commit

Permalink
Merge pull request #13 from benSlaughter/Issue7
Browse files Browse the repository at this point in the history
added tests for error handling during record event
  • Loading branch information
benSlaughter committed Sep 2, 2013
2 parents 2e478f1 + 279bf73 commit a28f3f0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/allotment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ class Allotment
class << self
def record_event name = 'unnamed', &block
start_recording name
yield
ensure
return stop_recording name
begin
yield
ensure
time = stop_recording name
end
return time
end

def start_recording name = 'unnamed'
Expand Down
5 changes: 5 additions & 0 deletions spec/allotment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
result = Allotment.record_event('my_recording 0.4') { sleep 0.01 }
result.round(2).should eq 0.01
end

it "returns still records the performance upon error" do
expect { Allotment.record_event('failed_recording') { sleep 0.01; raise 'error' } }.to raise_error RuntimeError, "error"
Allotment.results['failed_recording'].first.round(2).should eq 0.01
end
end

describe ".start_recording" do
Expand Down

0 comments on commit a28f3f0

Please sign in to comment.