Skip to content

Commit

Permalink
fixed recursivity problem
Browse files Browse the repository at this point in the history
  • Loading branch information
gtrias committed Oct 21, 2024
1 parent 3a3f7d4 commit 838c635
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/captain_hook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ def decorate_method!(method_name)

original_method_name = :"#{method_name}__without_hooks"

alias_method original_method_name, method_name unless method_defined?(original_method_name)
return if method_defined?(original_method_name)

alias_method original_method_name, method_name

# We decorate the method with the before, after and around hooks
define_method(method_name) do |*args, **kwargs|
Expand Down
4 changes: 2 additions & 2 deletions spec/captain_hook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def foo(dto:); end

def prepare(dto:)
super(dto: dto)
"servig food"
"child #{dto}"
end
end

Expand Down Expand Up @@ -153,7 +153,7 @@ def prepare(dto:)
subject.foo(dto: "fooing")

expect_any_instance_of(BeforeAllHook).to receive(:call).once
subject.prepare(dto: "foo")
expect(subject.prepare(dto: "foo")).to eq("child foo")
end
end
end

0 comments on commit 838c635

Please sign in to comment.