Class: Resat::ScenarioRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/scenario_runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc, schemasdir, config, variables, failonerror, dry_run) ⇒ ScenarioRunner

Instantiate new scenario runner with given YAML definition document and schemas directory. If parsing the scenario YAML definition fails then ‘valid?’ returns false and ‘parser_errors’ contains the error messages.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/scenario_runner.rb', line 24

def initialize(doc, schemasdir, config, variables, failonerror, dry_run)
  @schemasdir     = schemasdir
  @valid          = true
  @ignored        = false
  @name           = ''
  @failures       = Array.new
  @requests_count = 0
  @failonerror    = failonerror
  @dry_run        = dry_run
  parse(doc)
  if @valid
    @config = Config.new(config || @cfg_file, schemasdir)
    @valid = @config.valid?
    if @valid
      @variables = Variables.new
      @variables.load(@config.input, schemasdir) if @config.input && File.readable?(@config.input)
      @config.variables.each { |v| @variables[v['name']] = v['value'] } if @config.variables
      variables.each { |k, v| @variables[k] = v } if variables
    end
  end
end

Instance Attribute Details

#failuresObject

Returns the value of attribute failures.



18
19
20
# File 'lib/scenario_runner.rb', line 18

def failures
  @failures
end

#parser_errorsObject

Returns the value of attribute parser_errors.



18
19
20
# File 'lib/scenario_runner.rb', line 18

def parser_errors
  @parser_errors
end

#requests_countObject

Returns the value of attribute requests_count.



18
19
20
# File 'lib/scenario_runner.rb', line 18

def requests_count
  @requests_count
end

#variablesObject

Returns the value of attribute variables.



18
19
20
# File 'lib/scenario_runner.rb', line 18

def variables
  @variables
end

Instance Method Details

#ignored?Boolean

Returns:

  • (Boolean)


46
# File 'lib/scenario_runner.rb', line 46

def ignored?;   @ignored;         end

#runObject

Run the scenario. Once scenario has run check ‘succeeded?’. If ‘succeeded?’ returns false, use ‘failures’ to retrieve error messages.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/scenario_runner.rb', line 53

def run
  return if @ignored || !@valid
  Log.info("-" * 80 + "\nRunning scenario #{@name}")
  unless @variables.empty?
    info_msg = @variables.all.inject("Using variables:") do |msg, (k, v)|
      msg << "\n   - #{k}: #{v}"
    end
    Log.info(info_msg)
  end
  @steps.each_index do |index|
    @current_step = index
    @current_file = @steps[index][:origin]
    step = @steps[index][:step]
    case step
    when ApiRequest
      @requests_count += @request.send_count if @request # Last request
      @request = step
      @request.prepare(@variables, @config)
      @request.send unless @dry_run
    when Guard
      step.prepare(@variables)
      step.wait(@request) unless @dry_run
    when Filter, Handler
      step.prepare(@variables)
      step.run(@request) unless @dry_run 
    end
    puts step.inspect if step.failures.nil?
    step.failures.each { |f| add_failure(f) }
    break if @failonerror && !succeeded? # Abort on failure
  end

  @requests_count += @request.send_count
  @variables.save(@config.output) if @config.output
end

#succeeded?Boolean

Returns:

  • (Boolean)


48
# File 'lib/scenario_runner.rb', line 48

def succeeded?; @failures.empty?; end

#valid?Boolean

parser_errors contains the details

Returns:

  • (Boolean)


47
# File 'lib/scenario_runner.rb', line 47

def valid?;     @valid;           end