Class: Oktest::Runner

Inherits:
Visitor show all
Defined in:
lib/oktest.rb

Instance Method Summary collapse

Constructor Details

#initialize(reporter) ⇒ Runner

Returns a new instance of Runner.



1620
1621
1622
# File 'lib/oktest.rb', line 1620

def initialize(reporter)
  @reporter = reporter
end

Instance Method Details

#startObject



1624
1625
1626
1627
1628
1629
1630
1631
# File 'lib/oktest.rb', line 1624

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) ⇒ Object



1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
# File 'lib/oktest.rb', line 1641

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) ⇒ Object



1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
# File 'lib/oktest.rb', line 1671

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.location,
                                  spec.fixture ? spec.fixture.dup : {})
    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.to_s])
  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) ⇒ Object



1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
# File 'lib/oktest.rb', line 1656

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