diff options
author | Rémy Coutable <remy@rymai.me> | 2018-09-10 10:53:21 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2018-09-10 10:53:21 +0000 |
commit | 816e846a43255d6a3103bb84472c114a6282ba4b (patch) | |
tree | 813cbf8e1af12ee045b65468a53e64f64b635b53 /qa | |
parent | a5517ada119a0e73e0a70fd18e11fda3932138e8 (diff) | |
parent | dd85ea6a9dad26acbf8add2777f53faa1cd1ef1b (diff) | |
download | gitlab-ce-816e846a43255d6a3103bb84472c114a6282ba4b.tar.gz |
Merge branch 'qa-fix-specs-runner-when-args-given' into 'master'
[QA] Fix arguments passed to RSpec::Core::Runner
See merge request gitlab-org/gitlab-ce!21578
Diffstat (limited to 'qa')
-rw-r--r-- | qa/qa/specs/runner.rb | 7 | ||||
-rw-r--r-- | qa/spec/specs/runner_spec.rb | 60 |
2 files changed, 46 insertions, 21 deletions
diff --git a/qa/qa/specs/runner.rb b/qa/qa/specs/runner.rb index 5b5699d8a93..fea0ef94df3 100644 --- a/qa/qa/specs/runner.rb +++ b/qa/qa/specs/runner.rb @@ -5,10 +5,12 @@ module QA class Runner < Scenario::Template attr_accessor :tty, :tags, :options + DEFAULT_TEST_PATH_ARGS = ['--', File.expand_path('./features', __dir__)].freeze + def initialize @tty = false @tags = [] - @options = [File.expand_path('./features', __dir__)] + @options = [] end def perform @@ -18,10 +20,11 @@ module QA if tags.any? tags.each { |tag| args.push(['--tag', tag.to_s]) } else - args.push(%w[--tag ~orchestrated]) + args.push(%w[--tag ~orchestrated]) unless (%w[-t --tag] & options).any? end args.push(options) + args.push(DEFAULT_TEST_PATH_ARGS) unless options.any? { |opt| opt =~ %r{/features/} } Runtime::Browser.configure! diff --git a/qa/spec/specs/runner_spec.rb b/qa/spec/specs/runner_spec.rb index b237b954889..cf22d1c9395 100644 --- a/qa/spec/specs/runner_spec.rb +++ b/qa/spec/specs/runner_spec.rb @@ -7,43 +7,65 @@ describe QA::Specs::Runner do end it 'excludes the orchestrated tag by default' do - expect(RSpec::Core::Runner).to receive(:run) - .with(['--tag', '~orchestrated', File.expand_path('../../qa/specs/features', __dir__)], $stderr, $stdout) - .and_return(0) + expect_rspec_runner_arguments(['--tag', '~orchestrated', *described_class::DEFAULT_TEST_PATH_ARGS]) subject.perform end context 'when tty is set' do - subject do - described_class.new.tap do |runner| - runner.tty = true - end - end + subject { described_class.new.tap { |runner| runner.tty = true } } it 'sets the `--tty` flag' do - expect(RSpec::Core::Runner).to receive(:run) - .with(['--tty', '--tag', '~orchestrated', File.expand_path('../../qa/specs/features', __dir__)], $stderr, $stdout) - .and_return(0) + expect_rspec_runner_arguments(['--tty', '--tag', '~orchestrated', *described_class::DEFAULT_TEST_PATH_ARGS]) subject.perform end end context 'when tags are set' do - subject do - described_class.new.tap do |runner| - runner.tags = %i[orchestrated github] - end - end + subject { described_class.new.tap { |runner| runner.tags = %i[orchestrated github] } } it 'focuses on the given tags' do - expect(RSpec::Core::Runner).to receive(:run) - .with(['--tag', 'orchestrated', '--tag', 'github', File.expand_path('../../qa/specs/features', __dir__)], $stderr, $stdout) - .and_return(0) + expect_rspec_runner_arguments(['--tag', 'orchestrated', '--tag', 'github', *described_class::DEFAULT_TEST_PATH_ARGS]) + + 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 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 |