module TestUnitHelper::InstanceMethods

Container for methods that are added to Test::Unit::TestCase as instance methods.

Public Class Methods

new(*args) click to toggle source

Override initialize to add a few things.

Calls superclass method
# File lib/test_unit_helper/instance_methods.rb, line 39
def initialize(*args)
  super

  reset_io

  unless self.class.test_class.nil?
    @class = Kernel.const_get(self.class.test_class)
  end
end

Private Instance Methods

err() click to toggle source

The output from stderr while wrap_output was in effect.

Output

String

The output from stderr.

# File lib/test_unit_helper/instance_methods.rb, line 81
def err
  @err.respond_to?(:string) ? @err.string.sub(/\n*\z/, '') : ''
end
out() click to toggle source

The output from stdout while wrap_output was in effect.

Output

String

The output from stdout.

# File lib/test_unit_helper/instance_methods.rb, line 74
def out
  @out.respond_to?(:string) ? @out.string.sub(/\n*\z/, '') : ''
end
real_finis() click to toggle source

The combination of out and err in one function.

Output

Array

Two element array of strings.

The first element is from stdout.

The second element is from stderr.

# File lib/test_unit_helper/instance_methods.rb, line 98
def real_finis
  return out, err
end
reset_io() click to toggle source

Reset the stdout and stderr stream variables.

# File lib/test_unit_helper/instance_methods.rb, line 86
def reset_io
  @out = StringIO.new
  @err = StringIO.new
end
wrap_output() { || ... } click to toggle source

Wrap a block to capture the output on stdout and stderr.

Input

Block

A block that will have stdout and stderr trapped while it runs.

# File lib/test_unit_helper/instance_methods.rb, line 60
def wrap_output
  begin
    $stdout = @out
    $stderr = @err
    yield
  ensure
    $stdout = STDOUT
    $stderr = STDERR
  end
end