Use stub_rails_env for Rails.env stubbing
RailsHelpers.stub_rails_env takes care of stubbing Rails.env
This commit is contained in:
parent
0fca70a40f
commit
124bad7bd8
|
@ -58,7 +58,7 @@ describe 'Help Pages' do
|
|||
before do
|
||||
stub_application_setting(version_check_enabled: true)
|
||||
|
||||
allow(Rails.env).to receive(:production?).and_return(true)
|
||||
stub_rails_env('production')
|
||||
allow(VersionCheck).to receive(:url).and_return('/version-check-url')
|
||||
|
||||
sign_in(create(:user))
|
||||
|
|
|
@ -37,7 +37,7 @@ describe 'User can display performance bar', :js do
|
|||
|
||||
shared_examples 'performance bar is enabled by default in development' do
|
||||
before do
|
||||
allow(Rails.env).to receive(:development?).and_return(true)
|
||||
stub_rails_env('development')
|
||||
end
|
||||
|
||||
it 'shows the performance bar by default' do
|
||||
|
|
|
@ -60,20 +60,19 @@ describe IconsHelper do
|
|||
non_existing = 'non_existing_icon_sprite'
|
||||
|
||||
it 'raises in development mode' do
|
||||
allow(Rails.env).to receive(:development?).and_return(true)
|
||||
stub_rails_env('development')
|
||||
|
||||
expect { sprite_icon(non_existing) }.to raise_error(ArgumentError, /is not a known icon/)
|
||||
end
|
||||
|
||||
it 'raises in test mode' do
|
||||
allow(Rails.env).to receive(:test?).and_return(true)
|
||||
stub_rails_env('test')
|
||||
|
||||
expect { sprite_icon(non_existing) }.to raise_error(ArgumentError, /is not a known icon/)
|
||||
end
|
||||
|
||||
it 'does not raise in production mode' do
|
||||
allow(Rails.env).to receive(:test?).and_return(false)
|
||||
allow(Rails.env).to receive(:development?).and_return(false)
|
||||
stub_rails_env('production')
|
||||
|
||||
expect { sprite_icon(non_existing) }.not_to raise_error
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@ require 'spec_helper'
|
|||
describe VersionCheckHelper do
|
||||
describe '#version_status_badge' do
|
||||
it 'returns nil if not dev environment and not enabled' do
|
||||
allow(Rails.env).to receive(:production?) { false }
|
||||
stub_rails_env('development')
|
||||
allow(Gitlab::CurrentSettings.current_application_settings).to receive(:version_check_enabled) { false }
|
||||
|
||||
expect(helper.version_status_badge).to be(nil)
|
||||
|
@ -11,7 +11,7 @@ describe VersionCheckHelper do
|
|||
|
||||
context 'when production and enabled' do
|
||||
before do
|
||||
allow(Rails.env).to receive(:production?) { true }
|
||||
stub_rails_env('production')
|
||||
allow(Gitlab::CurrentSettings.current_application_settings).to receive(:version_check_enabled) { true }
|
||||
allow(VersionCheck).to receive(:url) { 'https://version.host.com/check.svg?gitlab_info=xxx' }
|
||||
end
|
||||
|
|
|
@ -1283,33 +1283,19 @@ describe Gitlab::Database::MigrationHelpers do
|
|||
|
||||
describe '#perform_background_migration_inline?' do
|
||||
it 'returns true in a test environment' do
|
||||
allow(Rails.env)
|
||||
.to receive(:test?)
|
||||
.and_return(true)
|
||||
stub_rails_env('test')
|
||||
|
||||
expect(model.perform_background_migration_inline?).to eq(true)
|
||||
end
|
||||
|
||||
it 'returns true in a development environment' do
|
||||
allow(Rails.env)
|
||||
.to receive(:test?)
|
||||
.and_return(false)
|
||||
|
||||
allow(Rails.env)
|
||||
.to receive(:development?)
|
||||
.and_return(true)
|
||||
stub_rails_env('development')
|
||||
|
||||
expect(model.perform_background_migration_inline?).to eq(true)
|
||||
end
|
||||
|
||||
it 'returns false in a production environment' do
|
||||
allow(Rails.env)
|
||||
.to receive(:test?)
|
||||
.and_return(false)
|
||||
|
||||
allow(Rails.env)
|
||||
.to receive(:development?)
|
||||
.and_return(false)
|
||||
stub_rails_env('production')
|
||||
|
||||
expect(model.perform_background_migration_inline?).to eq(false)
|
||||
end
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe Gitlab::Favicon, :request_store do
|
||||
include RailsHelpers
|
||||
|
||||
describe '.main' do
|
||||
it 'defaults to favicon.png' do
|
||||
stub_rails_env('production')
|
||||
|
|
|
@ -265,7 +265,7 @@ describe Gitlab::GitalyClient do
|
|||
|
||||
context 'in production and when RequestStore is enabled', :request_store do
|
||||
before do
|
||||
allow(Rails.env).to receive(:production?).and_return(true)
|
||||
stub_rails_env('production')
|
||||
end
|
||||
|
||||
context 'when the maximum number of calls is enforced by a feature flag' do
|
||||
|
|
|
@ -86,9 +86,7 @@ describe Gitlab::QueryLimiting::Transaction do
|
|||
it 'returns false in a production environment' do
|
||||
transaction = described_class.new
|
||||
|
||||
expect(Rails.env)
|
||||
.to receive(:test?)
|
||||
.and_return(false)
|
||||
stub_rails_env('production')
|
||||
|
||||
expect(transaction.raise_error?).to eq(false)
|
||||
end
|
||||
|
|
|
@ -9,14 +9,14 @@ describe Gitlab::QueryLimiting do
|
|||
end
|
||||
|
||||
it 'returns true in a development environment' do
|
||||
allow(Rails.env).to receive(:development?).and_return(true)
|
||||
stub_rails_env('development')
|
||||
stub_rails_env('development')
|
||||
|
||||
expect(described_class.enable?).to eq(true)
|
||||
end
|
||||
|
||||
it 'returns false on GitLab.com' do
|
||||
expect(Rails.env).to receive(:development?).and_return(false)
|
||||
expect(Rails.env).to receive(:test?).and_return(false)
|
||||
stub_rails_env('production')
|
||||
allow(Gitlab).to receive(:com?).and_return(true)
|
||||
|
||||
expect(described_class.enable?).to eq(false)
|
||||
|
@ -24,8 +24,7 @@ describe Gitlab::QueryLimiting do
|
|||
|
||||
it 'returns false in a non GitLab.com' do
|
||||
allow(Gitlab).to receive(:com?).and_return(false)
|
||||
expect(Rails.env).to receive(:development?).and_return(false)
|
||||
expect(Rails.env).to receive(:test?).and_return(false)
|
||||
stub_rails_env('production')
|
||||
|
||||
expect(described_class.enable?).to eq(false)
|
||||
end
|
||||
|
|
|
@ -3,8 +3,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Gitlab do
|
||||
include RailsHelpers
|
||||
|
||||
describe '.root' do
|
||||
it 'returns the root path of the app' do
|
||||
expect(described_class.root).to eq(Pathname.new(File.expand_path('../..', __dir__)))
|
||||
|
|
|
@ -131,7 +131,7 @@ describe CacheableAttributes do
|
|||
|
||||
context 'in production environment' do
|
||||
before do
|
||||
expect(Rails.env).to receive(:production?).and_return(true)
|
||||
stub_rails_env('production')
|
||||
end
|
||||
|
||||
it 'returns an uncached record and logs a warning' do
|
||||
|
@ -143,7 +143,7 @@ describe CacheableAttributes do
|
|||
|
||||
context 'in other environments' do
|
||||
before do
|
||||
expect(Rails.env).to receive(:production?).and_return(false)
|
||||
stub_rails_env('development')
|
||||
end
|
||||
|
||||
it 'returns an uncached record and logs a warning' do
|
||||
|
|
|
@ -17,7 +17,7 @@ describe ShaAttribute do
|
|||
describe '#sha_attribute' do
|
||||
context 'when in non-production' do
|
||||
before do
|
||||
allow(Rails.env).to receive(:production?).and_return(false)
|
||||
stub_rails_env('development')
|
||||
end
|
||||
|
||||
context 'when the table exists' do
|
||||
|
@ -76,7 +76,7 @@ describe ShaAttribute do
|
|||
|
||||
context 'when in production' do
|
||||
before do
|
||||
allow(Rails.env).to receive(:production?).and_return(true)
|
||||
stub_rails_env('production')
|
||||
end
|
||||
|
||||
it 'defines a SHA attribute' do
|
||||
|
|
|
@ -106,7 +106,8 @@ describe InternalId do
|
|||
end
|
||||
|
||||
it 'always attempts to generate internal IDs in production mode' do
|
||||
allow(Rails.env).to receive(:test?).and_return(false)
|
||||
stub_rails_env('production')
|
||||
|
||||
val = rand(1..100)
|
||||
generator = double(generate: val)
|
||||
expect(InternalId::InternalIdGenerator).to receive(:new).and_return(generator)
|
||||
|
|
|
@ -109,6 +109,7 @@ RSpec.configure do |config|
|
|||
config.include PolicyHelpers, type: :policy
|
||||
config.include MemoryUsageHelper
|
||||
config.include ExpectRequestWithStatus, type: :request
|
||||
config.include RailsHelpers
|
||||
|
||||
if ENV['CI']
|
||||
# This includes the first try, i.e. tests will be run 4 times before failing.
|
||||
|
|
|
@ -57,7 +57,7 @@ describe 'gitlab:gitaly namespace rake task' do
|
|||
stub_env('CI', false)
|
||||
FileUtils.mkdir_p(clone_path)
|
||||
expect(Dir).to receive(:chdir).with(clone_path).and_call_original
|
||||
allow(Rails.env).to receive(:test?).and_return(false)
|
||||
stub_rails_env('development')
|
||||
end
|
||||
|
||||
context 'gmake is available' do
|
||||
|
@ -93,7 +93,7 @@ describe 'gitlab:gitaly namespace rake task' do
|
|||
end
|
||||
|
||||
before do
|
||||
allow(Rails.env).to receive(:test?).and_return(true)
|
||||
stub_rails_env('test')
|
||||
end
|
||||
|
||||
it 'calls make in the gitaly directory with --no-deployment flag for bundle' do
|
||||
|
|
Loading…
Reference in New Issue