DeejUK
DeejUK

Reputation: 13471

Mocking Ruby's Timeout::timeout in a Rack App

I've got a Sinatra app. I'm testing it with Rack::Test. I want to make sure that a query string parameter is passed through to Timeout::timeout().

I thought that expect_any_instance_of(Timeout).to receive(:timeout) would have worked.

It does not, I just get the default Exactly one instance should have received the following message(s) but didn't: timeout. I can see with my eyes that the code definitely, without a doubt, gets called.

Any ideas?

Upvotes: 3

Views: 295

Answers (1)

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230286

Timeout::timeout - this is class method call, not instance method call. Therefore, you should be using this:

expect(Timeout).to receive(:timeout)

Upvotes: 2

Related Questions