2016-09-13 17:45:13 +05:30
|
|
|
require './spec/simplecov_env'
|
|
|
|
SimpleCovEnv.start!
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
ENV["RAILS_ENV"] ||= 'test'
|
2017-08-17 22:00:37 +05:30
|
|
|
ENV["IN_MEMORY_APPLICATION_SETTINGS"] = 'true'
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
require File.expand_path("../../config/environment", __FILE__)
|
2014-09-02 18:07:02 +05:30
|
|
|
require 'rspec/rails'
|
2015-09-11 14:41:01 +05:30
|
|
|
require 'shoulda/matchers'
|
2016-06-02 11:05:42 +05:30
|
|
|
require 'rspec/retry'
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
rspec_profiling_is_configured =
|
2017-09-10 17:25:29 +05:30
|
|
|
ENV['RSPEC_PROFILING_POSTGRES_URL'].present? ||
|
2017-08-17 22:00:37 +05:30
|
|
|
ENV['RSPEC_PROFILING']
|
|
|
|
branch_can_be_profiled =
|
|
|
|
ENV['GITLAB_DATABASE'] == 'postgresql' &&
|
|
|
|
(ENV['CI_COMMIT_REF_NAME'] == 'master' ||
|
|
|
|
ENV['CI_COMMIT_REF_NAME'] =~ /rspec-profile/)
|
|
|
|
|
|
|
|
if rspec_profiling_is_configured && (!ENV.key?('CI') || branch_can_be_profiled)
|
|
|
|
require 'rspec_profiling/rspec'
|
|
|
|
end
|
|
|
|
|
|
|
|
if ENV['CI'] && !ENV['NO_KNAPSACK']
|
2016-06-16 23:09:34 +05:30
|
|
|
require 'knapsack'
|
|
|
|
Knapsack::Adapters::RSpecAdapter.bind
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
# require rainbow gem String monkeypatch, so we can test SystemChecks
|
|
|
|
require 'rainbow/ext/string'
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
|
|
|
# in spec/support/ and its subdirectories.
|
2015-09-11 14:41:01 +05:30
|
|
|
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
RSpec.configure do |config|
|
|
|
|
config.use_transactional_fixtures = false
|
|
|
|
config.use_instantiated_fixtures = false
|
|
|
|
config.mock_with :rspec
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
config.verbose_retry = true
|
|
|
|
config.display_try_failure_messages = true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
config.include Devise::Test::ControllerHelpers, type: :controller
|
|
|
|
config.include Devise::Test::ControllerHelpers, type: :view
|
2017-09-10 17:25:29 +05:30
|
|
|
config.include Devise::Test::IntegrationHelpers, type: :feature
|
2016-09-29 09:46:39 +05:30
|
|
|
config.include Warden::Test::Helpers, type: :request
|
2017-08-17 22:00:37 +05:30
|
|
|
config.include LoginHelpers, type: :feature
|
|
|
|
config.include SearchHelpers, type: :feature
|
|
|
|
config.include WaitForRequests, :js
|
2015-09-11 14:41:01 +05:30
|
|
|
config.include StubConfiguration
|
2017-09-10 17:25:29 +05:30
|
|
|
config.include EmailHelpers, :mailer, type: :mailer
|
2014-09-02 18:07:02 +05:30
|
|
|
config.include TestEnv
|
2015-12-23 02:04:40 +05:30
|
|
|
config.include ActiveJob::TestHelper
|
2016-09-13 17:45:13 +05:30
|
|
|
config.include ActiveSupport::Testing::TimeHelpers
|
2015-09-25 12:07:36 +05:30
|
|
|
config.include StubGitlabCalls
|
|
|
|
config.include StubGitlabData
|
2017-08-17 22:00:37 +05:30
|
|
|
config.include ApiHelpers, :api
|
2017-09-10 17:25:29 +05:30
|
|
|
config.include Gitlab::Routing, type: :routing
|
|
|
|
config.include MigrationsHelpers, :migration
|
|
|
|
config.include StubFeatureFlags
|
|
|
|
config.include StubENV
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
config.infer_spec_type_from_file_location!
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
config.define_derived_metadata(file_path: %r{/spec/requests/(ci/)?api/}) do |metadata|
|
|
|
|
metadata[:api] = true
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
config.raise_errors_for_deprecations!
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
config.before(:suite) do
|
|
|
|
TestEnv.init
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
config.after(:suite) do
|
|
|
|
TestEnv.cleanup
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
config.before(:example) do
|
|
|
|
# Skip pre-receive hook check so we can use the web editor and merge.
|
|
|
|
allow_any_instance_of(Gitlab::Git::Hook).to receive(:trigger).and_return([true, nil])
|
|
|
|
# Enable all features by default for testing
|
|
|
|
allow(Feature).to receive(:enabled?) { true }
|
|
|
|
end
|
|
|
|
|
|
|
|
config.before(:example, :request_store) do
|
|
|
|
RequestStore.begin!
|
|
|
|
end
|
|
|
|
|
|
|
|
config.after(:example, :request_store) do
|
|
|
|
RequestStore.end!
|
|
|
|
RequestStore.clear!
|
|
|
|
end
|
|
|
|
|
|
|
|
config.before(:example, :mailer) do
|
|
|
|
reset_delivered_emails!
|
|
|
|
end
|
|
|
|
|
|
|
|
# Stub the `ForkedStorageCheck.storage_available?` method unless
|
|
|
|
# `:broken_storage` metadata is defined
|
|
|
|
#
|
|
|
|
# This check can be slow and is unnecessary in a test environment where we
|
|
|
|
# know the storage is available, because we create it at runtime
|
|
|
|
config.before(:example) do |example|
|
|
|
|
unless example.metadata[:broken_storage]
|
|
|
|
allow(Gitlab::Git::Storage::ForkedStorageCheck)
|
|
|
|
.to receive(:storage_available?).and_return(true)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
config.around(:each, :use_clean_rails_memory_store_caching) do |example|
|
2016-08-24 12:49:21 +05:30
|
|
|
caching_store = Rails.cache
|
2017-09-10 17:25:29 +05:30
|
|
|
Rails.cache = ActiveSupport::Cache::MemoryStore.new
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
example.run
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
Rails.cache = caching_store
|
|
|
|
end
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
config.around(:each, :clean_gitlab_redis_cache) do |example|
|
|
|
|
Gitlab::Redis::Cache.with(&:flushall)
|
|
|
|
|
|
|
|
example.run
|
|
|
|
|
|
|
|
Gitlab::Redis::Cache.with(&:flushall)
|
|
|
|
end
|
|
|
|
|
|
|
|
config.around(:each, :clean_gitlab_redis_shared_state) do |example|
|
|
|
|
Gitlab::Redis::SharedState.with(&:flushall)
|
2017-08-17 22:00:37 +05:30
|
|
|
Sidekiq.redis(&:flushall)
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
example.run
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
Gitlab::Redis::SharedState.with(&:flushall)
|
2017-08-17 22:00:37 +05:30
|
|
|
Sidekiq.redis(&:flushall)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
config.before(:each, :migration) do
|
|
|
|
schema_migrate_down!
|
|
|
|
end
|
|
|
|
|
|
|
|
config.after(:context, :migration) do
|
|
|
|
schema_migrate_up!
|
|
|
|
end
|
|
|
|
|
|
|
|
config.around(:each, :nested_groups) do |example|
|
|
|
|
example.run if Group.supports_nested_groups?
|
|
|
|
end
|
|
|
|
|
|
|
|
config.around(:each, :postgresql) do |example|
|
|
|
|
example.run if Gitlab::Database.postgresql?
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2015-10-24 18:46:33 +05:30
|
|
|
FactoryGirl::SyntaxRunner.class_eval do
|
|
|
|
include RSpec::Mocks::ExampleMethods
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
ActiveRecord::Migration.maintain_test_schema!
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
Shoulda::Matchers.configure do |config|
|
|
|
|
config.integrate do |with|
|
|
|
|
with.test_framework :rspec
|
|
|
|
with.library :rails
|
|
|
|
end
|
|
|
|
end
|