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

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

shared_examples 'a QA scenario class' do
  let(:attributes) { spy('Runtime::Scenario') }
  let(:runner) { spy('Specs::Runner') }
  let(:release) { spy('Runtime::Release') }
  let(:feature) { spy('Runtime::Feature') }

  let(:args) { { gitlab_address: 'http://gitlab_address' } }
  let(:named_options) { %w[--address http://gitlab_address] }
  let(:tags) { [] }
  let(:options) { %w[path1 path2] }

  before do
    stub_const('QA::Specs::Runner', runner)
    stub_const('QA::Runtime::Release', release)
    stub_const('QA::Runtime::Scenario', attributes)
    stub_const('QA::Runtime::Feature', feature)

    allow(runner).to receive(:perform).and_yield(runner)
    allow(QA::Runtime::Address).to receive(:valid?).and_return(true)
  end

  it 'responds to perform' do
    expect(subject).to respond_to(:perform)
  end

  it 'sets an address of the subject' do
    subject.perform(args)

    expect(attributes).to have_received(:define).with(:gitlab_address, 'http://gitlab_address').at_least(:once)
  end

  it 'sets tags on runner' do
    subject.perform(args)

    expect(runner).to have_received(:tags=).with(tags)
  end

  context 'specifying RSpec options' do
    it 'sets options on runner' do
      subject.perform(args, *options)

      expect(runner).to have_received(:options=).with(options)
    end
  end

  context 'with named command-line options' do
    it 'converts options to attributes' do
      described_class.launch!(named_options)

      args do |k, v|
        expect(attributes).to have_received(:define).with(k, v)
      end
    end

    it 'raises an error if the option is invalid' do
      expect { described_class.launch!(['--foo']) }.to raise_error(OptionParser::InvalidOption)
    end

    it 'passes on options after --' do
      expect(described_class).to receive(:perform).with(attributes, *%w[--tag quarantine])

      described_class.launch!(named_options.push(*%w[-- --tag quarantine]))
    end
  end
end