Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Don't waste time writing tests.

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 bin
Octocat-spinner-32 lib
Octocat-spinner-32 try
Octocat-spinner-32 .gitignore
Octocat-spinner-32 CHANGES.txt
Octocat-spinner-32 LICENSE.txt
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 VERSION.yml
Octocat-spinner-32 tryouts.gemspec
README.rdoc

Tryouts v2.0 ALPHA

Don't waste your time writing tests.

NOTE: Tryouts syntax changed since 0.x. The old version is still available in the 0.8-FINAL branch.

Check out the screencast created by Alex Peuchert.

Basic syntax

## A very simple test
  1 + 1
#=> 2

## The test description can spread
## across multiple lines. The same
## is true for test definitions.
  a = 'foo' 
  b = 'bar'
  a + b
#=> 'foobar'

## A test will pass when its return
## value equals the expectation. 
  'foo'.class
#=> String

## The expectations are evaluated.
  1 + 1
#=> 1 + 1

## Here's an example of testing errors
  begin
    raise RuntimeError
  rescue RuntimeError
    :success
  end
#=> :success

For real world examples, see the Gibbler tryouts.

Setup / Cleanup

All code before the first test definition is assumed to be setup code. All code after the last definition is assumed to be cleanup code. Here is an example:

# This is called before all tests
require 'gibbler'
Gibbler.digest_type = Digest::SHA256

## A Symbol can gibbler
  :anything.gibbler
#=> '754f87ca720ec256633a286d9270d68478850b2abd7b0ae65021cb769ae70c08'

# This will be called after all tests
Gibbler.digest_type = Digest::SHA1

Running Tests

Try ships with a command-line tool called try. When called with no arguments, it will look for files ending with _try.rb in the current directory, or in the subfolder try.

You can also supply a specific file to test.

$ try path/2/test.rb
Ruby 1.9.1 @ 2011-01-06 12:38:29 -0500               

 # TEST 1: test matches result with expectation             
7    a = 1 + 1
8    #=> 2
     ==  2
...

 ## TEST 12: comments, tests, and expectations can 
 ## contain multiple lines 
13   a = 1
14   b = 2
15   a + b
16   # => 3
17   # => 2 + 1
     ==  3
     ==  3

 12 of 12 tests passed (and 5 skipped)

If all tests pass, try exits with a 0. Otherwise it exits with the number of tests that failed.

For reduced output, use the `-q` option:

$ try -q
Ruby 1.9.1 @ 2011-01-06 12:38:29 -0500               

 42 of 42 tests passed (and 5 skipped)
  4 of 4 batches passed

Installation

One of:

$ gem install tryouts

Credits

With help from:

Thanks

  • Syntenic for the hackfest venue.

  • AlexPeuchert for the screencast.

  • Christian Michon for suggesting a better default output format.

This collision was brought to you by Montreal.rb.

Something went wrong with that request. Please try again.