【发布时间】:2016-08-31 20:35:53
【问题描述】:
规范助手:
def app
Sinatra::Application
end
应用:
require 'sinatra'
get '/' do
track_request
"Welcome"
end
def track_request
puts self.inspect
....
end
如何模拟track_request?
allow(app).to receive :track_request
allow_any_instance_of(Sinatra::Application).to receive :track_request
allow(Sinatra::Application).to receive :track_request
这些都不起作用。
self 是 main,所以我想我们需要在 main 上模拟一个方法。但是不知道怎么做。
【问题讨论】:
-
测试环境设置可能有所不同。我能够很好地模拟该方法。 gist.github.com/kgrz/4ea34a6cf79502c3eda678d6760b34b1
标签: ruby rspec mocking sinatra