Welcome to mirror list, hosted at ThFree Co, Russian Federation.

rspec.rb « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dfc881caddce425d3609092762b7bc1231bf64b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# frozen_string_literal: true

require_relative 'rake'
require_relative 'rspec_order'
require_relative 'rspec_run_time'
require_relative 'system_exit_detected'
require_relative 'helpers/stub_configuration'
require_relative 'helpers/stub_metrics'
require_relative 'helpers/stub_object_storage'
require_relative 'helpers/fast_rails_root'

require 'gitlab/rspec/all'
require 'gitlab/utils/all'

RSpec::Expectations.configuration.on_potential_false_positives = :raise

RSpec.configure do |config|
  # See https://gitlab.com/gitlab-org/gitlab/-/issues/379686
  config.threadsafe = false

  # Re-run failures locally with `--only-failures`
  config.example_status_persistence_file_path = ENV.fetch('RSPEC_LAST_RUN_RESULTS_FILE', './spec/examples.txt')

  config.define_derived_metadata(file_path: %r{(ee)?/spec/.+_spec\.rb\z}) do |metadata|
    # Infer metadata tag `type` if not already inferred by
    # `infer_spec_type_from_file_location!`.
    unless metadata.key?(:type)
      match = %r{/spec/([^/]+)/}.match(metadata[:location])
      metadata[:type] = match[1].singularize.to_sym if match
    end
  end

  # Makes diffs show entire non-truncated values.
  config.around(:each, :unlimited_max_formatted_output_length) do |example|
    old_max_formatted_output_length = RSpec::Support::ObjectFormatter.default_instance.max_formatted_output_length

    config.expect_with :rspec do |c|
      c.max_formatted_output_length = nil
    end

    example.run

    config.expect_with :rspec do |c|
      c.max_formatted_output_length = old_max_formatted_output_length
    end
  end

  unless ENV['CI']
    # Allow running `:focus` examples locally,
    # falling back to all tests when there is no `:focus` example.
    config.filter_run focus: true
    config.run_all_when_everything_filtered = true
  end

  config.mock_with :rspec do |mocks|
    mocks.verify_doubled_constant_names = true
  end

  config.raise_errors_for_deprecations!

  config.include StubConfiguration
  config.include StubMetrics
  config.include StubObjectStorage
  config.include StubENV
  config.include FastRailsRoot

  warn_missing_feature_category = Gitlab::Utils.to_boolean(ENV['RSPEC_WARN_MISSING_FEATURE_CATEGORY'], default: true)

  # Add warning for example missing feature_category
  config.before do |example|
    if warn_missing_feature_category && example.metadata[:feature_category].blank? && !ENV['CI']
      location =
        example.metadata[:shared_group_inclusion_backtrace].last&.formatted_inclusion_location ||
        example.location
      warn "Missing metadata feature_category: #{location} See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#feature-category-metadata"
    end
  end
end