Stub a Rails Environment in RSpec

2014-06-11

When writing tests to test for rails.env specific functions, in order to temporarily change the rails environment during testing, use this:

  Rails.stub(env: ActiveSupport::StringInquirer.new("production"))

This will then pass when doing a

  Rails.env.production?
I’m currently working on fyra.sh, a CLI-first static site deployment tool where you push your site and it’s served globally through a built-in CDN, without the overhead of heavy platforms.