Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

…s are registered.
  • Loading branch information...
commit 38b6d05dcec259e67cabc86edbe7b23b43934bf1 1 parent 99bff02
Kaoru Kobo authored
Showing with 34 additions and 1 deletion.
  1. +1 −1  lib/rhook.rb
  2. +33 −0 spec/rhook_minor_spec.rb
View
2  lib/rhook.rb
@@ -71,7 +71,7 @@ def to(opt = {})
def call_method(name, method_name, args, block, opt = {})
hooks = concat_hooks([], name)
- hooks.empty? and @obj.__send__(method_name, *args, &block)
+ hooks.empty? and return @obj.__send__(method_name, *args, &block)
inv = Invocation.new
inv.target = @obj
View
33 spec/rhook_minor_spec.rb
@@ -11,6 +11,39 @@ class Target
end
# ================================================================
+ describe "invocation" do
+ describe "is proceed by correct order & not rerun." do
+ class Target
+ attr_reader :order_ary
+ def order_call
+ @order_ary = []
+ _rhook.to.order_target
+ end
+
+ def order_target
+ @order_ary << "orig"
+ end
+ end
+
+ example do
+ t = Target.new
+
+ # [bug] It calls the target method/procedure twice when no hooks are registered.
+ t.order_call
+ t.order_ary.should == ["orig"]
+
+ t._rhook.bind(:order_target) do |inv|
+ t.order_ary << "before_call"
+ inv.call
+ t.order_ary << "after_call"
+ end
+ t.order_call
+ t.order_ary.should == ["before_call", "orig", "after_call"]
+ end
+ end
+ end
+
+ # ================================================================
describe "hack" do
# ================================================================
describe "Can hack on private method" do
Please sign in to comment.
Something went wrong with that request. Please try again.