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

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

RSpec.describe QA::Support::Run do
  let(:class_instance) { (Class.new { include QA::Support::Run }).new }
  let(:response) { 'successful response' }
  let(:command) { 'some command' }
  let(:expected_result) { described_class::Result.new("#{command} 2>&1", 0, response) }

  it 'runs successfully' do
    expect(Open3).to receive(:capture2e).and_return([+response, double(exitstatus: 0)])

    expect(class_instance.run(command)).to eq(expected_result)
  end

  it 'retries twice and succeeds the third time' do
    allow(Open3).to receive(:capture2e).and_return([+'', double(exitstatus: 1)]).twice
    allow(Open3).to receive(:capture2e).and_return([+response, double(exitstatus: 0)])

    expect(class_instance.run(command)).to eq(expected_result)
  end

  it 'raises an exception on 3rd failure' do
    allow(Open3).to receive(:capture2e).and_return([+'FAILURE', double(exitstatus: 1)]).thrice

    expect { class_instance.run(command) }.to raise_error(QA::Support::Run::CommandError, /The command .* failed \(1\) with the following output:\nFAILURE/)
  end
end