class Oktest::Runner

Public Class Methods

new(reporter) click to toggle source
# File lib/oktest.rb, line 1485
def initialize(reporter)
  @reporter = reporter
end

Public Instance Methods

start() click to toggle source
# File lib/oktest.rb, line 1489
def start()
  #; [!xrisl] runs topics and specs.
  #; [!dth2c] clears toplvel scope list.
  @reporter.enter_all(self)
  visit_scope(THE_GLOBAL_SCOPE, -1, nil)
  THE_GLOBAL_SCOPE.clear_children()
  @reporter.exit_all(self)
end
visit_scope(scope, depth, parent) click to toggle source
# File lib/oktest.rb, line 1506
def visit_scope(scope, depth, parent)
  @reporter.enter_scope(scope) unless scope.equal?(THE_GLOBAL_SCOPE)
  #; [!5anr7] calls before_all and after_all blocks.
  call_before_all_block(scope)
  #; [!c5cw0] run specs and case_when in advance of specs and topics when SimpleReporter.
  if @reporter.order_policy() == :spec_first
    _spec_first(scope).each {|c| c.accept_visitor(self, depth+1, scope) }
  else
    scope.each_child {|c| c.accept_visitor(self, depth+1, scope) }
  end
  #
  call_after_all_block(scope)
  @reporter.exit_scope(scope) unless scope.equal?(THE_GLOBAL_SCOPE)
end
visit_spec(spec, depth, parent) click to toggle source
# File lib/oktest.rb, line 1536
def visit_spec(spec, depth, parent)
  @reporter.enter_spec(spec, depth)
  #; [!u45di] runs spec block with context object which allows to call methods defined in topics.
  node = parent
  context = node.new_context_object()
  #; [!yagka] calls 'before' and 'after' blocks with context object as self.
  call_before_blocks(node, context)
  status = :PASS
  exc = nil
  #; [!yd24o] runs spec body, catching assertions or exceptions.
  begin
    params = Util.required_param_names_of_block(spec.block)
    values = params.nil? || params.empty? ? [] \
             : get_fixture_values(params, node, spec, context)
    spec.run_block_in_context_object(context, *values)
  rescue NoMemoryError   => exc;  raise exc
  rescue SignalException => exc;  raise exc
  rescue FAIL_EXCEPTION  => exc;  status = :FAIL
  rescue SKIP_EXCEPTION  => exc;  status = :SKIP
  rescue TODO_EXCEPTION  => exc;  status = :TODO
  rescue Exception       => exc;  status = :ERROR
  end
  #; [!68cnr] if TODO() called in spec...
  if context.__TODO
    #; [!6ol3p] changes PASS status to FAIL because test passed unexpectedly.
    if status == :PASS
      status = :FAIL
      exc = FAIL_EXCEPTION.new("spec should be failed (because not implemented yet), but passed unexpectedly.")
    #; [!6syw4] changes FAIL status to TODO because test failed expectedly.
    elsif status == :FAIL
      status = :TODO
      exc = TODO_EXCEPTION.new("not implemented yet")
    #; [!4aecm] changes also ERROR status to TODO because test failed expectedly.
    elsif status == :ERROR
      status = :TODO
      exc = TODO_EXCEPTION.new("#{exc.class} raised because not implemented yet")
    end
    location = context.__TODO
    exc.set_backtrace([location])
  end
  #; [!dihkr] calls 'at_end' blocks, even when exception raised.
  begin
    call_at_end_blocks(context)
  #; [!76g7q] calls 'after' blocks even when exception raised.
  ensure
    call_after_blocks(node, context)
  end
  @reporter.exit_spec(spec, depth, status, exc, parent)
end
visit_topic(topic, depth, parent) click to toggle source
# File lib/oktest.rb, line 1521
def visit_topic(topic, depth, parent)
  @reporter.enter_topic(topic, depth)
  #; [!i3yfv] calls 'before_all' and 'after_all' blocks.
  call_before_all_block(topic)
  #; [!p3a5o] run specs and case_when in advance of specs and topics when SimpleReporter.
  if @reporter.order_policy() == :spec_first
    _spec_first(topic).each {|c| c.accept_visitor(self, depth+1, topic) }
  else
    topic.each_child {|c| c.accept_visitor(self, depth+1, topic) }
  end
  #
  call_after_all_block(topic)
  @reporter.exit_topic(topic, depth)
end

Private Instance Methods

_call_blocks_child_first(node, name, context) click to toggle source
# File lib/oktest.rb, line 1603
def _call_blocks_child_first(node, name, context)
  while node
    block = node.get_hook_block(name)
    context.instance_eval(&block) if block
    node = node.parent
  end
end
_call_blocks_parent_first(node, name, context) click to toggle source
# File lib/oktest.rb, line 1592
def _call_blocks_parent_first(node, name, context)
  blocks = []
  while node
    block = node.get_hook_block(name)
    blocks << block if block
    node = node.parent
  end
  blocks.reverse.each {|blk| context.instance_eval(&blk) }
  blocks.clear
end
_spec_first(node) click to toggle source
# File lib/oktest.rb, line 1498
def _spec_first(node)
  a1, a2 = node.each_child.partition {|c|
    c.is_a?(SpecLeaf) || (c.is_a?(TopicNode) && c._prefix != '*')
  }
  return a1+a2
end
call_after_all_block(node) click to toggle source
# File lib/oktest.rb, line 1624
def call_after_all_block(node)
  block = node.get_hook_block(:after_all)
  node.instance_eval(&block) if block
end
call_after_blocks(node, context) click to toggle source
# File lib/oktest.rb, line 1615
def call_after_blocks(node, context)
  _call_blocks_child_first(node, :after, context)
end
call_at_end_blocks(context) click to toggle source
# File lib/oktest.rb, line 1629
def call_at_end_blocks(context)
  blocks = context.__at_end_blocks
  if blocks
    blocks.reverse_each {|block| context.instance_eval(&block) }
    blocks.clear
  end
end
call_before_all_block(node) click to toggle source
# File lib/oktest.rb, line 1619
def call_before_all_block(node)
  block = node.get_hook_block(:before_all)
  node.instance_eval(&block) if block
end
call_before_blocks(node, context) click to toggle source
# File lib/oktest.rb, line 1611
def call_before_blocks(node, context)
  _call_blocks_parent_first(node, :before, context)
end
get_fixture_values(names, node, spec, context) click to toggle source
# File lib/oktest.rb, line 1588
def get_fixture_values(names, node, spec, context)
  return THE_FIXTURE_MANAGER.get_fixture_values(names, node, spec, context)
end