Class: Rutema::Engine

Inherits:
Object
  • Object
show all
Includes:
Messaging
Defined in:
lib/rutema/core/engine.rb

Overview

Class implementing the inner workflow of rutema

This class takes care of instantiating the configured parser, runner and reporters. The reporters then receive event information from the runner through a Dispatcher instance.

The full workflow consists of subsequent parse, run and report phases and corresponds to one call of the #run method.

Instance Method Summary collapse

Methods included from Messaging

#error, #message

Constructor Details

#initialize(configuration) ⇒ Engine

Initialize a new Engine instance and setup all class instances needed for test execution

This brings up a parser, the runner and the reporters and wires them up as needed. After completion of this method the instance is ready for test execution by means of the #run method.

  • configuration - a Configuration instance according to which Engine, its components and the test run shall be set up

Raises:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rutema/core/engine.rb', line 31

def initialize(configuration)
  @queue = Queue.new
  @parser = instantiate_class(configuration.parser, configuration) if configuration.parser
  if configuration.runner
    raise RutemaError, "Runner settting overriden, but missing :class" unless configuration.runner[:class]

    @runner = configuration.runner[:class].new(configuration.context, @queue)

  else
    @runner = Rutema::Runners::Default.new(configuration.context, @queue)
  end
  raise RutemaError, "Could not instantiate parser" unless @parser

  @dispatcher = Dispatcher.new(@queue, configuration)
  @configuration = configuration
end

Instance Method Details

#parse(test_identifier = nil) ⇒ Object

Parse a single test specification or all the specs given by the configuration

  • test_identifier - an optional identifier of a single test case to be executed, this cannot be an arbitrary one but must still be contained in the configured test specification identifiers


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/rutema/core/engine.rb', line 79

def parse(test_identifier = nil)
  specs = []
  # so, while we are parsing, we have a list of tests
  # we're either parsing all of the tests, or just one
  # make sure the one test is on the list
  if test_identifier
    if is_spec_included?(test_identifier)
      specs << parse_specification(File.expand_path(test_identifier))
    else
      error(File.expand_path(test_identifier), "does not exist in the configuration")
    end
  else
    specs = parse_specifications(@configuration.tests)
  end
  specs.compact!
  suite_setup, suite_teardown, setup, teardown = parse_specials(@configuration)
  return [suite_setup, suite_teardown, setup, teardown, specs]
end

#run(test_identifier = nil) ⇒ Object

Parse the test specifications, execute the test(s) and report the results

  • test_identifier - an optional identifier of a single test case to be executed, this cannot be an arbitrary one but must still be contained in the configured test specification identifiers


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/rutema/core/engine.rb', line 54

def run(test_identifier = nil)
  @dispatcher.run!
  # start
  message("start")
  suite_setup, suite_teardown, setup, teardown, tests = *parse(test_identifier)
  if tests.empty?
    @dispatcher.exit
    raise RutemaError, "No tests to run!"
  else
    # running - at this point all checks are done and the tests are active
    message("running")
    run_scenarios(tests, suite_setup, suite_teardown, setup, teardown)
  end
  message("end")
  @dispatcher.exit
  @dispatcher.report(tests)
end