diff options
author | Mark Lapierre <mlapierre@gitlab.com> | 2019-02-11 09:04:59 +0000 |
---|---|---|
committer | Ramya Authappan <rauthappan@gitlab.com> | 2019-02-11 09:04:59 +0000 |
commit | 97265d39e72cbb32468a3f1d671820528af02a8b (patch) | |
tree | 03c7d01e071ce0843987ad6f1eb96234fa20074a /qa/spec | |
parent | 25af9032750c215860829fecb196da1e1c5ace6b (diff) | |
download | gitlab-ce-97265d39e72cbb32468a3f1d671820528af02a8b.tar.gz |
[CE] Improve `wait_for_push`
Diffstat (limited to 'qa/spec')
-rw-r--r-- | qa/spec/git/repository_spec.rb | 2 | ||||
-rw-r--r-- | qa/spec/helpers/stub_env.rb (renamed from qa/spec/support/stub_env.rb) | 2 | ||||
-rw-r--r-- | qa/spec/page/base_spec.rb | 30 | ||||
-rw-r--r-- | qa/spec/page/logging_spec.rb | 13 | ||||
-rw-r--r-- | qa/spec/resource/base_spec.rb | 2 | ||||
-rw-r--r-- | qa/spec/resource/events/base_spec.rb | 29 | ||||
-rw-r--r-- | qa/spec/resource/events/project_spec.rb | 69 | ||||
-rw-r--r-- | qa/spec/runtime/api/client_spec.rb | 2 | ||||
-rw-r--r-- | qa/spec/runtime/env_spec.rb | 2 | ||||
-rw-r--r-- | qa/spec/shared_examples/scenario_shared_examples.rb (renamed from qa/spec/support/shared_examples/scenario_shared_examples.rb) | 0 | ||||
-rw-r--r-- | qa/spec/spec_helper.rb | 4 | ||||
-rw-r--r-- | qa/spec/support/waiter_spec.rb | 37 |
12 files changed, 184 insertions, 8 deletions
diff --git a/qa/spec/git/repository_spec.rb b/qa/spec/git/repository_spec.rb index 4a350cd6c42..62c81050bd9 100644 --- a/qa/spec/git/repository_spec.rb +++ b/qa/spec/git/repository_spec.rb @@ -1,5 +1,5 @@ describe QA::Git::Repository do - include Support::StubENV + include Helpers::StubENV shared_context 'git directory' do let(:repository) { described_class.new } diff --git a/qa/spec/support/stub_env.rb b/qa/spec/helpers/stub_env.rb index 4788e0ab46c..62b4a1df787 100644 --- a/qa/spec/support/stub_env.rb +++ b/qa/spec/helpers/stub_env.rb @@ -1,5 +1,5 @@ # Inspired by https://github.com/ljkbennett/stub_env/blob/master/lib/stub_env/helpers.rb -module Support +module Helpers module StubENV def stub_env(key_or_hash, value = nil) init_stub unless env_stubbed? diff --git a/qa/spec/page/base_spec.rb b/qa/spec/page/base_spec.rb index 076a8087db5..32a350f2154 100644 --- a/qa/spec/page/base_spec.rb +++ b/qa/spec/page/base_spec.rb @@ -59,4 +59,34 @@ describe QA::Page::Base do end end end + + describe '#wait' do + subject { Class.new(described_class).new } + + context 'when the condition is true' do + it 'does not refresh' do + expect(subject).not_to receive(:refresh) + + subject.wait(max: 0.01) { true } + end + + it 'returns true' do + expect(subject.wait(max: 0.1) { true }).to be_truthy + end + end + + context 'when the condition is false' do + it 'refreshes' do + expect(subject).to receive(:refresh).at_least(:once) + + subject.wait(max: 0.01) { false } + end + + it 'returns false' do + allow(subject).to receive(:refresh) + + expect(subject.wait(max: 0.01) { false }).to be_falsey + end + end + end end diff --git a/qa/spec/page/logging_spec.rb b/qa/spec/page/logging_spec.rb index f289ee3c2bb..a6e9601cee4 100644 --- a/qa/spec/page/logging_spec.rb +++ b/qa/spec/page/logging_spec.rb @@ -4,8 +4,6 @@ require 'capybara/dsl' require 'logger' describe QA::Support::Page::Logging do - include Support::StubENV - let(:page) { double.as_null_object } before do @@ -31,11 +29,22 @@ describe QA::Support::Page::Logging do it 'logs wait' do expect { subject.wait(max: 0) {} } + .to output(/next wait uses reload: true/).to_stdout_from_any_process + expect { subject.wait(max: 0) {} } .to output(/with wait/).to_stdout_from_any_process expect { subject.wait(max: 0) {} } .to output(/ended wait after .* seconds$/).to_stdout_from_any_process end + it 'logs wait with reload false' do + expect { subject.wait(max: 0, reload: false) {} } + .to output(/next wait uses reload: false/).to_stdout_from_any_process + expect { subject.wait(max: 0, reload: false) {} } + .to output(/with wait/).to_stdout_from_any_process + expect { subject.wait(max: 0, reload: false) {} } + .to output(/ended wait after .* seconds$/).to_stdout_from_any_process + end + it 'logs scroll_to' do expect { subject.scroll_to(:element) } .to output(/scrolling to :element/).to_stdout_from_any_process diff --git a/qa/spec/resource/base_spec.rb b/qa/spec/resource/base_spec.rb index a2a3ad01749..4a6b76c869f 100644 --- a/qa/spec/resource/base_spec.rb +++ b/qa/spec/resource/base_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true describe QA::Resource::Base do - include Support::StubENV + include Helpers::StubENV let(:resource) { spy('resource') } let(:location) { 'http://location' } diff --git a/qa/spec/resource/events/base_spec.rb b/qa/spec/resource/events/base_spec.rb new file mode 100644 index 00000000000..9cdf4785092 --- /dev/null +++ b/qa/spec/resource/events/base_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +describe QA::Resource::Events::Base do + let(:resource) do + Class.new(QA::Resource::Base) do + def api_get_path + '/foo' + end + end + end + + subject { resource.tap { |f| f.include(described_class) }.new } + + describe "#events" do + it 'fetches all events when called without parameters' do + allow(subject).to receive(:parse_body).and_return('returned') + + expect(subject).to receive(:api_get_from).with('/foo/events') + expect(subject.events).to eq('returned') + end + + it 'fetches events with a specified action type' do + allow(subject).to receive(:parse_body).and_return('returned') + + expect(subject).to receive(:api_get_from).with('/foo/events?action=pushed') + expect(subject.events(action: 'pushed')).to eq('returned') + end + end +end 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 diff --git a/qa/spec/runtime/api/client_spec.rb b/qa/spec/runtime/api/client_spec.rb index 975586b505f..af43facc73d 100644 --- a/qa/spec/runtime/api/client_spec.rb +++ b/qa/spec/runtime/api/client_spec.rb @@ -1,5 +1,5 @@ describe QA::Runtime::API::Client do - include Support::StubENV + include Helpers::StubENV describe 'initialization' do it 'defaults to :gitlab address' do diff --git a/qa/spec/runtime/env_spec.rb b/qa/spec/runtime/env_spec.rb index bc0ec08d66d..fc51f45c3a1 100644 --- a/qa/spec/runtime/env_spec.rb +++ b/qa/spec/runtime/env_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true describe QA::Runtime::Env do - include Support::StubENV + include Helpers::StubENV shared_examples 'boolean method' do |**kwargs| it_behaves_like 'boolean method with parameter', kwargs diff --git a/qa/spec/support/shared_examples/scenario_shared_examples.rb b/qa/spec/shared_examples/scenario_shared_examples.rb index 5fd55d7d96b..5fd55d7d96b 100644 --- a/qa/spec/support/shared_examples/scenario_shared_examples.rb +++ b/qa/spec/shared_examples/scenario_shared_examples.rb diff --git a/qa/spec/spec_helper.rb b/qa/spec/spec_helper.rb index 0f3cf5f4408..3e7a6dd26ee 100644 --- a/qa/spec/spec_helper.rb +++ b/qa/spec/spec_helper.rb @@ -1,6 +1,8 @@ require_relative '../qa' -Dir[::File.join(__dir__, 'support', '**', '*.rb')].each { |f| require f } +%w[helpers shared_examples].each do |d| + Dir[::File.join(__dir__, d, '**', '*.rb')].each { |f| require f } +end RSpec.configure do |config| ServerNotRespondingError = Class.new(RuntimeError) diff --git a/qa/spec/support/waiter_spec.rb b/qa/spec/support/waiter_spec.rb new file mode 100644 index 00000000000..8283b65e1be --- /dev/null +++ b/qa/spec/support/waiter_spec.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +require 'logger' + +describe QA::Support::Waiter do + before do + logger = ::Logger.new $stdout + logger.level = ::Logger::DEBUG + QA::Runtime::Logger.logger = logger + end + + describe '.wait' do + context 'when the condition is true' do + it 'logs the start' do + expect { subject.wait(max: 0) {} } + .to output(/with wait: max 0; interval 0.1/).to_stdout_from_any_process + end + + it 'logs the end' do + expect { subject.wait(max: 0) {} } + .to output(/ended wait after .* seconds$/).to_stdout_from_any_process + end + end + + context 'when the condition is false' do + it 'logs the start' do + expect { subject.wait(max: 0) { false } } + .to output(/with wait: max 0; interval 0.1/).to_stdout_from_any_process + end + + it 'logs the end' do + expect { subject.wait(max: 0) { false } } + .to output(/ended wait after .* seconds$/).to_stdout_from_any_process + end + end + end +end |