Commit 235145e7 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'qa/gb/global-qa-scenario-arguments-ee' into 'master'

Global QA scenario arguments / EE version

See merge request gitlab-org/gitlab-ee!3329
parents 76cca713 a051190d
tmp/ tmp/
.ruby-version
...@@ -4,4 +4,4 @@ require_relative '../qa' ...@@ -4,4 +4,4 @@ require_relative '../qa'
QA::Scenario QA::Scenario
.const_get(ARGV.shift) .const_get(ARGV.shift)
.perform(*ARGV) .launch!(ARGV)
...@@ -18,6 +18,7 @@ module QA ...@@ -18,6 +18,7 @@ module QA
## ##
# Support files # Support files
# #
autoload :Bootable, 'qa/scenario/bootable'
autoload :Actable, 'qa/scenario/actable' autoload :Actable, 'qa/scenario/actable'
autoload :Entrypoint, 'qa/scenario/entrypoint' autoload :Entrypoint, 'qa/scenario/entrypoint'
autoload :Template, 'qa/scenario/template' autoload :Template, 'qa/scenario/template'
......
...@@ -3,7 +3,7 @@ module QA ...@@ -3,7 +3,7 @@ module QA
module Mattermost module Mattermost
class Login < Page::Base class Login < Page::Base
def initialize def initialize
visit(Runtime::Scenario.mattermost + '/login') visit(Runtime::Scenario.mattermost_address + '/login')
end end
def sign_in_using_oauth def sign_in_using_oauth
......
...@@ -3,7 +3,7 @@ module QA ...@@ -3,7 +3,7 @@ module QA
module Mattermost module Mattermost
class Main < Page::Base class Main < Page::Base
def initialize def initialize
visit(Runtime::Scenario.mattermost) visit(Runtime::Scenario.mattermost_address)
end end
end end
end end
......
module QA module QA
module Runtime module Runtime
##
# Singleton approach to global test scenario arguments.
#
module Scenario module Scenario
extend self extend self
attr_accessor :mattermost
attr_reader :attributes
def define(attribute, value)
(@attributes ||= {}).store(attribute.to_sym, value)
define_singleton_method(attribute) do
@attributes[attribute.to_sym].tap do |value|
if value.to_s.empty?
raise ArgumentError, "Empty `#{attribute}` attribute!"
end
end
end
end
def method_missing(name, *)
raise ArgumentError, "Scenario attribute `#{name}` not defined!"
end
end end
end end
end end
require 'optparse'
module QA
module Scenario
module Bootable
Option = Struct.new(:name, :arg, :desc)
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def launch!(argv)
return self.perform(*argv) unless has_attributes?
arguments = OptionParser.new do |parser|
options.to_a.each do |opt|
parser.on(opt.arg, opt.desc) do |value|
Runtime::Scenario.define(opt.name, value)
end
end
end
arguments.parse!(argv)
self.perform(**Runtime::Scenario.attributes)
end
private
def attribute(name, arg, desc)
options.push(Option.new(name, arg, desc))
end
def options
@options ||= []
end
def has_attributes?
options.any?
end
end
end
end
end
...@@ -5,6 +5,8 @@ module QA ...@@ -5,6 +5,8 @@ module QA
# including staging and on-premises installation. # including staging and on-premises installation.
# #
class Entrypoint < Template class Entrypoint < Template
include Bootable
def self.tags(*tags) def self.tags(*tags)
@tags = tags @tags = tags
end end
......
...@@ -10,8 +10,9 @@ module QA ...@@ -10,8 +10,9 @@ module QA
tags :mattermost tags :mattermost
def perform(address, mattermost, *files) def perform(address, mattermost, *files)
Runtime::Scenario.mattermost = mattermost Runtime::Scenario.define(:mattermost_address, mattermost)
super(address, files)
super(address, *files)
end end
end end
end end
......
describe QA::Runtime::Scenario do
subject do
Module.new.extend(described_class)
end
it 'makes it possible to define global scenario attributes' do
subject.define(:my_attribute, 'some-value')
subject.define(:another_attribute, 'another-value')
expect(subject.my_attribute).to eq 'some-value'
expect(subject.another_attribute).to eq 'another-value'
expect(subject.attributes)
.to eq(my_attribute: 'some-value', another_attribute: 'another-value')
end
it 'raises error when attribute is not known' do
expect { subject.invalid_accessor }
.to raise_error ArgumentError, /invalid_accessor/
end
it 'raises error when attribute is empty' do
subject.define(:empty_attribute, '')
expect { subject.empty_attribute }
.to raise_error ArgumentError, /empty_attribute/
end
end
describe QA::Scenario::Bootable do
subject do
Class.new(QA::Scenario::Template)
.include(described_class)
end
it 'makes it possible to define the scenario attribute' do
subject.class_eval do
attribute :something, '--something SOMETHING', 'Some attribute'
attribute :another, '--another ANOTHER', 'Some other attribute'
end
expect(subject).to receive(:perform)
.with(something: 'test', another: 'other')
subject.launch!(%w[--another other --something test])
end
it 'does not require attributes to be defined' do
expect(subject).to receive(:perform).with('some', 'argv')
subject.launch!(%w[some argv])
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment