change rails environment in the mid of testing

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

How to change the environment variable of rails in testing

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-24 01:52

    If you're using something like rspec, you can stub Rails.env to return a different value for the specific test example you're running:

    it "should log something in production" do
      Rails.stub(:env).and_return('production')
      Rails.logger.should_receive(:warning).with("message")
      run_your_code
    end
    

提交回复
热议问题