Tap Test

test v. to reveal the strengths or capabilities of something

Test modules for Tap.

Description

Provides test modules to simplify testing of common Tap tasks, especially tasks that require interaction with files. Modules are also provided to test the shell behavior of executables and to define conditions for tests (ex *nix/windows only). Tap-Test is not a testing framework. By default Tap-Test integrates with Test::Unit and Mini::Test, but it is possible to include the test modules into other test frameworks.

Usage

The Tap-Test modules are small and targeted. More complete examples can be found in the documentation, these are intended to show the point of each module. To enable a module in Test::Unit or Mini::Test, require ‘tap/test/unit’ and simply call the acts_as_x_test method. Multiple modules can be overlaid.

FileTest (acts_as_file_test)

Sets up a test-specific method_root for working with temporary files. Better in most cases than using Tempfile because you can flag temporary files to be saved on a failure (using ENV=‘true’).

require 'tap/test/unit'
class FileTestTest < Test::Unit::TestCase
  acts_as_file_test

  def test_method_root
    assert_equal "test_method_root", File.basename(method_root.path)

    path = method_root.prepare('tmp/file.txt') {|io| io << 'content' }
    assert_equal "content", File.read(path)
  end
end

ShellTest (acts_as_shell_test)

Simple testing of shell commands.

require 'tap/test/unit'
class ShellTestTest < Test::Unit::TestCase
  acts_as_shell_test :cmd_pattern => '% alias', :cmd => 'echo'

  def test_echo
    assert_equal "goodnight moon", sh("echo goodnight moon").strip
  end

  def test_echo_with_an_alias
    sh_test %q{
    % alias goodnight moon
    goodnight moon
    }
  end
end

SubsetTest (acts_as_subset_test)

Allows in-file subsetting of tests into groups. Easy to get carried away with this one, but handy, especially for platform-specific tests. Turn on a subset or all tests using an ENV variable (ex ENV=‘true’).

require 'tap/test/unit'
class SubsetTestTest < Test::Unit::TestCase
  acts_as_subset_test

  condition(:windows) { match_platform?('mswin') }

  def test_something_for_windows_only
    condition_test(:windows) do
      # ...
    end
  end

  def test_something_that_takes_forever
    extended_test do
      # ...
    end
  end
end

TapTest (acts_as_tap_test)

Sets up Tap::App.current for testing tasks.

require 'tap/test/unit'
class TapTestTest < Test::Unit::TestCase
  acts_as_tap_test

  def test_info
    assert_equal 'state: 0 (READY) queue: 0', app.info
  end
end

Installation

Tap-Test is available as a gem on Gemcutter.

% gem install tap-test

Info

Developer

Simon Chiang

License

MIT-Style