[Rubygems-developers] test_cmd_manager.rb started...

Richard Kilmer rich at infoether.com
Fri Jun 18 00:39:46 EDT 2004


All,

I started writing tests against the new cmd_manager stuff.  This was to both
write tests, and exercise the new UserInteraction stuff.  Here is one cool
example:

  def test_parsing_install_options

    #capture all install options
    check_options = nil
    @cmd_manager['install'].when_invoked do |options|
      check_options = options
      true
    end

So (above) I capture the command options after they are parsed but before
they are passed into the process_install_command.

    <lots of options tests snipped>

Here I want to check on an error message (based on a bad option):

    #check bad argument
    error = nil
    @ui.on_alert_error do |message, question|
      error = message
    end
    @cmd_manager.process_args("install --bad-arg")
    assert_match /invalid option: --bad-arg/, error
  end

Here I capture the user interaction and get a handle to the command manager
singleton.

  def setup
    @ui = Gem::UserInteraction.capture
    @cmd_manager = Gem::CommandManager.instance
  end

Pretty cool, and easy to test!  The current tests are just to check the
options parsed by the install command, and I'll add the other commands
tomorrow.  Then on to testing the process_<command>_command methods to
ensure that install/uninstall/query/update/etc function correctly.

-rich




More information about the Rubygems-developers mailing list