在机架应用程序中模拟 Ruby 的 Timeout::timeout
Mocking Ruby's Timeout::timeout in a Rack App
我有一个 Sinatra 应用程序。我正在用 Rack::Test
测试它。我想确保将查询字符串参数传递给 Timeout::timeout()
.
我认为 expect_any_instance_of(Timeout).to receive(:timeout)
会奏效。
它没有,我只是得到默认值Exactly one instance should have received the following message(s) but didn't: timeout
。亲眼所见,代码肯定被调用了,毫无疑问。
有什么想法吗?
Timeout::timeout
- 这是 class 方法调用,而不是实例方法调用。因此,你应该使用这个:
expect(Timeout).to receive(:timeout)
我有一个 Sinatra 应用程序。我正在用 Rack::Test
测试它。我想确保将查询字符串参数传递给 Timeout::timeout()
.
我认为 expect_any_instance_of(Timeout).to receive(:timeout)
会奏效。
它没有,我只是得到默认值Exactly one instance should have received the following message(s) but didn't: timeout
。亲眼所见,代码肯定被调用了,毫无疑问。
有什么想法吗?
Timeout::timeout
- 这是 class 方法调用,而不是实例方法调用。因此,你应该使用这个:
expect(Timeout).to receive(:timeout)