Reputation: 3350
I have logic in a Sinatra project that determines different behaviour depending on if the environment is production or development.
if Services.production?
# do something
else
# do something else
end
How can I test this code? I have tried the following but it didn't work:
expect_any_instance_of(Services).to receive(:production?).and_return(true)
Upvotes: 1
Views: 100
Reputation: 49950
From your code it looks like production? is a class method, so it's not being called on an instance of Services, but rather on the class Services. Try
expect(Services).to receive(:production?).and_return(true)
Upvotes: 1
Reputation: 949
It's not an instance of Services
you're calling production?
on, it's the Services
class itself. You should be able to just do
expect(Services).to receive(:production?).and_return(true)
Upvotes: 1