Skip to content

Commit

Permalink
Refactored exception handling tests for Promise and Agent.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdantonio committed Oct 10, 2013
1 parent 4b2092c commit 51eac70
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
20 changes: 9 additions & 11 deletions spec/concurrent/agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ module Concurrent
subject.
rescue(ArgumentError){|ex| @expected = 1 }.
rescue(LoadError){|ex| @expected = 2 }.
rescue(Exception){|ex| @expected = 3 }
rescue(StandardError){|ex| @expected = 3 }
subject.post{ raise ArgumentError }
sleep(0.1)
@expected.should eq 1
Expand All @@ -212,7 +212,7 @@ module Concurrent
subject.
rescue(ArgumentError){|ex| @expected = 1 }.
rescue(LoadError){|ex| @expected = 2 }.
rescue(Exception){|ex| @expected = 3 }
rescue(StandardError){|ex| @expected = 3 }
subject.post{ raise LoadError }
sleep(0.1)
@expected.should eq 2
Expand All @@ -221,7 +221,7 @@ module Concurrent
subject.
rescue(ArgumentError){|ex| @expected = 1 }.
rescue(LoadError){|ex| @expected = 2 }.
rescue(Exception){|ex| @expected = 3 }
rescue(StandardError){|ex| @expected = 3 }
subject.post{ raise StandardError }
sleep(0.1)
@expected.should eq 3
Expand All @@ -232,19 +232,17 @@ module Concurrent
subject.
rescue(ArgumentError){|ex| @expected = ex }.
rescue(LoadError){|ex| @expected = ex }.
rescue(Exception){|ex| @expected = ex }
rescue(StandardError){|ex| @expected = ex }
subject.post{ raise StandardError }
sleep(0.1)
@expected.should be_a(StandardError)
end

it 'ignores rescuers without a block' do
@expected = nil
subject.
Promise.new{ raise StandardError }.
rescue(StandardError).
rescue(StandardError){|ex| @expected = ex }.
rescue(Exception){|ex| @expected = ex }
subject.post{ raise StandardError }
rescue(StandardError){|ex| @expected = ex }
sleep(0.1)
@expected.should be_a(StandardError)
end
Expand All @@ -253,16 +251,16 @@ module Concurrent
lambda {
subject.
rescue(ArgumentError){|ex| @expected = ex }.
rescue(StandardError){|ex| @expected = ex }.
rescue(Exception){|ex| @expected = ex }
rescue(NotImplementedError){|ex| @expected = ex }.
rescue(NoMethodError){|ex| @expected = ex }
subject.post{ raise StandardError }
sleep(0.1)
}.should_not raise_error
end

it 'supresses exceptions thrown from rescue handlers' do
lambda {
subject.rescue(Exception){ raise StandardError }
subject.rescue(StandardError){ raise StandardError }
subject.post{ raise ArgumentError }
sleep(0.1)
}.should_not raise_error
Expand Down
19 changes: 9 additions & 10 deletions spec/concurrent/promise_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ module Concurrent
it 'sets the promise reason the error object on exception' do
p = Promise.new{ raise StandardError.new('Boom!') }
sleep(0.1)
p.reason.should be_a(Exception)
p.reason.should be_a(StandardError)
p.reason.should.to_s =~ /Boom!/
end

Expand Down Expand Up @@ -207,23 +207,23 @@ module Concurrent
Promise.new{ raise ArgumentError }.
rescue(ArgumentError){|ex| @expected = 1 }.
rescue(LoadError){|ex| @expected = 2 }.
rescue(Exception){|ex| @expected = 3 }
rescue(StandardError){|ex| @expected = 3 }
sleep(0.1)
@expected.should eq 1

@expected = nil
Promise.new{ raise LoadError }.
rescue(ArgumentError){|ex| @expected = 1 }.
rescue(LoadError){|ex| @expected = 2 }.
rescue(Exception){|ex| @expected = 3 }
rescue(StandardError){|ex| @expected = 3 }
sleep(0.1)
@expected.should eq 2

@expected = nil
Promise.new{ raise StandardError }.
rescue(ArgumentError){|ex| @expected = 1 }.
rescue(LoadError){|ex| @expected = 2 }.
rescue(Exception){|ex| @expected = 3 }
rescue(StandardError){|ex| @expected = 3 }
sleep(0.1)
@expected.should eq 3
end
Expand All @@ -233,7 +233,7 @@ module Concurrent
Promise.new{ raise StandardError }.
rescue(ArgumentError){|ex| @expected = ex }.
rescue(LoadError){|ex| @expected = ex }.
rescue(Exception){|ex| @expected = ex }
rescue(StandardError){|ex| @expected = ex }
sleep(0.1)
@expected.should be_a(StandardError)
end
Expand All @@ -242,8 +242,7 @@ module Concurrent
@expected = nil
Promise.new{ raise StandardError }.
rescue(StandardError).
rescue(StandardError){|ex| @expected = ex }.
rescue(Exception){|ex| @expected = ex }
rescue(StandardError){|ex| @expected = ex }
sleep(0.1)
@expected.should be_a(StandardError)
end
Expand All @@ -252,16 +251,16 @@ module Concurrent
lambda {
Promise.new{ raise StandardError }.
rescue(ArgumentError){|ex| @expected = ex }.
rescue(StandardError){|ex| @expected = ex }.
rescue(Exception){|ex| @expected = ex }
rescue(NotImplementedError){|ex| @expected = ex }.
rescue(NoMethodError){|ex| @expected = ex }
sleep(0.1)
}.should_not raise_error
end

it 'supresses exceptions thrown from rescue handlers' do
lambda {
Promise.new{ raise ArgumentError }.
rescue(Exception){ raise StandardError }
rescue(StandardError){ raise StandardError }
sleep(0.1)
}.should_not raise_error
end
Expand Down

0 comments on commit 51eac70

Please sign in to comment.