ruby - Minitest mocking Sinatra app -
i have sinatra app inherited sinatra::base
class. in app have 1 helper method use in before filter. how mock such method in tests using minitest mock library?
before unless valid_signature? halt 401 end end
in order valid_signature?
sinatra helper method, needs part of module. assuming module mymodule
module mymodule def valid_signature? end end
we can mock valid_signature?
using minitest follows:
mymodule.stub :valid_signature?, "stub return value" # method stubbed in block, run tests here # make sure module defined before stub it. end
if running tests within block limiting, recommend looking @ mocha stubbing , mock library or manually redefining method @ runtime in test file:
mymodule def valid_signature? # can redefine after class has been defined. "stub return value" end end
Comments
Post a Comment