• Stars
    star
    181
  • Rank 204,606 (Top 5 %)
  • Language
    Ruby
  • License
    Other
  • Created over 13 years ago
  • Updated about 7 years ago

Reviews

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

Repository Details

💞 Tests your Ruby code, in parallel, as you change it
_______      _______
 ___  /___________ /__
  _  __/ __ \  __/ /_/
  / /_/ /_/ / / / ,\
  \__/\____/_/ /_/|_\
             >>>------>

Test with fork

Tork runs your tests as they change, in parallel:

  1. Absorbs test execution overhead into a master process.

  2. Forks to inherit overhead and run test files in parallel.

  3. Avoids running unchanged tests inside changed test files.

Features

  • No configuration necessary: simply run tork to start testing now!

  • Runs test files in parallel using fork for multi-core/CPU utilization.

  • Tests changes your Ruby application for rapid TDD: avoids running (1) unchanged test files and (2) unchanged tests inside changed test files.

  • Supports MiniTest, Test::Unit, RSpec, and any testing framework that (1) exits with a nonzero status to indicate test failures and (2) is loaded by your application's test/test_helper.rb or spec/spec_helper.rb file.

  • Logs the output from your tests into separate files: one log per test.

  • Configurable through Ruby scripts in your current working directory.

  • You can override the modular tork* programs with your own in $PATH.

  • You can remotely control other tork* programs using tork-remote(1).

Architecture

Following UNIX philosophy, Tork is composed of simple text-based programs that do one thing well. As a result, you can even create your own user interface for Tork by wrapping the tork-driver(1) program appropriately!

  • tork(1) is an interactive command-line user interface for tork-driver(1)
  • tork-runner(1) runs your test suite once, non-interactively, and then exits
  • tork-herald(1) monitors current directory tree and reports changed files
  • tork-driver(1) drives the engine according to the herald's observations
  • tork-engine(1) tells master to run tests and keeps track of test results
  • tork-master(1) absorbs test execution overhead and forks to run your tests
  • tork-remote(1) remotely controls any Tork program running in the same pwd
  • tork-notify(1) notifies you when previously passing tests fail or vice versa

When the herald observes that files in or beneath the current directory have been written to, it tells the driver, which then commands the master to fork a worker process to run the tests affected by those changed files. This is all performed automatically. However, to run a test file manually, you can:

  1. Simply save the file! When you do, Tork tries to figure out which tests inside your newly saved test file have changed (using diff and regexps) and then attempts to run just those. To make it run all tests in your saved file, simply save the file again without changing it.

  2. Type t followed by a space and the file you want to run into tork(1):

    # run all of test/some_test.rb
    t test/some_test.rb
    
    # run lines 4, 33, and 21 of test/some_test.rb
    t test/some_test.rb 4 33 21
    
  3. Send a ["run_test_file"] message to tork-engine(1) using tork-remote(1):

    # run all of test/some_test.rb
    echo run_test_file test/some_test.rb | tork-remote tork-engine
    
    # run lines 4, 33, and 21 of test/some_test.rb
    echo run_test_file test/some_test.rb 4 33 21 | tork-remote tork-engine
    

Alternatively, you can use tork-runner(1) to run your test suite in one shot and then exit with a nonzero status if tests failed, similar to rake test.

Installation

gem install tork

Prerequisites

  • Ruby 1.8.7 or 1.9.3 or newer.

  • Operating system that supports POSIX signals and the fork() system call. To check if your system qualifies, launch irb(1) and enter the following:

    Process.respond_to? :fork  # must be true
    Signal.list.key? 'TERM'    # must be true
    Signal.list.key? 'KILL'    # must be true
    
  • To make the tork-herald(1) program's filesystem monitoring more efficient:

    gem install rb-inotify  # linux
    gem install rb-fsevent  # macosx
    

Development

git clone git://github.com/sunaku/tork
cd tork
bundle install
bundle exec tork --help  # run it directly
bundle exec rake --tasks # packaging tasks

Usage

At the command line

tork --help

You can add line editing, history, and filename completion:

rlwrap -c tork

You can control tork(1) interactively from another terminal:

tork-remote tork-engine
# type your commands here, one per line.
# press Control-D to exit tork-remote(1)

You can also do the same non-interactively using a pipeline:

# run lines 4, 33, and 21 of test/some_test.rb
echo run_test_file test/some_test.rb 4 33 21 | tork-remote tork-engine

You can monitor your test processes from another terminal:

watch 'pgrep -f ^tork | xargs -r ps uf'

With Bundler

The bundler configuration helper loads a Bundler bundle into tork-master(1). The default configuration helper does this for you automatically if there is a Gemfile or Gemfile.lock file present in your current working directory.

As a result, you don't need to add Tork to your Gemfile just to run tests! Instead, installing Tork as a Ruby gem outside of your bundle is sufficient.

Try it: go into any bundled application and call tork to run its test suite.

With MiniTest

MiniTest 1.3.2 and newer contain a bug where minitest/autorun won't run any tests if someone calls Kernel#exit explicitly or simply loads a library (such as RSpec) which makes the call implicitly. Use Tork 19.0.2+ to avoid this problem or apply this patch to the minitest library to fix the problem.

With RSpec

RSpec 2.9.0 and newer contain a bug where RSpec's autorun helper won't run any specs if someone calls Kernel#exit explicitly or simply loads a library (such as Test::Unit) which makes the call implicitly. Use Tork 19.0.2+ to avoid this problem or apply this patch to the rspec-core library to fix the problem.

RSpec 2.8.0 and older contain a bug where a nonzero exit status (caused by an uncaught exception) is overridden by RSpec's Kernel#at_exit handler to be zero, thereby falsely indicating that a spec had passed. This patch fixes the problem.

With Ruby on Rails

For Rails 3 or newer, use the rails configuration helper before the test or spec helpers. Otherwise your test helper will load Rails before the specified rails configuration helper has a chance to disable class caching!

For older Rails, make sure your config/environments/test.rb file contains:

config.cache_classes = false

For older Rails, to use SQLite3 as your test database, install the in-memory database adapter. Otherwise, you might face these errors:

SQLite3::BusyException: database is locked

cannot start a transaction within a transaction

For older Rails, to use SQLite3 as your test database along with browser-based acceptance testing frameworks such as Capybara, see http://www.spacevatican.org/2012/8/18/threading-the-rat/

Configuration

Tork looks for a configuration directory named .tork/ inside its working directory. The configuration directory contains specially-named Ruby scripts, within which you can query and modify the settings for various tork programs. See the "FILES" sections in the manual pages of tork programs for details.

Note that tork does not automatically reload changes from your configuration directory. Consequently, you must restart tork if your configuration changes.

License

Like my work? 👍 Please spare a life today as thanks! 🐮🐷🐔🐟🙊✌️💞

Copyright 2010 Suraj N. Kurapati https://github.com/sunaku

Released under the ISC license. See the LICENSE file for details.

More Repositories

1

tamzen-font

💌 Bitmapped programming font, based on Tamsyn
Ruby
818
star
2

dasht

💁 Search API docs offline, in terminal or browser
Shell
803
star
3

md2man

📚 Converts markdown into UNIX manual pages
Ruby
362
star
4

vim-shortcut

💇 Discoverable & searchable shortcuts for (Neo)Vim
Vim Script
185
star
5

vim-dasht

💁 (Neo)Vim plugin for dasht integration
Vim Script
131
star
6

home

🏡 My $HOME directory (dot files & bin scripts)
Shell
128
star
7

.vim

✌️ A modular (Neo)Vim configuration
Vim Script
112
star
8

vim-ruby-minitest

Vim highlighting & completion for MiniTest
Vim Script
107
star
9

glove80-keymaps

Glove80 keymap: "Glorious Engrammer"
HTML
100
star
10

vim-unbundle

🎁 Fast, filetype-lazy loader of Vim scripts & plugins
Vim Script
97
star
11

wmiirc

Ruby configuration for WMII window manager
Ruby
81
star
12

tmux-navigate

🥂 Seamless tmux/vim navigation (over SSH too!)
Shell
50
star
13

engrammer

Arno's Engram layout for programmers
Makefile
42
star
14

vim-hicterm

🌈 Highlights terminal color code numbers (0-255)
Vim Script
41
star
15

vim-modusline

🌈 Mode-specific statusline colors
Vim Script
39
star
16

binman

🤓 Creates manual pages from header comments
Ruby
36
star
17

wmii

My fork of the WMII window manager.
C
36
star
18

readably

📚 Static blogs: YAML + Slim → HTML5
Ruby
30
star
19

simple-ftp

My final project for CMPE-150 at UCSC during Spring 2004.
C
27
star
20

rumai

Ruby interface to 9P2000 protocol and WMII window manager
Ruby
21
star
21

bdf2fon

Convert X11 BDF fonts to Microsoft .FNT and .FON formats
C
15
star
22

ruby-vpi

Ruby interface to IEEE 1364-2005 Verilog VPI
Ruby
15
star
23

sunaku.github.io

🌟 My own little corner of the Web
HTML
10
star
24

.dwm

My dwm configuration with Ruby statusbar.
C
10
star
25

inochi

Infrastructure for Ruby projects
Ruby
10
star
26

ruby-coroutine-example

How to embed Ruby inside C coroutines.
C
9
star
27

ember

eRuby template processor
Ruby
8
star
28

sm4tik-font

BDF font of sm4tik's 8x8 XBM icons.
7
star
29

erbook

Write books, manuals, and documents in eRuby.
JavaScript
7
star
30

beakl15p

BEAKL-15p keyboard layout
7
star
31

kwalify

YAML schema validation for Ruby
7
star
32

swig-ruby-ffi

Ruby FFI language module for SWIG
C++
7
star
33

structy_record

🎩 Provides a Struct-like interface for Records
Elixir
6
star
34

detest

Assertion testing library for Ruby
Ruby
5
star
35

rassmalog

Static blogging with YAML and eRuby
Ruby
5
star
36

libixp

Mirror of 9P2000 library from WMII window manager.
C
5
star
37

babelfish

Ruby interface to Yahoo! BabelFish translation service.
Ruby
4
star
38

ofc2_to_png

Open Flash Chart 2 JSON to PNG converter
JavaScript
4
star
39

knights-tour

Knight's Tour algorithm in C, OpenGL, and Cg. This was my final project for CMPE-220 at UCSC during Winter 2007.
C
3
star
40

.dmenu

My dmenu configuration.
C
3
star
41

programming-elixir-issues

Sample project from the Programming Elixir book
Elixir
2
star
42

vim-ruby-shoulda-context

Vim highlighting & completion for shoulda-context.
Vim Script
2
star
43

firefox-tranquility

My fork of the Tranquility addon for Firefox
JavaScript
1
star
44

test-loop

MOVED TO sunaku/testr
1
star
45

kernel_hash

Adds a Kernel#Hash() method like Kernel#Array()
Ruby
1
star
46

redcarpet-manpage

renamed to md2man
1
star
47

test-unit-must

Selfish "must" assertions for Test::Unit
Ruby
1
star
48

ff-bash

For each File (GNU BASH)
Shell
1
star
49

opener

👐 A 33-line alternative to Ruby's launchy gem
Ruby
1
star
50

testr

MOVED TO sunaku/tork
1
star
51

onig-5.9.2

My patches to Oniguruma 5.9.2
C
1
star
52

test-unit-must.vim

Vim syntax highlighting for test-unit-must assertions
Vim Script
1
star
53

equal_rights_for_hash

Adds Kernel#Hash() and generic #to_h() methods.
Ruby
1
star