summaryrefslogtreecommitdiff
path: root/qa/spec/resource/events/project_spec.rb
blob: 88d50749a0a641d8788f16ed08f2f6c54221c0d6 (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
# frozen_string_literal: true

RSpec.describe QA::Resource::Events::Project do
  let(:resource) do
    Class.new(QA::Resource::Base) do
      def api_get_path
        '/foo'
      end
    end
  end

  let(:all_events) do
    [
      {
        "action_name": "pushed",
        "push_data": {
          "commit_title": "foo commit"
        }
      },
      {
        "action_name": "pushed",
        "push_data": {
          "ref": "master"
        }
      },
      {
        "action_name": "pushed",
        "push_data": {
          "ref": "another-branch"
        }
      }
    ]
  end

  before do
    allow(subject).to receive(:max_wait).and_return(0.01)
    allow(subject).to receive(:raise_on_failure).and_return(false)
    allow(subject).to receive(:parse_body).and_return(all_events)
  end

  subject { resource.tap { |f| f.include(described_class) }.new }

  describe "#wait_for_push" do
    it 'waits for a push with a specified commit message' do
      expect(subject).to receive(:api_get_from).with('/foo/events?action=pushed')
      expect { subject.wait_for_push('foo commit') }.not_to raise_error
    end

    it 'raises an error if a push with the specified commit message is not found' do
      expect(subject).to receive(:api_get_from).with('/foo/events?action=pushed').at_least(:once)
      expect { subject.wait_for_push('bar') }.to raise_error(QA::Resource::Events::EventNotFoundError)
    end
  end

  describe "#wait_for_push_new_branch" do
    it 'waits for a push to master if no branch is given' do
      expect(subject).to receive(:api_get_from).with('/foo/events?action=pushed')
      expect { subject.wait_for_push_new_branch }.not_to raise_error
    end

    it 'waits for a push to the given branch' do
      expect(subject).to receive(:api_get_from).with('/foo/events?action=pushed')
      expect { subject.wait_for_push_new_branch('another-branch') }.not_to raise_error
    end

    it 'raises an error if a push with the specified branch is not found' do
      expect(subject).to receive(:api_get_from).with('/foo/events?action=pushed').at_least(:once)
      expect { subject.wait_for_push_new_branch('bar') }.to raise_error(QA::Resource::Events::EventNotFoundError)
    end
  end
end