Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

check empty rescue node

  • Loading branch information...
commit d29caac96c14d69a54d85fa1a4fe9c87a190edf8 1 parent 570b119
Richard Huang authored November 02, 2012
1  lib/code_analyzer/sexp.rb
@@ -540,6 +540,7 @@ def statements
540 540
   #         => s(s(:var_ref, s(:@const, "CustomException", s(1, 17))))
541 541
   def exception_classes
542 542
     if :rescue == sexp_type
  543
+      return [] unless self[1]
543 544
       if :mrhs_add == self[1].sexp_type
544 545
         exceptions = Array.new(self[1][2])
545 546
         arg_nodes = self[1][1][1]
12  spec/code_analyzer/sexp_spec.rb
@@ -426,6 +426,11 @@ def show
426 426
       node.exception_classes.first.to_s.should == "CustomException"
427 427
     end
428 428
 
  429
+    it "should get empty of empty rescue node" do
  430
+      node = parse_content("def test; rescue; end").grep_node(sexp_type: :rescue)
  431
+      node.exception_classes.first.to_s.should == ""
  432
+    end
  433
+
429 434
     it "should get exception classes of rescue node for multiple exceptions" do
430 435
       node = parse_content("def test; rescue StandardError, CustomException; end").grep_node(sexp_type: :rescue)
431 436
       node.exception_classes.first.to_s.should == "StandardError"
@@ -434,10 +439,15 @@ def show
434 439
   end
435 440
 
436 441
   describe "exception_variable" do
437  
-    it "should get exception class of rescue node" do
  442
+    it "should get exception varible of rescue node" do
438 443
       node = parse_content("def test; rescue => e; end").grep_node(sexp_type: :rescue)
439 444
       node.exception_variable.to_s.should == "e"
440 445
     end
  446
+
  447
+    it "should get empty of empty rescue node" do
  448
+      node = parse_content("def test; rescue; end").grep_node(sexp_type: :rescue)
  449
+      node.exception_variable.to_s.should == ""
  450
+    end
441 451
   end
442 452
 
443 453
   describe "hash_value" do

0 notes on commit d29caac

Please sign in to comment.
Something went wrong with that request. Please try again.