change rails environment in the mid of testing

后端 未结 5 1941
天命终不由人
天命终不由人 2020-12-24 01:11

How to change the environment variable of rails in testing

5条回答
  •  無奈伤痛
    2020-12-24 02:12

    Rspec 3 onwards you can do

    it "should do something specific for production" do 
      allow(Rails).to receive(:env).and_return(ActiveSupport::StringInquirer.new("production"))
      #other assertions
    end
    

提交回复
热议问题