Created
May 6, 2010 23:26
-
-
Save gisborne/392815 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(Thanks to Adam Grant) | |
Used with Autowatchr helper gem, Watchr adds testing functionality to your project | |
ala Zentest/autotest without the cruft and (sometimes) confusing callback hooks | |
that can lead someone to stop testing and turn to drinking massive amounts of Tab Cola. | |
The script contains a set of simple rules that map observed files to an action. | |
Its DSL is a single method: | |
watch(pattern, &action) | |
The Basic Idea: | |
watch( 'a regexp pattern matching paths to observe' ) {|match_data_object| command_to_run } | |
For example: | |
watch( 'test/test_.*\.rb' ) {|files| system("ruby #{files[0]}") } | |
will match any test file and run it whenever it is saved! | |
Demo files: | |
test/test.watchr: | |
================================================================================ | |
require 'watchr' | |
require 'autowatchr' | |
Autowatchr.new(self) do |config| | |
config.run_suite = true | |
config.test_dir = 'test' | |
config.require = %w(test_helper) | |
config.test_re = '^%s.*/.*_test\.rb$' % config.test_dir | |
end | |
================================================================================ | |
Rakefile: | |
================================================================================ | |
require(File.join(File.dirname(__FILE__), 'config', 'boot')) | |
require 'rake' | |
require 'rake/testtask' | |
require 'rake/rdoctask' | |
require 'tasks/rails' | |
desc "Starts running the test environment ala Zentest/autotest style!" | |
task :autotest do | |
sh "watchr #{File.join(File.dirname(__FILE__), 'test', 'test.watchr')}" | |
end | |
================================================================================ | |
To use, run this in your terminal from the RAILS_ROOT directory: | |
rake autotest | |
And you're done! | |
Homepage: | |
http://github.com/mynyml/watchr | |
Installation: | |
gem install watchr | |
gem install rev (If on *nix system this is a big help!) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment