Class: Resat::Engine

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Engine

Hash of variables hashes indexed by scenario filename



23
24
25
26
27
28
29
30
31
# File 'lib/engine.rb', line 23

def initialize(options)
  @options        = options
  @failures       = Hash.new
  @run_count      = 0
  @ignored_count  = 0
  @requests_count = 0
  @skipped_count  = 0
  @variables      = Hash.new
end

Instance Attribute Details

#failuresObject

Returns the value of attribute failures.



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

def failures
  @failures
end

#ignored_countObject

Total number of ignored scenarios



16
17
18
# File 'lib/engine.rb', line 16

def ignored_count
  @ignored_count
end

#requests_countObject

Total number of HTTP requests



15
16
17
# File 'lib/engine.rb', line 15

def requests_count
  @requests_count
end

#run_countObject

Total number of run scenarios



14
15
16
# File 'lib/engine.rb', line 14

def run_count
  @run_count
end

#skipped_countObject

Total number of skipped YAML files



17
18
19
# File 'lib/engine.rb', line 17

def skipped_count
  @skipped_count
end

#variablesObject

Hash of error messages (string arrays) indexed by scenario filename



20
21
22
# File 'lib/engine.rb', line 20

def variables
  @variables
end

Instance Method Details

#run(target = nil) ⇒ Object

Run all scenarios and set attributes accordingly



39
40
41
42
43
44
45
46
47
48
49
50
51
52
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
# File 'lib/engine.rb', line 39

def run(target=nil)
  target ||= @options.target
  begin
    if File.directory?(target)
      files = FileSet.new(target, %w{.yml .yaml})
    elsif File.file?(target)
      files = [target]
    else
      @failures[target] ||= []
      @failures[target] << "Invalid taget #{target}: Not a directory, nor a file"
      return
    end
    schemasdir = @options.schemasdir || Config::DEFAULT_SCHEMA_DIR
    files.each do |file|
      runner = ScenarioRunner.new(file, schemasdir, @options.config, 
                 @options.variables, @options.failonerror, @options.dry_run)
      @ignored_count += 1 if runner.ignored?
      @skipped_count += 1 unless runner.valid?
      if runner.valid? && !runner.ignored?
        runner.run
        @run_count += 1
        @requests_count += runner.requests_count
        if runner.succeeded?
          @variables[file] = runner.variables
        else
          @failures[file] = runner.failures
        end
      else
        unless runner.valid?
          Log.info "Skipping '#{file}' (#{runner.parser_errors})"
        end
        Log.info "Ignoring '#{file}'" if runner.ignored?
      end
    end 
  rescue Exception => e
    Log.error(e.message)
    backtrace = "   " + e.backtrace.inject("") { |msg, s| msg << "#{s}\n" }
    Log.debug(backtrace)
  end
end

#succeeded?Boolean

Was test run successful?

Returns:

  • (Boolean)


34
35
36
# File 'lib/engine.rb', line 34

def succeeded?
  @failures.size == 0
end

#summaryObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/engine.rb', line 80

def summary
  if succeeded?
    case run_count
      when 0 then res = "\nNo scenario to run."
      when 1 then res = "\nOne scenario SUCCEEDED"
      else res = "\n#{run_count} scenarios SUCCEEDED"
    end
  else
    i = 1
    res = "\nErrors summary:\n"
    failures.each do |file, errors|
      res << "\n#{i.to_s}) Scenario '#{file}' failed with: "
      errors.each do |error|
        res << "\n     "
        res << error
      end
      i = i + 1
    end
    res << "\n\n#{i - 1} of #{run_count} scenario#{'s' if run_count > 1} FAILED"
  end
  res
end