BigW Consortium Gitlab

spec_helper.rb 2.49 KB
Newer Older
1 2
require './spec/simplecov_env'
SimpleCovEnv.start!
3

4
ENV["RAILS_ENV"] ||= 'test'
5
ENV["IN_MEMORY_APPLICATION_SETTINGS"] = 'true'
6

7
require File.expand_path("../../config/environment", __FILE__)
Robert Speicher committed
8
require 'rspec/rails'
9
require 'shoulda/matchers'
Kamil Trzcinski committed
10
require 'rspec/retry'
Kamil Trzcinski committed
11

12 13
if (ENV['RSPEC_PROFILING_POSTGRES_URL'] || ENV['RSPEC_PROFILING']) &&
    (!ENV.has_key?('CI') || ENV['CI_COMMIT_REF_NAME'] == 'master')
14 15 16
  require 'rspec_profiling/rspec'
end

17
if ENV['CI'] && !ENV['NO_KNAPSACK']
18 19 20
  require 'knapsack'
  Knapsack::Adapters::RSpecAdapter.bind
end
Robert Speicher committed
21 22 23

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
24
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
Robert Speicher committed
25 26

RSpec.configure do |config|
Jeroen van Baarsen committed
27 28
  config.use_transactional_fixtures = false
  config.use_instantiated_fixtures  = false
Robert Speicher committed
29 30
  config.mock_with :rspec

Kamil Trzcinski committed
31 32 33
  config.verbose_retry = true
  config.display_try_failure_messages = true

34 35
  config.include Devise::Test::ControllerHelpers, type: :controller
  config.include Devise::Test::ControllerHelpers, type: :view
36
  config.include Warden::Test::Helpers, type: :request
37 38
  config.include LoginHelpers, type: :feature
  config.include SearchHelpers, type: :feature
39
  config.include WaitForRequests, :js
40
  config.include WaitForAjax, :js
41
  config.include StubConfiguration
42
  config.include EmailHelpers, type: :mailer
Robert Speicher committed
43
  config.include TestEnv
44
  config.include ActiveJob::TestHelper
45
  config.include ActiveSupport::Testing::TimeHelpers
46 47
  config.include StubGitlabCalls
  config.include StubGitlabData
48
  config.include ApiHelpers, :api
49

50
  config.infer_spec_type_from_file_location!
51 52 53 54 55

  config.define_derived_metadata(file_path: %r{/spec/requests/(ci/)?api/}) do |metadata|
    metadata[:api] = true
  end

56
  config.raise_errors_for_deprecations!
Robert Speicher committed
57 58

  config.before(:suite) do
59
    TestEnv.init
Robert Speicher committed
60
  end
61

62 63 64 65 66 67 68
  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

69 70 71 72 73 74
  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
75 76 77

  config.around(:each, :redis) do |example|
    Gitlab::Redis.with(&:flushall)
78 79
    Sidekiq.redis(&:flushall)

80
    example.run
81

82
    Gitlab::Redis.with(&:flushall)
83
    Sidekiq.redis(&:flushall)
84
  end
Andrew8xx8 committed
85
end
86

Kamil Trzcinski committed
87 88 89 90
FactoryGirl::SyntaxRunner.class_eval do
  include RSpec::Mocks::ExampleMethods
end

91
ActiveRecord::Migration.maintain_test_schema!