BigW Consortium Gitlab

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

4
ENV["RAILS_ENV"] ||= 'test'
5

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

12
if ENV['CI'] && !ENV['NO_KNAPSACK']
13 14 15
  require 'knapsack'
  Knapsack::Adapters::RSpecAdapter.bind
end
Robert Speicher committed
16 17 18

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

RSpec.configure do |config|
Jeroen van Baarsen committed
22 23
  config.use_transactional_fixtures = false
  config.use_instantiated_fixtures  = false
Robert Speicher committed
24 25
  config.mock_with :rspec

Kamil Trzcinski committed
26 27 28
  config.verbose_retry = true
  config.display_try_failure_messages = true

29
  config.include Devise::Test::ControllerHelpers,   type: :controller
30 31
  config.include Warden::Test::Helpers, type: :request
  config.include LoginHelpers,          type: :feature
32
  config.include StubConfiguration
33
  config.include EmailHelpers
Robert Speicher committed
34
  config.include TestEnv
35
  config.include ActiveJob::TestHelper
36
  config.include ActiveSupport::Testing::TimeHelpers
37 38
  config.include StubGitlabCalls
  config.include StubGitlabData
39

40
  config.infer_spec_type_from_file_location!
41
  config.raise_errors_for_deprecations!
Robert Speicher committed
42 43

  config.before(:suite) do
44
    TestEnv.init
Robert Speicher committed
45
  end
46 47 48 49 50 51 52

  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
53 54 55 56 57 58

  config.around(:each, :redis) do |example|
    Gitlab::Redis.with(&:flushall)
    example.run
    Gitlab::Redis.with(&:flushall)
  end
Andrew8xx8 committed
59
end
60

Kamil Trzcinski committed
61 62 63 64
FactoryGirl::SyntaxRunner.class_eval do
  include RSpec::Mocks::ExampleMethods
end

65
ActiveRecord::Migration.maintain_test_schema!