def throw_symbol(*obj)
build_matcher(:throw_symbol, obj) do |receiver, matcher, args|
raised, thrown_symbol, expected = false, nil, args[0]
begin
receiver.call
rescue NameError => e
raise e unless e.message =~ /uncaught throw/
raised = true
thrown_symbol = e.name.to_sym if e.respond_to?(:name)
rescue ArgumentError => e
raise e unless e.message =~ /uncaught throw/
thrown_symbol = e.message.match(/uncaught throw :(.+)/)[1].to_sym
end
matcher.positive_failure_message = "Expected #{receiver.inspect} to throw :#{expected}, but " +
"#{thrown_symbol ? ':' + thrown_symbol.to_s + ' was thrown instead' : 'no symbol was thrown'}."
matcher.negative_failure_message = "Expected #{receiver.inspect} to not throw :#{expected}."
expected == thrown_symbol
end
end