webmock
webmock copied to clipboard
webmock doesn't play nice with MiniTest hooks
I'm using webmocks to replace expensive calls to Facebook to create test users. I was previously using Minitest-hooks (https://github.com/jeremyevans/minitest-hooks) to do the creation in before_all and deletion in after_all blocks. However, webmock/minitest.rb monkey patches MiniTest's teardown causing code in after_all to fail.
I'm looking for the best way to manually control when webmock calls reset!.
was able to get this working by adding this to the bottom of my rails project's test/test_helper.rb
ActiveSupport::TestCase.class_eval do
alias_method :teardown, :teardown_without_webmock
alias_method :after_all_without_webmock, :after_all
def after_all_with_webmock
after_all_without_webmock
WebMock.reset!
end
alias_method :after_all, :after_all_with_webmock
end
Hi @kwasimensah ,
Do you need further help on this or we can close this issue?
Oh, haven't looked at this in a while. I believe my code still has the monkey patch. Are you asking if it works without that?
@kwasimensah do you have any suggestions on how to change https://github.com/bblimke/webmock/blob/master/lib/webmock/minitest.rb in order to support minitest hooks?
Facing this very same issue, with Rails 7, minitest 5.18.0 and minitest-hooks 1.5.0 and webmock 318.1
I guess the problem nowadays lies in the fact we run the tests in separate threads, so the "mocks" are not available in the running threads.