TTransmit
TTransmit

Reputation: 3350

How to test, in rspec, environment determined with Settings.production?

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

Answers (2)

Thomas Walpole
Thomas Walpole

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

Ramfjord
Ramfjord

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

Related Questions