Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/delano/tryouts
Ruby tests that read like documentation.
https://github.com/delano/tryouts
Last synced: 4 days ago
JSON representation
Ruby tests that read like documentation.
- Host: GitHub
- URL: https://github.com/delano/tryouts
- Owner: delano
- License: mit
- Created: 2009-05-19T10:15:50.000Z (over 15 years ago)
- Default Branch: main
- Last Pushed: 2024-11-14T00:25:19.000Z (about 2 months ago)
- Last Synced: 2024-12-24T16:08:49.640Z (12 days ago)
- Language: Ruby
- Homepage: https://delano.github.com/tryouts
- Size: 408 KB
- Stars: 19
- Watchers: 6
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Tryouts v2.4 (2024-07-20)
**Ruby tests that read like documentation.**
A simple test framework for Ruby code that uses introspection to allow defining checks in comments.
## Installation
One of:
* In your Gemfile: `gem 'tryouts'`
* As a gem: `gem install tryouts`
* From source:```bash
$ git clone git://github.com/tryouts/tryouts.git
```## Usage
```bash
# Run all tests accessible from the current directory (e.g. ./try, ./tryouts))
$ try# Run a single test file
$ try try/10_utils_try.rb# Command arguments
$ try -h
Usage: try [options]
-V, --version Display the version
-q, --quiet Run in quiet mode
-v, --verbose Run in verbose mode
-f, --fails Show only failing tryouts
-D, --debug Run in debug mode
-h, --help Display this help
```### Exit codes
When all tests pass, try exits with a 0. An exit code of 1 or more indicates the number of failing tests.
## Writing tests
```ruby
## 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 as well.
81
#=> 9 * 9## Here's an example of testing errors
begin
raise RuntimeError
rescue RuntimeError
:success
end
#=> :success
```For real world examples, see [Onetimesecret](https://github.com/onetimesecret/onetimesecret/) tryouts.
### Test setup / cleanup
Put the setup code at the top of the file, and cleanup code at the bottom. Like this:
```ruby
# This is called before all tests
require 'gibbler'
Gibbler.digest_type = Digest::SHA256## This is a single testcase
:anything.gibbler
#=> '8574309'# This will be called after all tests
Gibbler.digest_type = Digest::SHA1
```__
## Thanks
* [cloudhead](https://github.com/cloudhead)
* [mynyml](https://github.com/mynyml)
* [Syntenic](https://syntenic.com/) for the hackfest venue.
* [AlexPeuchert](https://www.rubypulse.com/) for the screencast.
* Christian Michon for suggesting a better default output format.*This collision was brought to you by Montreal.rb.*