summaryrefslogtreecommitdiff
path: root/qa/qa/scenario/template.rb
blob: b8ea26e805e5003d6b35e290066ac82133cd6bb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
module QA
  module Scenario
    class Template
      class << self
        def perform(*args)
          new.tap do |scenario|
            yield scenario if block_given?
            break scenario.perform(*args)
          end
        end

        def tags(*tags)
          @tags = tags
        end

        def focus
          @tags.to_a
        end
      end

      def perform(options, *args)
        extract_address(:gitlab_address, options, args)

        ##
        # Perform before hooks, which are different for CE and EE
        #
        Runtime::Release.perform_before_hooks

        Runtime::Feature.enable(options[:enable_feature]) if options.key?(:enable_feature)

        Specs::Runner.perform do |specs|
          specs.tty = true
          specs.tags = self.class.focus
          specs.options = args if args.any?
        end
      ensure
        Runtime::Feature.disable(options[:enable_feature]) if options.key?(:enable_feature)
      end

      def extract_option(name, options, args)
        option = if options.key?(name)
                   options[name]
                 else
                   args.shift
                 end

        Runtime::Scenario.define(name, option)

        option
      end

      # For backwards-compatibility, if the gitlab instance address is not
      # specified as an option parsed by OptionParser, it can be specified as
      # the first argument
      def extract_address(name, options, args)
        address = extract_option(name, options, args)

        raise ::ArgumentError, "The address provided for `#{name}` is not valid: #{address}" unless Runtime::Address.valid?(address)
      end
    end
  end
end