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.



1535
1536
1537
# File 'lib/oktest.rb', line 1535

def initialize(reporter)
  @reporter = reporter
end

Instance Method Details

#startObject



1539
1540
1541
1542
1543
1544
1545
1546
# File 'lib/oktest.rb', line 1539

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



1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
# File 'lib/oktest.rb', line 1556

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



1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
# File 'lib/oktest.rb', line 1586

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



1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
# File 'lib/oktest.rb', line 1571

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