I have a Sinatra app like this:
my_module.rb
module MyModule
def my_method
"yay"
end
end
app.rb
get "/my_module" do
puts my_method
end
I'm trying to stub my_method
on a test with Minitest
and mocha
.
def test_my_method
MyModule.stubs(:my_method).returns("stubbed")
get "/my_module"
end
But this don't seems to work, because the original method is still called. Any thoughts on how to do this? Thanks!
I've found out two different ways to achieve this.
1) Using stub any instance gem.
With this gem I could stub any instace of
Sinatra::Application
. So the solution looks like this:2) Using
mocha
's any_instance.This solution follows the same principle. Just using
mocha
s methods.