class Rutema::Engine
Rutema::Engine
implements the rutema workflow.
It instantiates the configured parser, runner and reporter instances and wires them together via Rutema::Dispatcher
The full workflow is Parse->Run->Report and corresponds to one call of the Engine#run
method
Public Class Methods
new(configuration)
click to toggle source
# File lib/rutema/core/engine.rb, line 16 def initialize configuration @queue=Queue.new @parser=instantiate_class(configuration.parser,configuration) if configuration.parser if configuration.runner if configuration.runner[:class] @runner=configuration.runner[:class].new(configuration.context,@queue) else raise RutemaError,"Runner settting overriden, but missing :class" end 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
Public Instance Methods
parse(test_identifier=nil)
click to toggle source
Parse a single test spec or all the specs listed in the configuration
# File lib/rutema/core/engine.rb, line 53 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)
click to toggle source
Parse, run, report
# File lib/rutema/core/engine.rb, line 33 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 @runner.setup=setup @runner.teardown=teardown #running - at this point we've done any and all checks and we're stepping on the gas message("running") run_scenarios(tests,suite_setup,suite_teardown) end message("end") @dispatcher.exit @dispatcher.report(tests) end
Private Instance Methods
instantiate_class(definition,configuration)
click to toggle source
# File lib/rutema/core/engine.rb, line 131 def instantiate_class definition,configuration if definition[:class] klass=definition[:class] return klass.new(configuration) end return nil end
is_spec_included?(test_identifier)
click to toggle source
# File lib/rutema/core/engine.rb, line 138 def is_spec_included? test_identifier full_path=File.expand_path(test_identifier) return @configuration.tests.include?(full_path) || is_special?(test_identifier) end
is_special?(test_identifier)
click to toggle source
# File lib/rutema/core/engine.rb, line 142 def is_special? test_identifier full_path=File.expand_path(test_identifier) return full_path==@configuration.suite_setup || full_path==@configuration.suite_teardown || full_path==@configuration.setup || full_path==@configuration.teardown end
parse_specials(configuration)
click to toggle source
# File lib/rutema/core/engine.rb, line 85 def parse_specials configuration suite_setup=nil suite_teardown=nil setup=nil teardown=nil if configuration.suite_setup suite_setup=parse_specification(configuration.suite_setup) end if configuration.suite_teardown suite_teardown=parse_specification(configuration.suite_teardown) end if configuration.setup setup=parse_specification(configuration.setup) end if configuration.teardown teardown=parse_specification(configuration.teardown) end return suite_setup,suite_teardown,setup,teardown end
parse_specification(spec_identifier)
click to toggle source
# File lib/rutema/core/engine.rb, line 77 def parse_specification spec_identifier begin @parser.parse_specification(spec_identifier) rescue Rutema::ParserError error(spec_identifier,$!.message) raise Rutema::ParserError, "In #{spec_identifier}: #{$!.message}" end end
parse_specifications(tests)
click to toggle source
# File lib/rutema/core/engine.rb, line 72 def parse_specifications tests tests.map do |t| parse_specification(t) end.compact end
run_scenarios(specs,suite_setup,suite_teardown)
click to toggle source
# File lib/rutema/core/engine.rb, line 104 def run_scenarios specs,suite_setup,suite_teardown if specs.empty? error(nil,"No tests to run") else if suite_setup if run_test(suite_setup)==:success specs.each{|s| run_test(s)} else error(nil,"Suite setup test failed") end else specs.each{|spec| run_test(spec)} end if suite_teardown run_test(suite_teardown) end end end
run_test(specification)
click to toggle source
# File lib/rutema/core/engine.rb, line 122 def run_test specification if specification.scenario status=@runner.run(specification)["status"] else status=:not_executed message(:test=>specification.name,:text=>"No scenario", :status=>status) end return status end