• Stars
    star
    237
  • Rank 169,885 (Top 4 %)
  • Language
    Ruby
  • License
    Other
  • Created over 13 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Super simple Ruby testing library
 _            _                  _         _
| |_  ___ ___| |_ _ __ ___   ___| | __ ___| |_
| __|/ _ | __| __| '__/ _ \ / __| |/ // _ \ __|
| |_|  __|__ \ |_| | | (_) | (__|   <|  __/ |_
 \__|\___|___/\__|_|  \___/ \___|_|\_\\___|\__|

Testrocket is a super simple (as simple as it gets really) testing library for Ruby 2.0 and higher.

It was initially developed for a CodeBrawl contest and it won! People asked me to release it 'for real' so here we are.

To install:

gem install testrocket

.. or add it to your Gemfile in the usual way.

As yet there are no useful bits and pieces for creating test files (look at the example, it's easy!) or Rake tasks. But it's all crazy simple. A few things may be added later on.

Note: Prior to version 1, TestRocket extended built-in classes to work, but has (in 2019) been modernized to use refinements to avoid it clashing with third party libraries in real world scenarios (yes, people use this library in real world code!)

Dependencies

  • Ruby 2.1 or higher
  • minitest/spec (part of MRI 1.9+ standard library)

Example

require 'testrocket'
using TestRocket

# BASIC USAGE
# +-> { block that should succeed }
# --> { block that should fail }

+-> { Die.new(2) }
--> { raise }
+-> { 2 + 2 == 4 }

# These two tests will deliberately fail
+-> { raise }
--> { true }

# A 'pending' test
~-> { "this is a pending test" }

# A description
!-> { "use this for descriptive output and to separate your test parts" }

As well as running tests in separate test files in the 'traditional' way, TestRocket can also be used 'inline' with real world code. A trivial example:

class YourClass
  using TestRocket

  def initialize
  end

  def does_something
    # ...
  end

  +->{  # a test for does_something goes here }

  def does_something_else
    # ...
  end

  +->{  # a test for does_something_else goes here }
  -->{  # a test for does_something_else goes here }
end

In this way, your class is tested each time you run the app in development or test modes. Note that if TestRocket detects RACK_ENV is production, RAILS_ENV is production or Rails is running and Rails.env.production? is true, the usual TestRocket methods will simply pass straight through so as to not impede performance on the loading of your app.

Other Features

By default, output is written to STDERR (as well as returned by the test expressions themselves). You can override where test output goes like so:

TestRocket.out = File.new('/dev/null', 'w')

TestRocket.out also supports Logger instances.

Credits

Initial concept and maintenance by Peter Cooper

Extra concepts and code by Christoph Grabo

Thanks to Gary Bernhardt for often praising and shining attention on TestRocket :-)

Thanks to Serge Bedzhyk for modernizing the library to use refinements.

More Repositories

1

pismo

Extracts machine-readable metadata and content from Web pages
Ruby
747
star
2

whatlanguage

A language detection library for Ruby that uses bloom filters for speed.
Ruby
685
star
3

engblogs

Engineering Blogs
Ruby
119
star
4

bitarray

Pure Ruby bit array/bitfield implementation
Ruby
105
star
5

hackerslide

A sliding view of the Hacker News front page over time
JavaScript
76
star
6

trtl

Tk-powered Ruby turtle graphics
Ruby
65
star
7

chrome2gif

Dynamically create an animated GIF of a page running in Chrome
JavaScript
63
star
8

rsmaz

Ruby port of Smaz - a short string compression library
Ruby
44
star
9

multirb

Run Ruby code over multiple implementations/versions using RVM from a IRB-esque prompt
Ruby
43
star
10

potc-jruby

JRuby port of Prelude of the Chambered, a Java game
Ruby
41
star
11

videocr

Perform OCR upon entire videos to look for credentials or similar.
Python
39
star
12

webloc

Read and write .webloc (web link) files on macOS / OS X
Ruby
24
star
13

switchpipe

SwitchPipe is a backend process manager and HTTP proxy that makes (especially Ruby) web app deployment simple. NOW OBSOLETE. DO NOT USE.
Ruby
14
star
14

webassembly-simplest-demo

A simple example of compiling C to WebAssembly and running it
HTML
13
star
15

simredis

Redis simulator that allows you to use redis-rb without a Redis daemon running
Ruby
10
star
16

monos

My Ludum Dare 22 entry
Ruby
8
star
17

coffeebots

A programmable robot war game in CoffeeScript / JavaScript
CoffeeScript
4
star
18

illustrator-cc-scripting

Help and resources on scripting Illustrator CC on macOS
JavaScript
4
star
19

igsubscriber

Streams live market data from IG.com's Lightstreamer into a Redis data store
JavaScript
4
star
20

massiveattract

A game developed in a few hours for Ludum Dare 23
JavaScript
2
star
21

bits

Random bits of code I want to keep track of
Ruby
1
star
22

hntitles

Hacker News title edit tracker
Ruby
1
star
23

cardnut

Simple backend for pushing Twilio text messages over WebSocket to a client (not useful for many)
JavaScript
1
star
24

toto

MIDI proxying for great fun with keyboards
Ruby
1
star
25

superhighway

superhighway.dev
HTML
1
star
26

ruranopupore

An Ubuntu 12.04 LTS Ruby, Rails, Nginx, Node.js, Puma, Postgres, and Redis Ansible Playbook Collection
1
star
27

aoc2019solutions

My Advent of Code 2019 Solutions
Ruby
1
star
28

herokuexperiment

Running two processes (web and worker) on a single Heroku dyno
Ruby
1
star