Class: Peruby::TestBuilder
- Inherits:
-
Object
- Object
- Peruby::TestBuilder
- 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
- #done_testing ⇒ Object
-
#initialize(output) ⇒ TestBuilder
constructor
A new instance of TestBuilder.
- #ok(success, name = '') ⇒ Object
- #plan(count) ⇒ Object
- #subtest(name) ⇒ Object
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_testing ⇒ Object
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 |