Module: CiTest

Defined in:
lib/test_case/ci_test.rb

Instance Method Summary collapse

Instance Method Details

#runObject



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
# File 'lib/test_case/ci_test.rb', line 3

def run
  # The behavior of a CI script is controlled by script options, so that multiple CI tests can use the same script,
  # but with different inputs/outputs depending on the needs of the test.
  ci_actions = Hash[test_data.fetch(:_ci_actions, {})].fetch(id, [])
  ci_actions = [ci_actions] unless ci_actions.is_a?(Array)
  logger.info("CI Actions: #{ci_actions.inspect}")

  # Perform test actions by step
  ci_actions.each do |ci_action|
    # Define actions
    do_actions = proc do
      # Get the actions list
      actions = ci_action.fetch(:actions, [])
      actions = [actions] unless actions.is_a?(Array)
      actions.each do |action|
        obj = self
        # Get the methods list
        methods = action.fetch(:method, [])
        methods = [methods] unless methods.is_a?(Array)
        # Get the params list
        params = action.fetch(:params, [])
        params = [params] unless params.is_a?(Array)
        logger.info("#{methods.join('.')}(#{params.map {|p| p.inspect}.join(', ')})", tag: 'ACTION')
        methods.each_with_index do |sym, i|
          if params.empty? || i < (methods.count - 1)
            # Send method
            obj = obj.send(sym.to_sym)
          else
            # Send final method with specified parameters
            obj = obj.send(sym.to_sym, *params)
          end
        end
      end
    end

    # Perform actions, in a step if specified
    if ci_action[:step].nil?
      do_actions.call
    else
      test_step(ci_action[:step], name: 'Verify something', &do_actions)
    end
  end

end