Welcome to TestUnitHelper

TestUnitHelper provides additional functionality to Test::Unit.

Getting Started

Install TestUnitHelper at the command prompt if you haven't yet:

$ gem install test_unit_helper

Require the gem in your Gemfile:

gem 'test_unit_helper', '~> 0.0.2'

Require the gem wherever you need to use it:

require 'test_unit_helper'

Usage

This gem adds a number of things to TestCase. The first one is an addition to the class methods. A function named 'test' exists so that you may use the following inside your tests:

test 'this should pass' do
  assert true
end

If you have a class named MyClass and your test class is named either TestMyClass or MyClassTest, an instance variable (@class) will be made available, which allows for things like:

def setup
  @my_object = @class.new
end

If your test is named after a class as above, the following tests illustrate other enhancements:

test '.some_method does something' do
  assert false # => test MyClass.some_method does something (MyClassTest)
end

test '#some_method does something' do
  assert false # => test MyClass#some_method does something (MyClassTest)
end

The wrap_output instance method has been added. It traps all output to standard out and standard error in a way that prevents them from spitting out all through your tests, but also allows you to check what the results:

test 'output should be trapped' do
  wrap_output { puts 'TestUnitHelper is awesome!' }
  assert_equal 'TestUnitHelper is awesome!', out
end

A reset_io method is available to reset out and err, if wrap_output will be called multiple times and you need to clear them in between (they are automatically reset before each test).

Additional Notes

out and err strip all trailing new lines. If it is absolutely necessary to compare with the newlines, @out and @err are available. They are StringIO objects, though. But the key here is that the only ways they are modified are when something is added to them (via wrap_output) or when they are reset.

Additional Documentation

$ rake rdoc:app

Updates

  • 0.0.2 - 2012 Jun 17
    • Updated to a version of rake_tasks that won't break ci.
    • Made Class.test_class more intelligent. It now checks for multiple constant name possibilities.
    • Added test/rubies.yml to facilitate testing multiple Ruby versions vi rake_tasks's rake test:full.
  • 0.0.1 - 2012 Mar 04
    • Initial release.

License

TestUnitHelper is released under the LGPLv3 license.