RSpec

rspecでテスト環境以外の環境を想定したテストの書き方

More than 1 year has passed since last update.
def env_in_jp
 return '本番環境' if Rails.env.production?
end
describe '環境別に処理を変える' do
  it '本番環境' do
    allow(Rails).to receive(:env).and_return('production'.inquiry)
    expect(Rails.env.production?).to eq true
    expect(env_in_jp).to eq '本番環境'
  end

  it '開発環境' do
   allow(Rails).to receive(:env).and_return('development'.inquiry)
   expect(Rails.env.development?).to eq true
   expect(env_in_jp).to eq nil
  end
end