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

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -