Commit 65faebb9 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'qa/gb/rspec-decouple-test-instance-address' into 'master'

Decouple QA test subject's address from Capybara/RSpec

Closes gitlab-qa#88

See merge request gitlab-org/gitlab-ce!15310
parents 58dd9d73 2c468dfd
...@@ -3,7 +3,7 @@ module QA ...@@ -3,7 +3,7 @@ module QA
module Main module Main
class Entry < Page::Base class Entry < Page::Base
def initialize def initialize
visit('/') visit(Runtime::Scenario.gitlab_address)
# This resolves cold boot / background tasks problems # This resolves cold boot / background tasks problems
# #
......
...@@ -7,18 +7,8 @@ module QA ...@@ -7,18 +7,8 @@ module QA
class Entrypoint < Template class Entrypoint < Template
include Bootable include Bootable
def self.tags(*tags)
@tags = tags
end
def self.get_tags
@tags
end
def perform(address, *files) def perform(address, *files)
Specs::Config.perform do |specs| Runtime::Scenario.define(:gitlab_address, address)
specs.address = address
end
## ##
# Perform before hooks, which are different for CE and EE # Perform before hooks, which are different for CE and EE
...@@ -26,13 +16,19 @@ module QA ...@@ -26,13 +16,19 @@ module QA
Runtime::Release.perform_before_hooks Runtime::Release.perform_before_hooks
Specs::Runner.perform do |specs| Specs::Runner.perform do |specs|
specs.rspec( specs.tty = true
tty: true, specs.tags = self.class.get_tags
tags: self.class.get_tags, specs.files = files.any? ? files : 'qa/specs/features'
files: files.any? ? files : 'qa/specs/features'
)
end end
end end
def self.tags(*tags)
@tags = tags
end
def self.get_tags
@tags
end
end end
end end
end end
...@@ -9,15 +9,7 @@ require 'selenium-webdriver' ...@@ -9,15 +9,7 @@ require 'selenium-webdriver'
module QA module QA
module Specs module Specs
class Config < Scenario::Template class Config < Scenario::Template
attr_writer :address
def initialize
@address = ENV['GITLAB_URL']
end
def perform def perform
raise 'Please configure GitLab address!' unless @address
configure_rspec! configure_rspec!
configure_capybara! configure_capybara!
end end
...@@ -56,7 +48,6 @@ module QA ...@@ -56,7 +48,6 @@ module QA
end end
Capybara.configure do |config| Capybara.configure do |config|
config.app_host = @address
config.default_driver = :chrome config.default_driver = :chrome
config.javascript_driver = :chrome config.javascript_driver = :chrome
config.default_max_wait_time = 4 config.default_max_wait_time = 4
......
...@@ -2,16 +2,22 @@ require 'rspec/core' ...@@ -2,16 +2,22 @@ require 'rspec/core'
module QA module QA
module Specs module Specs
class Runner class Runner < Scenario::Template
include Scenario::Actable attr_accessor :tty, :tags, :files
def rspec(tty: false, tags: [], files: ['qa/specs/features']) def initialize
args = [] @tty = false
args << '--tty' if tty @tags = []
tags.to_a.each do |tag| @files = ['qa/specs/features']
args << ['-t', tag.to_s]
end end
args << files
def perform
args = []
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| RSpec::Core::Runner.run(args.flatten, $stderr, $stdout).tap do |status|
abort if status.nonzero? abort if status.nonzero?
......
...@@ -6,31 +6,30 @@ describe QA::Scenario::Entrypoint do ...@@ -6,31 +6,30 @@ describe QA::Scenario::Entrypoint do
end end
context '#perform' do context '#perform' do
let(:config) { spy('Specs::Config') } let(:arguments) { spy('Runtime::Scenario') }
let(:release) { spy('Runtime::Release') } let(:release) { spy('Runtime::Release') }
let(:runner) { spy('Specs::Runner') } let(:runner) { spy('Specs::Runner') }
before do 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::Release', release)
stub_const('QA::Runtime::Scenario', arguments)
stub_const('QA::Specs::Runner', runner) stub_const('QA::Specs::Runner', runner)
allow(runner).to receive(:perform).and_yield(runner)
end end
it 'should set address' do it 'sets an address of the subject' do
subject.perform("hello") subject.perform("hello")
expect(config).to have_received(:address=).with("hello") expect(arguments).to have_received(:define)
.with(:gitlab_address, "hello")
end end
context 'no paths' do context 'no paths' do
it 'should call runner with default arguments' do it 'should call runner with default arguments' do
subject.perform("test") subject.perform("test")
expect(runner).to have_received(:rspec) expect(runner).to have_received(:files=).with('qa/specs/features')
.with(hash_including(files: 'qa/specs/features'))
end end
end end
...@@ -38,8 +37,7 @@ describe QA::Scenario::Entrypoint do ...@@ -38,8 +37,7 @@ describe QA::Scenario::Entrypoint do
it 'should call runner with paths' do it 'should call runner with paths' do
subject.perform('test', 'path1', 'path2') subject.perform('test', 'path1', 'path2')
expect(runner).to have_received(:rspec) expect(runner).to have_received(:files=).with(%w[path1 path2])
.with(hash_including(files: %w(path1 path2)))
end end
end end
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