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.



1205
1206
1207
# File 'lib/oktest.rb', line 1205

def initialize(reporter)
  @reporter = reporter
end

Instance Method Details

#startObject



1209
1210
1211
1212
1213
1214
1215
1216
# File 'lib/oktest.rb', line 1209

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



1218
1219
1220
1221
1222
1223
1224
1225
# File 'lib/oktest.rb', line 1218

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)
  scope.each_child {|c| c.accept_visitor(self, depth+1, scope) }
  call_after_all_block(scope)
  @reporter.exit_scope(scope) unless scope.equal?(THE_GLOBAL_SCOPE)
end

#visit_spec(spec, depth, parent) ⇒ Object



1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
# File 'lib/oktest.rb', line 1236

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



1227
1228
1229
1230
1231
1232
1233
1234
# File 'lib/oktest.rb', line 1227

def visit_topic(topic, depth, parent)
  @reporter.enter_topic(topic, depth)
  #; [!i3yfv] calls 'before_all' and 'after_all' blocks.
  call_before_all_block(topic)
  topic.each_child {|c| c.accept_visitor(self, depth+1, topic) }
  call_after_all_block(topic)
  @reporter.exit_topic(topic, depth)
end