diff options
Diffstat (limited to 'qa/spec/resource/events/project_spec.rb')
-rw-r--r-- | qa/spec/resource/events/project_spec.rb | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/qa/spec/resource/events/project_spec.rb b/qa/spec/resource/events/project_spec.rb new file mode 100644 index 00000000000..b3efdb518f3 --- /dev/null +++ b/qa/spec/resource/events/project_spec.rb @@ -0,0 +1,69 @@ +# frozen_string_literal: true + +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(: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 |