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

template_spec.rb « scenario « spec « qa - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9800f92b3063b3a24e74963152bd3e26763cf84a (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
# frozen_string_literal: true

RSpec.describe QA::Scenario::Template do
  let(:feature) { spy('Runtime::Feature') }
  let(:release) { spy('Runtime::Release') }
  let(:gitlab_address) { 'https://gitlab.com/' }

  before do
    stub_const('QA::Runtime::Release', release)
    stub_const('QA::Runtime::Feature', feature)
    allow(QA::Specs::Runner).to receive(:perform)
    allow(QA::Runtime::Address).to receive(:valid?).and_return(true)
  end

  it 'allows a feature to be enabled' do
    subject.perform({ gitlab_address: gitlab_address, enable_feature: 'a-feature' })

    expect(feature).to have_received(:enable).with('a-feature')
  end

  it 'allows a feature to be disabled' do
    allow(QA::Runtime::Feature).to receive(:enabled?)
                                     .with('another-feature').and_return(true)

    subject.perform({ gitlab_address: gitlab_address, disable_feature: 'another-feature' })

    expect(feature).to have_received(:disable).with('another-feature')
  end

  it 'does not disable a feature if already disabled' do
    allow(QA::Runtime::Feature).to receive(:enabled?)
                                     .with('another-feature').and_return(false)

    subject.perform({ gitlab_address: gitlab_address, disable_feature: 'another-feature' })

    expect(feature).not_to have_received(:disable).with('another-feature')
  end

  it 'ensures an enabled feature is disabled afterwards' do
    allow(QA::Specs::Runner).to receive(:perform).and_raise('failed test')

    expect { subject.perform({ gitlab_address: gitlab_address, enable_feature: 'a-feature' }) }.to raise_error('failed test')

    expect(feature).to have_received(:enable).with('a-feature')
    expect(feature).to have_received(:disable).with('a-feature')
  end

  it 'ensures a disabled feature is enabled afterwards' do
    allow(QA::Specs::Runner).to receive(:perform).and_raise('failed test')

    allow(QA::Runtime::Feature).to receive(:enabled?)
                                     .with('another-feature').and_return(true)

    expect { subject.perform({ gitlab_address: gitlab_address, disable_feature: 'another-feature' }) }.to raise_error('failed test')

    expect(feature).to have_received(:disable).with('another-feature')
    expect(feature).to have_received(:enable).with('another-feature')
  end

  it 'ensures a disabled feature is not enabled afterwards if it was disabled earlier' do
    allow(QA::Specs::Runner).to receive(:perform).and_raise('failed test')

    allow(QA::Runtime::Feature).to receive(:enabled?)
                                     .with('another-feature').and_return(false)

    expect { subject.perform({ gitlab_address: gitlab_address, disable_feature: 'another-feature' }) }.to raise_error('failed test')

    expect(feature).not_to have_received(:disable).with('another-feature')
    expect(feature).not_to have_received(:enable).with('another-feature')
  end

  it 'defines an about address by default' do
    subject.perform( { gitlab_address: gitlab_address })

    expect(QA::Runtime::Scenario.gitlab_address).to eq(gitlab_address)
    expect(QA::Runtime::Scenario.about_address).to eq('https://about.gitlab.com/')

    subject.perform({ gitlab_address: 'http://gitlab-abc.test/' })

    expect(QA::Runtime::Scenario.gitlab_address).to eq('http://gitlab-abc.test/')
    expect(QA::Runtime::Scenario.about_address).to eq('http://about.gitlab-abc.test/')
  end
end