BigW Consortium Gitlab

spec_helper.rb 2.1 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 14 15
if ENV['RSPEC_PROFILING_POSTGRES_URL'] || ENV['RSPEC_PROFILING']
  require 'rspec_profiling/rspec'
end

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

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

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

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

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

47
  config.infer_spec_type_from_file_location!
48
  config.raise_errors_for_deprecations!
Robert Speicher committed
49 50

  config.before(:suite) do
51
    TestEnv.init
Robert Speicher committed
52
  end
53 54 55 56 57 58 59

  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
60 61 62

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

65
    example.run
66

67
    Gitlab::Redis.with(&:flushall)
68
    Sidekiq.redis(&:flushall)
69
  end
Andrew8xx8 committed
70
end
71

Kamil Trzcinski committed
72 73 74 75
FactoryGirl::SyntaxRunner.class_eval do
  include RSpec::Mocks::ExampleMethods
end

76
ActiveRecord::Migration.maintain_test_schema!