debian-mirror-gitlab/spec/spec_helper.rb

103 lines
2.7 KiB
Ruby
Raw Normal View History

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 =
ENV['RSPEC_PROFILING_POSTGRES_URL'] ||
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']
require 'knapsack'
Knapsack::Adapters::RSpecAdapter.bind
end
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
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
config.include WaitForAjax, :js
2015-09-11 14:41:01 +05:30
config.include StubConfiguration
2017-08-17 22:00:37 +05:30
config.include EmailHelpers, 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
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
if ENV['CI']
# Retry only on feature specs that use JS
config.around :each, :js do |ex|
ex.run_with_retry retry: 3
end
end
2016-08-24 12:49:21 +05:30
config.around(:each, :caching) do |example|
caching_store = Rails.cache
Rails.cache = ActiveSupport::Cache::MemoryStore.new if example.metadata[:caching]
example.run
Rails.cache = caching_store
end
2016-11-03 12:29:30 +05:30
config.around(:each, :redis) do |example|
Gitlab::Redis.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
2016-11-03 12:29:30 +05:30
Gitlab::Redis.with(&:flushall)
2017-08-17 22:00:37 +05:30
Sidekiq.redis(&:flushall)
2016-11-03 12:29:30 +05:30
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!