BigW Consortium Gitlab

spec_helper.rb 1.94 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 30
  config.include Devise::Test::ControllerHelpers, type: :controller
  config.include Devise::Test::ControllerHelpers, type: :view
31
  config.include Warden::Test::Helpers, type: :request
32 33
  config.include LoginHelpers, type: :feature
  config.include SearchHelpers, type: :feature
34
  config.include StubConfiguration
35
  config.include EmailHelpers, type: :mailer
Robert Speicher committed
36
  config.include TestEnv
37
  config.include ActiveJob::TestHelper
38
  config.include ActiveSupport::Testing::TimeHelpers
39 40
  config.include StubGitlabCalls
  config.include StubGitlabData
41

42
  config.infer_spec_type_from_file_location!
43
  config.raise_errors_for_deprecations!
Robert Speicher committed
44 45

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

  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
55 56 57

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

60
    example.run
61

62
    Gitlab::Redis.with(&:flushall)
63
    Sidekiq.redis(&:flushall)
64
  end
Andrew8xx8 committed
65
end
66

Kamil Trzcinski committed
67 68 69 70
FactoryGirl::SyntaxRunner.class_eval do
  include RSpec::Mocks::ExampleMethods
end

71
ActiveRecord::Migration.maintain_test_schema!