Socket
Book a DemoInstallSign in
Socket

command-unit

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

command-unit

0.0.3
bundlerRubygems
Version published
Maintainers
1
Created
Source

Command Unit

Lightweight test runner, primarily written to support development of Righteous Git Hooks.

Written in Ruby, designed to test command line apps, whether they're written in Ruby, Shell, Bash, C#, Java, whatever ;)

Design goals:

  • As few dependencies as possible
  • Should be self-testing
  • Suitable for testing command line tools

Tests are written in Command Unit itself, so no need for any external dependencies yet. I might make this a fundamental requirement of future development, but I'll see how far the project can go on basic Ruby first.

This is alpha software

So far I've only tested this on Ruby 1.9.3, others may work but I'm not considering support on any other platforms until I've got a stable/useful release out. The code itself is very rough-and ready, and could benefit from quite a lot of refactoring, especially in scenario.rb.

Features

  • No dependencies apart from Ruby itself
  • Assertion helpers (these need work)
  • Clear, readable, colour console output
  • All command-unit tests written using command-unit itself
  • Expectations require a description, making test more useful as documentation
  • Hooks, you can inject your own code easily to respond to tests running/passing/failing.

Minimalist usage example

require 'command-unit'
include CommandUnit
scenario 'Writing tests in Command Unit' do
   
   when_i 'do something wacky' do |context|
   	context[:data] = 'call a method or something here'
   end

   i_expect "to receive a string containing 'or' do |context|
   	expect context[:data], &contains('or')
   end

   i_expect "the string to exactly equal 'or'" do |context|
   	expect context[:data], &is_equal_to('or')
   end

end

run

Output:

Running 1 scenarios...

Running scenario 1: Writing tests in Command Unit
	When I do something wacky
		I expect to receive a string containing 'or'...Success! 
		I expect the string to exactly equal 'or'...Failure!
Expecting exactly 'or', but got 'call a method or something here'
Scenario 1 finished, 1 tests, 2 expectations with 1 successful and 1 failures.

Ran 1 scenarios, 0 passed, 1 failed (tests passed: 0, failed: 1) (expectations passed: 1, failed: 1)

Installation

gem install command-unit

Development

Unpack the gem with gem unpack command-unit Run tests:

    $ cd command-unit-0.0.3
    $ ruby test/test.rb

More?

This is fairly experimental, and I know a lot of people probably won't like it, or will think it needless (why not just use rspec?!), but it satisfies a need I have right now, and I'm happy so far.

I'd really love to hear any constructive criticism on both the code and the conventions in test-writing that command-unit enforces, you can email me at samsalisbury@gmail.com

FAQs

Package last updated on 18 Aug 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.