I’ve started doing this in initializers as well if it conveys my intent better. Sometimes my intent is “if I’m in development or test, configure this thing slightly differently.” But in some cases, as seems to the case with PusherFake here, what I mean is “If this gem is available in this environment at all, configure it like this.”
I think it’s a better pattern since you don’t rely on environments directly, but on the presence of the class, whatever the environment is.
If we write if Rails.env.test? || Rails.env.development?, we only depend on the fact that the gem is loaded on those environments (based on what’s written in the Gemfile), which is kind of obscure.