LoginSignup
1
1

More than 5 years have passed since last update.

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

Posted at

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
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1