summaryrefslogtreecommitdiff
path: root/qa/spec
diff options
context:
space:
mode:
Diffstat (limited to 'qa/spec')
-rw-r--r--qa/spec/service/docker_run/gitlab_runner_spec.rb2
-rw-r--r--qa/spec/service/docker_run/k3s_spec.rb2
-rw-r--r--qa/spec/spec_helper.rb3
-rw-r--r--qa/spec/support/matchers/have_file.rb15
-rw-r--r--qa/spec/support/matchers/have_text.rb48
-rw-r--r--qa/spec/support/shared_examples/merge_with_code_owner_shared_examples.rb2
-rw-r--r--qa/spec/support/shared_examples/scenario_shared_examples.rb106
7 files changed, 123 insertions, 55 deletions
diff --git a/qa/spec/service/docker_run/gitlab_runner_spec.rb b/qa/spec/service/docker_run/gitlab_runner_spec.rb
index db1bb74ca8f..34d95943321 100644
--- a/qa/spec/service/docker_run/gitlab_runner_spec.rb
+++ b/qa/spec/service/docker_run/gitlab_runner_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
module QA
- describe Service::DockerRun::GitlabRunner do
+ RSpec.describe Service::DockerRun::GitlabRunner do
let(:runner_name) { 'test-runner' }
let(:address) { 'gitlab.test' }
let(:token) { 'abc123' }
diff --git a/qa/spec/service/docker_run/k3s_spec.rb b/qa/spec/service/docker_run/k3s_spec.rb
index 0224b7d6704..e994fbdd30e 100644
--- a/qa/spec/service/docker_run/k3s_spec.rb
+++ b/qa/spec/service/docker_run/k3s_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
module QA
- describe Service::DockerRun::K3s do
+ RSpec.describe Service::DockerRun::K3s do
describe '#host_name' do
context 'in CI' do
let(:name) { 'k3s-12345' }
diff --git a/qa/spec/spec_helper.rb b/qa/spec/spec_helper.rb
index 81730c3ab13..9785d0a9014 100644
--- a/qa/spec/spec_helper.rb
+++ b/qa/spec/spec_helper.rb
@@ -14,10 +14,13 @@ QA::Runtime::Browser.configure!
QA::Runtime::Scenario.from_env(QA::Runtime::Env.runtime_scenario_attributes) if QA::Runtime::Env.runtime_scenario_attributes
Dir[::File.join(__dir__, "support/helpers/*.rb")].sort.each { |f| require f }
+Dir[::File.join(__dir__, "support/matchers/*.rb")].sort.each { |f| require f }
Dir[::File.join(__dir__, "support/shared_contexts/*.rb")].sort.each { |f| require f }
Dir[::File.join(__dir__, "support/shared_examples/*.rb")].sort.each { |f| require f }
RSpec.configure do |config|
+ config.include ::Matchers
+
QA::Specs::Helpers::Quarantine.configure_rspec
config.before do |example|
diff --git a/qa/spec/support/matchers/have_file.rb b/qa/spec/support/matchers/have_file.rb
new file mode 100644
index 00000000000..2ae295d5ca2
--- /dev/null
+++ b/qa/spec/support/matchers/have_file.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+module Matchers
+ module HaveFile
+ RSpec::Matchers.define :have_file do |file|
+ match do |page_object|
+ page_object.has_file?(file)
+ end
+
+ match_when_negated do |page_object|
+ page_object.has_no_file?(file)
+ end
+ end
+ end
+end
diff --git a/qa/spec/support/matchers/have_text.rb b/qa/spec/support/matchers/have_text.rb
new file mode 100644
index 00000000000..4e6fbf1f6d6
--- /dev/null
+++ b/qa/spec/support/matchers/have_text.rb
@@ -0,0 +1,48 @@
+# frozen_string_literal: true
+
+module Matchers
+ class HaveText
+ def initialize(expected_text, **kwargs)
+ @expected_text = expected_text
+ @kwargs = kwargs
+ end
+
+ def matches?(actual)
+ @actual = wrap(actual)
+ @actual.has_text?(@expected_text, **@kwargs)
+ end
+
+ def does_not_match?(actual)
+ @actual = wrap(actual)
+ @actual.has_no_text?(@expected_text, **@kwargs)
+ end
+
+ def failure_message
+ "expected to find text \"#{@expected_text}\" in \"#{normalized_actual_text}\""
+ end
+
+ def failure_message_when_negated
+ "expected not to find text \"#{@expected_text}\" in \"#{normalized_actual_text}\""
+ end
+
+ def normalized_actual_text
+ @actual.text.gsub(/\s+/, " ")
+ end
+
+ # From https://github.com/teamcapybara/capybara/blob/fe5940c6afbfe32152df936ce03ad1371ae05354/lib/capybara/rspec/matchers/base.rb#L66
+ def wrap(actual)
+ actual = actual.to_capybara_node if actual.respond_to?(:to_capybara_node)
+ @context_el = if actual.respond_to?(:has_selector?)
+ actual
+ else
+ Capybara.string(actual.to_s)
+ end
+ end
+ end
+
+ def have_text(text, **kwargs) # rubocop:disable Naming/PredicateName
+ HaveText.new(text, **kwargs)
+ end
+
+ alias_method :have_content, :have_text
+end
diff --git a/qa/spec/support/shared_examples/merge_with_code_owner_shared_examples.rb b/qa/spec/support/shared_examples/merge_with_code_owner_shared_examples.rb
index feaeb78815d..610bf8b9e28 100644
--- a/qa/spec/support/shared_examples/merge_with_code_owner_shared_examples.rb
+++ b/qa/spec/support/shared_examples/merge_with_code_owner_shared_examples.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
module QA
- shared_examples 'code owner merge request' do
+ RSpec.shared_examples 'code owner merge request' do
let(:branch_name) { 'new-branch' }
it 'is approved and merged' do
diff --git a/qa/spec/support/shared_examples/scenario_shared_examples.rb b/qa/spec/support/shared_examples/scenario_shared_examples.rb
index 6e20adbd4ad..637cfb9a05d 100644
--- a/qa/spec/support/shared_examples/scenario_shared_examples.rb
+++ b/qa/spec/support/shared_examples/scenario_shared_examples.rb
@@ -1,73 +1,75 @@
# 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
+module QA
+ RSpec.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 'responds to perform' do
+ expect(subject).to respond_to(:perform)
+ end
- it 'sets an address of the subject' do
- subject.perform(args)
+ 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
+ expect(attributes).to have_received(:define).with(:gitlab_address, 'http://gitlab_address').at_least(:once)
+ end
- it 'performs before hooks only once' do
- subject.perform(args)
+ it 'performs before hooks only once' do
+ subject.perform(args)
- expect(release).to have_received(:perform_before_hooks).once
- end
+ expect(release).to have_received(:perform_before_hooks).once
+ end
- it 'sets tags on runner' do
- subject.perform(args)
+ it 'sets tags on runner' do
+ subject.perform(args)
- expect(runner).to have_received(:tags=).with(tags)
- end
+ expect(runner).to have_received(:tags=).with(tags)
+ end
- context 'specifying RSpec options' do
- it 'sets options on runner' do
- subject.perform(args, *options)
+ context 'specifying RSpec options' do
+ it 'sets options on runner' do
+ subject.perform(args, *options)
- expect(runner).to have_received(:options=).with(options)
+ expect(runner).to have_received(:options=).with(options)
+ end
end
- end
- context 'with named command-line options' do
- it 'converts options to attributes' do
- described_class.launch!(named_options)
+ 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)
+ args do |k, v|
+ expect(attributes).to have_received(:define).with(k, v)
+ end
end
- end
- it 'raises an error if the option is invalid' do
- expect { described_class.launch!(['--foo']) }.to raise_error(OptionParser::InvalidOption)
- 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])
+ 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]))
+ described_class.launch!(named_options.push(*%w[-- --tag quarantine]))
+ end
end
end
end