Class: Peruby::TestBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/peruby/runtime/test_builder.rb

Overview

Minimal TAP producer shared by Test::More and Test::Simple.

Defined Under Namespace

Classes: Context

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ TestBuilder

Returns a new instance of TestBuilder.



8
9
10
11
# File 'lib/peruby/runtime/test_builder.rb', line 8

def initialize(output)
  @output = output
  @contexts = [Context.new(0, nil, '')]
end

Instance Method Details

#done_testingObject



26
27
28
29
# File 'lib/peruby/runtime/test_builder.rb', line 26

def done_testing
  @output.puts "#{current.indent}1..#{current.tests_run}" unless current.planned
  1
end

#ok(success, name = '') ⇒ Object



19
20
21
22
23
24
# File 'lib/peruby/runtime/test_builder.rb', line 19

def ok(success, name = '')
  current.tests_run += 1
  label = name.to_s.empty? ? '' : " - #{name}"
  @output.puts "#{current.indent}#{success ? 'ok' : 'not ok'} #{current.tests_run}#{label}"
  success ? 1 : ''
end

#plan(count) ⇒ Object



13
14
15
16
17
# File 'lib/peruby/runtime/test_builder.rb', line 13

def plan(count)
  current.planned = count.to_i
  @output.puts "#{current.indent}1..#{current.planned}"
  1
end

#subtest(name) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/peruby/runtime/test_builder.rb', line 31

def subtest(name)
  @output.puts "#{current.indent}# Subtest: #{name}"
  @contexts << Context.new(0, nil, "#{current.indent}    ")
  yield
  done_testing
  @contexts.pop
  ok(true, name)
rescue StandardError
  @contexts.pop if @contexts.length > 1
  ok(false, name)
end