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

config_spec.rb « rspec_flaky « tooling « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c95e5475d66a81297f226eb61b297709d3543a6c (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# frozen_string_literal: true

require 'rspec-parameterized'
require_relative '../../support/helpers/stub_env'

require_relative '../../../tooling/rspec_flaky/config'

RSpec.describe RspecFlaky::Config, :aggregate_failures do
  include StubENV

  before do
    # Stub these env variables otherwise specs don't behave the same on the CI
    stub_env('FLAKY_RSPEC_GENERATE_REPORT', nil)
    stub_env('FLAKY_RSPEC_SUITE_REPORT_PATH', nil)
    stub_env('FLAKY_RSPEC_REPORT_PATH', nil)
    stub_env('NEW_FLAKY_RSPEC_REPORT_PATH', nil)
    stub_env('SKIPPED_FLAKY_TESTS_REPORT_PATH', nil)
    # Ensure the behavior is the same locally and on CI (where Rails is defined since we run this test as part of the whole suite), i.e. Rails isn't defined
    allow(described_class).to receive(:rails_path).and_wrap_original do |method, path|
      path
    end
  end

  describe '.generate_report?' do
    context "when ENV['FLAKY_RSPEC_GENERATE_REPORT'] is not set" do
      it 'returns false' do
        expect(described_class).not_to be_generate_report
      end
    end

    context "when ENV['FLAKY_RSPEC_GENERATE_REPORT'] is set" do
      using RSpec::Parameterized::TableSyntax

      where(:env_value, :result) do
        '1'      | true
        'true'   | true
        'foo'    | false
        '0'      | false
        'false'  | false
      end

      with_them do
        before do
          stub_env('FLAKY_RSPEC_GENERATE_REPORT', env_value)
        end

        it 'returns false' do
          expect(described_class.generate_report?).to be(result)
        end
      end
    end
  end

  describe '.suite_flaky_examples_report_path' do
    context "when ENV['FLAKY_RSPEC_SUITE_REPORT_PATH'] is not set" do
      it 'returns the default path' do
        expect(described_class.suite_flaky_examples_report_path).to eq('rspec/flaky/suite-report.json')
      end
    end

    context "when ENV['FLAKY_RSPEC_SUITE_REPORT_PATH'] is set" do
      before do
        stub_env('FLAKY_RSPEC_SUITE_REPORT_PATH', 'foo/suite-report.json')
      end

      it 'returns the value of the env variable' do
        expect(described_class.suite_flaky_examples_report_path).to eq('foo/suite-report.json')
      end
    end
  end

  describe '.flaky_examples_report_path' do
    context "when ENV['FLAKY_RSPEC_REPORT_PATH'] is not set" do
      it 'returns the default path' do
        expect(described_class.flaky_examples_report_path).to eq('rspec/flaky/report.json')
      end
    end

    context "when ENV['FLAKY_RSPEC_REPORT_PATH'] is set" do
      before do
        stub_env('FLAKY_RSPEC_REPORT_PATH', 'foo/report.json')
      end

      it 'returns the value of the env variable' do
        expect(described_class.flaky_examples_report_path).to eq('foo/report.json')
      end
    end
  end

  describe '.new_flaky_examples_report_path' do
    context "when ENV['NEW_FLAKY_RSPEC_REPORT_PATH'] is not set" do
      it 'returns the default path' do
        expect(described_class.new_flaky_examples_report_path).to eq('rspec/flaky/new-report.json')
      end
    end

    context "when ENV['NEW_FLAKY_RSPEC_REPORT_PATH'] is set" do
      before do
        stub_env('NEW_FLAKY_RSPEC_REPORT_PATH', 'foo/new-report.json')
      end

      it 'returns the value of the env variable' do
        expect(described_class.new_flaky_examples_report_path).to eq('foo/new-report.json')
      end
    end
  end

  describe '.skipped_flaky_tests_report_path' do
    context "when ENV['SKIPPED_FLAKY_TESTS_REPORT_PATH'] is not set" do
      it 'returns the default path' do
        expect(described_class.skipped_flaky_tests_report_path).to eq('rspec/flaky/skipped_flaky_tests_report.txt')
      end
    end

    context "when ENV['SKIPPED_FLAKY_TESTS_REPORT_PATH'] is set" do
      before do
        stub_env('SKIPPED_FLAKY_TESTS_REPORT_PATH', 'foo/skipped_flaky_tests_report.txt')
      end

      it 'returns the value of the env variable' do
        expect(described_class.skipped_flaky_tests_report_path).to eq('foo/skipped_flaky_tests_report.txt')
      end
    end
  end
end