Commit dd85ea6a authored by Rémy Coutable's avatar Rémy Coutable

[QA] Fix arguments passed to RSpec::Core::Runner

- When -t or --tag are passed, we shouldn't exclude the :orchestrated tag
- When test path is passed, we shouldn't append the default test path
Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 13202722
...@@ -5,10 +5,12 @@ module QA ...@@ -5,10 +5,12 @@ module QA
class Runner < Scenario::Template class Runner < Scenario::Template
attr_accessor :tty, :tags, :options attr_accessor :tty, :tags, :options
DEFAULT_TEST_PATH_ARGS = ['--', File.expand_path('./features', __dir__)].freeze
def initialize def initialize
@tty = false @tty = false
@tags = [] @tags = []
@options = [File.expand_path('./features', __dir__)] @options = []
end end
def perform def perform
...@@ -18,10 +20,11 @@ module QA ...@@ -18,10 +20,11 @@ module QA
if tags.any? if tags.any?
tags.each { |tag| args.push(['--tag', tag.to_s]) } tags.each { |tag| args.push(['--tag', tag.to_s]) }
else else
args.push(%w[--tag ~orchestrated]) args.push(%w[--tag ~orchestrated]) unless (%w[-t --tag] & options).any?
end end
args.push(options) args.push(options)
args.push(DEFAULT_TEST_PATH_ARGS) unless options.any? { |opt| opt =~ %r{/features/} }
Runtime::Browser.configure! Runtime::Browser.configure!
......
...@@ -7,43 +7,65 @@ describe QA::Specs::Runner do ...@@ -7,43 +7,65 @@ describe QA::Specs::Runner do
end end
it 'excludes the orchestrated tag by default' do it 'excludes the orchestrated tag by default' do
expect(RSpec::Core::Runner).to receive(:run) expect_rspec_runner_arguments(['--tag', '~orchestrated', *described_class::DEFAULT_TEST_PATH_ARGS])
.with(['--tag', '~orchestrated', File.expand_path('../../qa/specs/features', __dir__)], $stderr, $stdout)
.and_return(0)
subject.perform subject.perform
end end
context 'when tty is set' do context 'when tty is set' do
subject do subject { described_class.new.tap { |runner| runner.tty = true } }
described_class.new.tap do |runner|
runner.tty = true
end
end
it 'sets the `--tty` flag' do it 'sets the `--tty` flag' do
expect(RSpec::Core::Runner).to receive(:run) expect_rspec_runner_arguments(['--tty', '--tag', '~orchestrated', *described_class::DEFAULT_TEST_PATH_ARGS])
.with(['--tty', '--tag', '~orchestrated', File.expand_path('../../qa/specs/features', __dir__)], $stderr, $stdout)
.and_return(0)
subject.perform subject.perform
end end
end end
context 'when tags are set' do context 'when tags are set' do
subject do subject { described_class.new.tap { |runner| runner.tags = %i[orchestrated github] } }
described_class.new.tap do |runner|
runner.tags = %i[orchestrated github]
end
end
it 'focuses on the given tags' do it 'focuses on the given tags' do
expect(RSpec::Core::Runner).to receive(:run) expect_rspec_runner_arguments(['--tag', 'orchestrated', '--tag', 'github', *described_class::DEFAULT_TEST_PATH_ARGS])
.with(['--tag', 'orchestrated', '--tag', 'github', File.expand_path('../../qa/specs/features', __dir__)], $stderr, $stdout)
.and_return(0) subject.perform
end
end
context 'when "--tag smoke" is set as options' do
subject { described_class.new.tap { |runner| runner.options = %w[--tag smoke] } }
it 'focuses on the given tag without excluded the orchestrated tag' do
expect_rspec_runner_arguments(['--tag', 'smoke', *described_class::DEFAULT_TEST_PATH_ARGS])
subject.perform
end
end
context 'when "qa/specs/features/foo" is set as options' do
subject { described_class.new.tap { |runner| runner.options = %w[qa/specs/features/foo] } }
it 'passes the given tests path and excludes the orchestrated tag' do
expect_rspec_runner_arguments(['--tag', '~orchestrated', 'qa/specs/features/foo'])
subject.perform subject.perform
end end
end end
context 'when "-- qa/specs/features/foo" is set as options' do
subject { described_class.new.tap { |runner| runner.options = %w[-- qa/specs/features/foo] } }
it 'passes the given tests path and excludes the orchestrated tag' do
expect_rspec_runner_arguments(['--tag', '~orchestrated', '--', 'qa/specs/features/foo'])
subject.perform
end
end
def expect_rspec_runner_arguments(arguments)
expect(RSpec::Core::Runner).to receive(:run)
.with(arguments, $stderr, $stdout)
.and_return(0)
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