Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: method 'info' has already been hooked after bump to ruby 2.7.2 #21

Open
lilien1010 opened this issue Mar 10, 2021 · 1 comment
Open

Comments

@lilien1010
Copy link

lilien1010 commented Mar 10, 2021

my test code is like below, but it keep saying that method 'info' has already been hooked

Spy.on(Rails.logger, [:debug, :info, :error].freeze)
Error:
xxxx::xxxx:
Spy::AlreadyHookedError: #<ActiveSupport::Logger:0x00007f8f70d28488> method 'info' has already been hooked
    test/xxxx.rb:8:in `block (2 levels) in <module:xxxxxx>'

4904 tests, 13087 assertions, 0 failures, 1 errors, 0 skips

any idea how to fix this?

@krazylegz
Copy link

I realize it's been 2 years, but did you ever sort this out? I just started using this gem yesterday, but I found I had to call Spy.off to tear down my spies at the end of the test.

spy/lib/spy.rb

Lines 32 to 41 in 6ac9240

def off(base_object, *method_names)
removed_spies = method_names.map do |method_name|
spy = Subroutine.get(base_object, method_name)
if spy
spy.unhook
end
end
removed_spies.size > 1 ? removed_spies : removed_spies.first
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants