Permalink
Browse files

Accept a boolean response in a rescue block

  • Loading branch information...
1 parent cc698cd commit 6e862bda4998a573c0f7776b0609bdebc484f381 Marty Andrews committed Nov 21, 2009
Showing with 27 additions and 1 deletion.
  1. +1 −1 lib/roodi/checks/empty_rescue_body_check.rb
  2. +26 −0 spec/roodi/checks/empty_rescue_body_check_spec.rb
@@ -7,7 +7,7 @@ module Checks
# When the body of a rescue block is empty, exceptions can get caught and swallowed without
# any feedback to the user.
class EmptyRescueBodyCheck < Check
- STATEMENT_NODES = [:fcall, :return, :attrasgn, :vcall, :nil, :call, :lasgn]
+ STATEMENT_NODES = [:fcall, :return, :attrasgn, :vcall, :nil, :call, :lasgn, :true, :false]
def interesting_nodes
[:resbody]
@@ -111,4 +111,30 @@
errors.should_not be_empty
errors[0].to_s.should match(/dummy-file.rb:[3-4] - Rescue block should not be empty./)
end
+
+ it "should accept a rescue block that returns true" do
+ content = <<-END
+ begin
+ call_method
+ rescue Exception => e
+ true
+ end
+ END
+ @roodi.check_content(content)
+ errors = @roodi.errors
+ errors.should be_empty
+ end
+
+ it "should accept a rescue block that returns false" do
+ content = <<-END
+ begin
+ call_method
+ rescue Exception => e
+ false
+ end
+ END
+ @roodi.check_content(content)
+ errors = @roodi.errors
+ errors.should be_empty
+ end
end

0 comments on commit 6e862bd

Please sign in to comment.