From 14238ee238697a80defc480bc8385dc91550598d Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 10 Nov 2017 09:15:20 +0100 Subject: Fix bootable scenario arguments for OptionParser --- qa/qa/scenario/bootable.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/qa/qa/scenario/bootable.rb b/qa/qa/scenario/bootable.rb index 22496bcc2fc..cf8996cd597 100644 --- a/qa/qa/scenario/bootable.rb +++ b/qa/qa/scenario/bootable.rb @@ -11,6 +11,8 @@ module QA 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| @@ -21,11 +23,7 @@ module QA arguments.parse!(argv) - if has_attributes? - self.perform(**Runtime::Scenario.attributes) - else - self.perform(*argv) - end + self.perform(**Runtime::Scenario.attributes) end private -- cgit v1.2.1 From a5ab2a5e3a708762015073b1f63c51afe584ad95 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 10 Nov 2017 09:15:40 +0100 Subject: Do not require to set Capybara app_host in RSpec --- qa/qa/page/main/entry.rb | 2 +- qa/qa/scenario/entrypoint.rb | 23 ++++++++++++----------- qa/qa/specs/config.rb | 8 +------- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/qa/qa/page/main/entry.rb b/qa/qa/page/main/entry.rb index a9810beeb29..fa1cad62741 100644 --- a/qa/qa/page/main/entry.rb +++ b/qa/qa/page/main/entry.rb @@ -3,7 +3,7 @@ module QA module Main class Entry < Page::Base def initialize - visit('/') + visit(Runtime::Scenario.gitlab_address) # This resolves cold boot / background tasks problems # diff --git a/qa/qa/scenario/entrypoint.rb b/qa/qa/scenario/entrypoint.rb index 8f708fe38ab..a6a7120aed8 100644 --- a/qa/qa/scenario/entrypoint.rb +++ b/qa/qa/scenario/entrypoint.rb @@ -7,18 +7,9 @@ module QA class Entrypoint < Template include Bootable - def self.tags(*tags) - @tags = tags - end - - def self.get_tags - @tags - end - def perform(address, *files) - Specs::Config.perform do |specs| - specs.address = address - end + Runtime::Scenario.define(:gitlab_address, address) + Specs::Config.perform ## # Perform before hooks, which are different for CE and EE @@ -33,6 +24,16 @@ module QA ) end end + + private + + def self.tags(*tags) + @tags = tags + end + + def self.get_tags + @tags + end end end end diff --git a/qa/qa/specs/config.rb b/qa/qa/specs/config.rb index 79c681168cc..b1b8d9a3ca8 100644 --- a/qa/qa/specs/config.rb +++ b/qa/qa/specs/config.rb @@ -11,13 +11,7 @@ module QA class Config < Scenario::Template attr_writer :address - def initialize - @address = ENV['GITLAB_URL'] - end - def perform - raise 'Please configure GitLab address!' unless @address - configure_rspec! configure_capybara! end @@ -56,7 +50,7 @@ module QA end Capybara.configure do |config| - config.app_host = @address + # config.app_host = @address config.default_driver = :chrome config.javascript_driver = :chrome config.default_max_wait_time = 4 -- cgit v1.2.1 From 6dc5dab7d72d609faf415c4537bf26b1e8fce3e8 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 10 Nov 2017 09:39:34 +0100 Subject: Configure RSpec from within RSpec runner class --- qa/qa/scenario/entrypoint.rb | 1 - qa/qa/specs/config.rb | 3 --- qa/qa/specs/runner.rb | 16 +++++++--------- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/qa/qa/scenario/entrypoint.rb b/qa/qa/scenario/entrypoint.rb index a6a7120aed8..db51a7365f5 100644 --- a/qa/qa/scenario/entrypoint.rb +++ b/qa/qa/scenario/entrypoint.rb @@ -9,7 +9,6 @@ module QA def perform(address, *files) Runtime::Scenario.define(:gitlab_address, address) - Specs::Config.perform ## # Perform before hooks, which are different for CE and EE diff --git a/qa/qa/specs/config.rb b/qa/qa/specs/config.rb index b1b8d9a3ca8..591ddde8ab9 100644 --- a/qa/qa/specs/config.rb +++ b/qa/qa/specs/config.rb @@ -9,8 +9,6 @@ require 'selenium-webdriver' module QA module Specs class Config < Scenario::Template - attr_writer :address - def perform configure_rspec! configure_capybara! @@ -50,7 +48,6 @@ module QA end Capybara.configure do |config| - # config.app_host = @address config.default_driver = :chrome config.javascript_driver = :chrome config.default_max_wait_time = 4 diff --git a/qa/qa/specs/runner.rb b/qa/qa/specs/runner.rb index 2aa18d5d3a1..3cfe52b350c 100644 --- a/qa/qa/specs/runner.rb +++ b/qa/qa/specs/runner.rb @@ -2,16 +2,14 @@ require 'rspec/core' module QA module Specs - class Runner - include Scenario::Actable - - def rspec(tty: false, tags: [], files: ['qa/specs/features']) + class Runner < Scenario::Template + def perform(tty: false, tags: [], files: ['qa/specs/features']) args = [] - args << '--tty' if tty - tags.to_a.each do |tag| - args << ['-t', tag.to_s] - end - args << files + args.push('--tty') if tty + tags.to_a.each { |tag| args.push(['-t', tag.to_s]) } + args.push(files) + + Specs::Config.perform RSpec::Core::Runner.run(args.flatten, $stderr, $stdout).tap do |status| abort if status.nonzero? -- cgit v1.2.1 From 3abae1a78d3b6451f486466acb73e0f21f47f035 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 10 Nov 2017 09:48:28 +0100 Subject: Improve QA test scenario entrypoint specs --- qa/spec/scenario/entrypoint_spec.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/qa/spec/scenario/entrypoint_spec.rb b/qa/spec/scenario/entrypoint_spec.rb index 3fd068b641c..61c239ff3e0 100644 --- a/qa/spec/scenario/entrypoint_spec.rb +++ b/qa/spec/scenario/entrypoint_spec.rb @@ -6,23 +6,23 @@ describe QA::Scenario::Entrypoint do end context '#perform' do - let(:config) { spy('Specs::Config') } + let(:arguments) { spy('Runtime::Scenario') } let(:release) { spy('Runtime::Release') } let(:runner) { spy('Specs::Runner') } before do - allow(config).to receive(:perform) { |&block| block.call config } - allow(runner).to receive(:perform) { |&block| block.call runner } - - stub_const('QA::Specs::Config', config) stub_const('QA::Runtime::Release', release) + stub_const('QA::Runtime::Scenario', arguments) stub_const('QA::Specs::Runner', runner) + + allow(runner).to receive(:perform).and_yield(runner) end - it 'should set address' do + it 'sets an address of the subject' do subject.perform("hello") - expect(config).to have_received(:address=).with("hello") + expect(arguments).to have_received(:define) + .with(:gitlab_address, "hello") end context 'no paths' do -- cgit v1.2.1 From 9a92c16a50b7f37b74426a454c235cf8e9ee8d9b Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 10 Nov 2017 09:57:47 +0100 Subject: Refactor QA specs runners and improve specs --- qa/qa/scenario/entrypoint.rb | 8 +++----- qa/qa/specs/runner.rb | 10 +++++++++- qa/spec/scenario/entrypoint_spec.rb | 6 ++---- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/qa/qa/scenario/entrypoint.rb b/qa/qa/scenario/entrypoint.rb index db51a7365f5..4734e4bd157 100644 --- a/qa/qa/scenario/entrypoint.rb +++ b/qa/qa/scenario/entrypoint.rb @@ -16,11 +16,9 @@ module QA Runtime::Release.perform_before_hooks Specs::Runner.perform do |specs| - specs.rspec( - tty: true, - tags: self.class.get_tags, - files: files.any? ? files : 'qa/specs/features' - ) + specs.tty = true + specs.tags = self.class.get_tags + specs.files = files.any? ? files : 'qa/specs/features' end end diff --git a/qa/qa/specs/runner.rb b/qa/qa/specs/runner.rb index 3cfe52b350c..f98b8f88e9a 100644 --- a/qa/qa/specs/runner.rb +++ b/qa/qa/specs/runner.rb @@ -3,7 +3,15 @@ require 'rspec/core' module QA module Specs class Runner < Scenario::Template - def perform(tty: false, tags: [], files: ['qa/specs/features']) + attr_accessor :tty, :tags, :files + + def initialize + @tty = false + @tags = [] + @files = ['qa/specs/features'] + end + + def perform args = [] args.push('--tty') if tty tags.to_a.each { |tag| args.push(['-t', tag.to_s]) } diff --git a/qa/spec/scenario/entrypoint_spec.rb b/qa/spec/scenario/entrypoint_spec.rb index 61c239ff3e0..aec79dcea04 100644 --- a/qa/spec/scenario/entrypoint_spec.rb +++ b/qa/spec/scenario/entrypoint_spec.rb @@ -29,8 +29,7 @@ describe QA::Scenario::Entrypoint do it 'should call runner with default arguments' do subject.perform("test") - expect(runner).to have_received(:rspec) - .with(hash_including(files: 'qa/specs/features')) + expect(runner).to have_received(:files=).with('qa/specs/features') end end @@ -38,8 +37,7 @@ describe QA::Scenario::Entrypoint do it 'should call runner with paths' do subject.perform('test', 'path1', 'path2') - expect(runner).to have_received(:rspec) - .with(hash_including(files: %w(path1 path2))) + expect(runner).to have_received(:files=).with(%w[path1 path2]) end end end -- cgit v1.2.1 From 2c468dfdafbeded7c8d5f2dc70e09d3595efa542 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 10 Nov 2017 10:22:27 +0100 Subject: Fix Rubocop offense in QA scenario entrypoint --- qa/qa/scenario/entrypoint.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/qa/qa/scenario/entrypoint.rb b/qa/qa/scenario/entrypoint.rb index 4734e4bd157..ae099fd911e 100644 --- a/qa/qa/scenario/entrypoint.rb +++ b/qa/qa/scenario/entrypoint.rb @@ -22,8 +22,6 @@ module QA end end - private - def self.tags(*tags) @tags = tags end -- cgit v1.2.1