1. What's CmdUnit
CmdUnit is Ruby API for testing shell command, and is idealy suited for automated unit testing of web sites when combined with a Ruby unit test framework such as RubyUnit. It was designed and implemented by Masaki Suketa.
2. Download and Install
Download cmdunit-20YYMMDD-*.tar.gz from http://xpenguin.biz/download/cmdunit/, and, extract it to some directory, then, do ``ruby install.rb''.
3. Example
3.1. Source
require 'cmdunit/cmdunit'
class TestSample < CmdUnit::TestCase
def setup
ENV['LANG'] = 'C'
end
def test_echo
result = Command::new( "echo a" ).exec
assert_status( 0, result )
assert_output( "a\n", "", result )
end
def test_ls
command = Command::new( "ls %s" )
command.exec( 'dummy' )
assert_status( 1, command )
assert_output( "", "ls: dummy: No such file or directory\n", command )
command.exec( '-d /' )
assert_status( 0, command )
assert_output( "/\n", "", command )
end
end
3.2. Result
TestSample#test_echo . TestSample#test_ls . Time: 0.074055 OK (2/2 tests 6 asserts)
4. Copying
This Program is copyrighted free software by yuichi TAKAHASHI.
You can redistribute it and/or modify it under either the terms of the GPL (see COPYING file), or same as Ruby.
5. Bug Report
6. Changes
20010606-alpha -> now
- Command#stdin : add input for a command
- assert_output : new
- assert_status : new
- assert.rb : add
- TestCase#teardown : call restore_original_env
- Command#exec : add argument for a command
- test_cmdunit.rb : use File::expand_path for __FILE__