From the Rails.env stubbing lightning talk. Code paths gated on Rails.env.development? / Rails.env.production? are not untestable. In minitest, the stub_any_instance gem with a stub_environment helper can make the Rails.env predicates return the desired triple of booleans inside a block. In RSpec, the same is achievable with RSpec mocks and around-example hooks, at the cost of measurably slower tests (test-environment optimizations seem to be bypassed when Rails.env predicates are stubbed).