• Stars
    star
    1,278
  • Rank 35,481 (Top 0.8 %)
  • Language
    Ruby
  • License
    MIT License
  • Created almost 15 years ago
  • Updated over 12 years ago

Reviews

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

Repository Details

Modern continuous testing (flexible alternative to Autotest)

Summary

Agile development tool that monitors a directory tree, and triggers a user defined action whenever an observed file is modified. Its most typical use is continuous testing, and as such it is a more flexible alternative to autotest.

Features

watchr is:

  • Simple to use
  • Highly flexible
  • Evented ( Listens for filesystem events with native c libs )
  • Portable ( Linux, *BSD, OSX, Solaris, Windows )
  • Fast ( Immediately reacts to file changes )

Most importantly it allows running tests in an environment that is agnostic to:

  • Web frameworks ( rails, merb, sinatra, camping, invisible, ... )
  • Test frameworks ( test/unit, minitest, rspec, test/spec, expectations, ... )
  • Ruby interpreters ( ruby1.8, ruby1.9, MRI, JRuby, Rubinius, ... )
  • Package frameworks ( rubygems, rip, ... )

Usage

On the command line,

$ watchr path/to/script.file

will monitor files in the current directory tree, and react to events on those files in accordance with the script.

Scripts

The script contains a set of simple rules that map observed files to an action. Its DSL is a single method: watch(pattern, &action)

watch( 'a regexp pattern matching paths to observe' )  {|match_data_object| command_to_run }

So for example,

watch( 'test/test_.*\.rb' )  {|md| system("ruby #{md[0]}") }

will match any test file and run it whenever it is saved.

A continuous testing script for a basic project could be

watch( 'test/test_.*\.rb' )  {|md| system("ruby #{md[0]}") }
watch( 'lib/(.*)\.rb' )      {|md| system("ruby test/test_#{md[1]}.rb") }

which, in addition to running any saved test file as above, will also run a lib file's associated test. This mimics the equivalent autotest behaviour.

It's easy to see why watchr is so flexible, since the whole command is custom. The above actions could just as easily call "jruby", "ruby --rubygems", "ruby -Ilib", "specrb", "rbx", ... or any combination of these. For the sake of comparison, autotest runs with:

$ /usr/bin/ruby1.8 -I.:lib:test -rubygems -e "%w[test/unit test/test_helper.rb test/test_watchr.rb].each { |f| require f }"

locking the environment into ruby1.8, rubygems and test/unit for all tests.

And remember the scripts are pure ruby, so feel free to add methods, Signal#trap calls, etc. Updates to script files are picked up on the fly (no need to restart watchr) so experimenting is painless.

The wiki has more details and examples. You might also want to take a look at watchr's own scripts, specs.watchr, docs.watchr and gem.watchr, to get you started.

Install

gem install watchr

If you're on Linux/BSD and have the rev gem installed, Watchr will detect it and use it automatically. This will make Watchr evented.

gem install rev

You can get the same evented behaviour on OS X by installing ruby-fsevent.

gem install ruby-fsevent

See Also

  • redgreen: Standalone redgreen eye candy for test results, ala autotest.
  • phocus: Run focused tests when running the whole file/suite is unnecessary.
  • autowatchr: Provides some autotest-like behavior for watchr
  • nestor: Continuous testing server for Rails

Links

More Repositories

1

harmony

Javascript + DOM in your ruby, the simple way
Ruby
445
star
2

holygrail

Harmony plugin for Ruby on Rails tests
Ruby
169
star
3

every

Symbol#to_proc's hot cousin. Simple and elegant alternative to using &:method with enumerables.
Ruby
75
star
4

nanotest

When all you need is #assert
Ruby
69
star
5

redgreen

Standalone redgreen eye candy for test results, ala autotest
Ruby
43
star
6

simple_router

Simple rack router
Ruby
28
star
7

unindent

Ruby method to unindent strings.
Ruby
27
star
8

phocus

Focus your tests
Ruby
25
star
9

rack-respond_to

Rack middleware port of Rails's respond_to feature
Ruby
23
star
10

attachment_fu_fixtures

Allows attachment_fu models to fully use fixtures. Ideal for seed, sample or dev data.
Ruby
17
star
11

montrealrb

Montreal.rb website source
Ruby
16
star
12

rack-accept-media-types

Rack convenience middleware for simplified handling of Accept header (Accept header parser).
Ruby
13
star
13

rack-abstract-format

Rack middleware that abstracts format (extension) away from the path (into env)
Ruby
12
star
14

pathname

OO wrapper for node's path/fs modules. Based on Ruby's sweet Pathname class
JavaScript
12
star
15

nanotest_extensions

Nano extensions for nanotest
Ruby
8
star
16

rack-supported-media-types

Rack middleware to specify an app's supported media types.
Ruby
7
star
17

override

Like #alias_method_chain, but awesome
Ruby
6
star
18

simple_example

Add easy fancy-pants examples to your projects
Ruby
3
star
19

swap

Ruby lib that allows dynamically replacing and restoring methods
Ruby
3
star
20

merb-in-file-templates

Define views right in your controller's file
Ruby
2
star
21

merb_simple_views

Merb plugin that allows defining templates (views, css, js)in the same file as the controller.
Ruby
2
star
22

tmptation

Classes that help safely manipulate temporary files and directories
Ruby
1
star
23

ntest

a little node.js test framework i wrote to learn the ropes.
JavaScript
1
star
24

rack-js4xhr

Rack middleware to set application/javascript media type on xhr requests.
Ruby
1
star