4 class ThrowSymbol #:nodoc:
5 def initialize(expected=nil)
14 raise e unless e.message =~ /uncaught throw/
15 @actual = e.name.to_sym
18 return @actual.nil? ? false : true
20 return @actual == @expected
27 "expected #{expected}, got #{@actual.inspect}"
29 "expected #{expected} but nothing was thrown"
33 def negative_failure_message
35 "expected #{expected} not to be thrown"
37 "expected no Symbol, got :#{@actual}"
48 @expected.nil? ? "a Symbol" : @expected.inspect
54 # should throw_symbol()
55 # should throw_symbol(:sym)
56 # should_not throw_symbol()
57 # should_not throw_symbol(:sym)
59 # Given a Symbol argument, matches if a proc throws the specified Symbol.
61 # Given no argument, matches if a proc throws any Symbol.
65 # lambda { do_something_risky }.should throw_symbol
66 # lambda { do_something_risky }.should throw_symbol(:that_was_risky)
68 # lambda { do_something_risky }.should_not throw_symbol
69 # lambda { do_something_risky }.should_not throw_symbol(:that_was_risky)
70 def throw_symbol(sym=nil)
71 Matchers::ThrowSymbol.new(sym)