Browse files

Flesh out tests a bit

  • Loading branch information...
1 parent c6d8bbc commit 719c8b68ff5f584379f446356a7b7cf004a4c536 @ConradIrwin committed Aug 11, 2012
Showing with 67 additions and 0 deletions.
  1. +67 −0 spec/interception_spec.rb
View
67 spec/interception_spec.rb
@@ -61,4 +61,71 @@
@exceptions.map(&:first).should == [e1, e2]
end
+
+ it "should be able to listen for the duration of a block" do
+
+ e1, e2 = nil
+ block = proc{
+ begin
+ raise "foo"
+ rescue => e1
+ #
+ end
+ }
+ Interception.listen(block) do |e, b|
+ e2 = e
+ end
+
+ e1.should == e2
+ end
+
+ it "should allow nested calls to listen with a block" do
+ e1, e2 = nil
+ b1, b2 = nil
+ block = proc{
+ begin
+ raise "foo"
+ rescue => e1
+ #
+ end
+ }
+ block2 = proc{
+ Interception.listen(block) do |e, b|
+ e2 = e
+ b1 = b
+ end
+ }
+ Interception.listen(block2) do |e, b|
+ b2 = b
+ end
+
+ e1.should == e2
+ b1.should == b2
+ end
+
+ it "should be able to handle NoMethodErrors" do
+ shoulder = :bucket
+
+ begin
+ line = __LINE__; "snorkle".desnrok
+ rescue => e1
+ #
+ end
+
+ @exceptions.map{ |e, b| [e] + b.eval('[__LINE__, shoulder]') }.should == [[e1, line, :bucket]]
+ e1.message.should =~ /desnrok/
+ end
+
+ it "should be able to handle division by 0 errors" do
+ shoulder = :bucket
+
+ begin
+ line = __LINE__; 1 / 0
+ rescue => e1
+ #
+ end
+
+ @exceptions.map{ |e, b| [e] + b.eval('[__LINE__, shoulder]') }.should == [[e1, line, :bucket]]
+ ZeroDivisionError.should === e1
+ end
end

0 comments on commit 719c8b6

Please sign in to comment.