Permalink
Browse files

Fix throw_symbol matcher so that it no longer swallows exceptions tha…

…t occur in the proc.
  • Loading branch information...
1 parent cfc20db commit 6cde7f6a11f6b73c22f63c44f61a5f93a0e41540 @myronmarston myronmarston committed with dchelimsky Oct 22, 2010
Showing with 25 additions and 10 deletions.
  1. +14 −8 lib/rspec/matchers/throw_symbol.rb
  2. +11 −2 spec/rspec/matchers/throw_symbol_spec.rb
View
22 lib/rspec/matchers/throw_symbol.rb
@@ -25,17 +25,23 @@ def matches?(given_proc)
# Ruby 1.8 uses NameError with `symbol'
# Ruby 1.9 uses ArgumentError with :symbol
rescue NameError, ArgumentError => e
- raise e unless e.message =~ /uncaught throw (`|\:)([a-zA-Z0-9_]*)(')?/
+ unless e.message =~ /uncaught throw (`|\:)([a-zA-Z0-9_]*)(')?/
+ other_exception = e
+ raise
+ end
@caught_symbol = $2.to_sym
-
+ rescue => other_exception
+ raise
ensure
- if @expected_symbol.nil?
- return !@caught_symbol.nil?
- else
- if @expected_arg.nil?
- return @caught_symbol == @expected_symbol
+ unless other_exception
+ if @expected_symbol.nil?
+ return !@caught_symbol.nil?
else
- return (@caught_symbol == @expected_symbol) & (@caught_arg == @expected_arg)
+ if @expected_arg.nil?
+ return @caught_symbol == @expected_symbol
+ else
+ return (@caught_symbol == @expected_symbol) & (@caught_arg == @expected_arg)
+ end
end
end
end
View
13 spec/rspec/matchers/throw_symbol_spec.rb
@@ -53,7 +53,9 @@ module Matchers
@matcher.failure_message_for_should_not.should == "expected :sym not to be thrown"
end
it "only matches NameErrors raised by uncaught throws" do
- @matcher.matches?(lambda{ sym }).should be_false
+ expect {
+ @matcher.matches?(lambda{ sym }).should be_false
+ }.to raise_error(NameError)
end
end
@@ -88,7 +90,14 @@ module Matchers
@matcher.failure_message_for_should_not.should == %q[expected :sym with "a" not to be thrown]
end
it "only matches NameErrors raised by uncaught throws" do
- @matcher.matches?(lambda{ sym }).should be_false
+ expect {
+ @matcher.matches?(lambda{ sym }).should be_false
+ }.to raise_error(NameError)
+ end
+ it "raises other errors" do
+ expect {
+ @matcher.matches?(lambda { raise "Boom" })
+ }.to raise_error(/Boom/)
end
end
end

0 comments on commit 6cde7f6

Please sign in to comment.