Skip to content
This repository
Browse code

[BUG] Fatal - It calls the target method/procedure twice when no hook…

…s are registered.
  • Loading branch information...
commit 38b6d05dcec259e67cabc86edbe7b23b43934bf1 1 parent 99bff02
authored November 12, 2010
2  lib/rhook.rb
@@ -71,7 +71,7 @@ def to(opt = {})
71 71
     
72 72
     def call_method(name, method_name, args, block, opt = {})
73 73
       hooks = concat_hooks([], name)
74  
-      hooks.empty? and @obj.__send__(method_name, *args, &block)
  74
+      hooks.empty? and return @obj.__send__(method_name, *args, &block)
75 75
       
76 76
       inv = Invocation.new
77 77
       inv.target = @obj
33  spec/rhook_minor_spec.rb
@@ -11,6 +11,39 @@ class Target
11 11
   end
12 12
   
13 13
   # ================================================================
  14
+  describe "invocation" do
  15
+    describe "is proceed by correct order & not rerun." do
  16
+      class Target
  17
+        attr_reader :order_ary
  18
+        def order_call
  19
+          @order_ary = []
  20
+          _rhook.to.order_target
  21
+        end
  22
+        
  23
+        def order_target
  24
+          @order_ary << "orig"
  25
+        end
  26
+      end
  27
+      
  28
+      example do
  29
+        t = Target.new
  30
+        
  31
+        # [bug] It calls the target method/procedure twice when no hooks are registered.
  32
+        t.order_call
  33
+        t.order_ary.should == ["orig"]
  34
+
  35
+        t._rhook.bind(:order_target) do |inv|
  36
+          t.order_ary << "before_call"
  37
+          inv.call
  38
+          t.order_ary << "after_call"
  39
+        end
  40
+        t.order_call
  41
+        t.order_ary.should == ["before_call", "orig", "after_call"]
  42
+      end
  43
+    end
  44
+  end
  45
+  
  46
+  # ================================================================
14 47
   describe "hack" do
15 48
     # ================================================================
16 49
     describe "Can hack on private method" do 

0 notes on commit 38b6d05

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