Wednesday, January 16, 2008

Autotest with verbose flag on

I followed a tip from David Chelimsky's blog and began running autotest with the -v flag for verbosity.  When you first run it, you get a bunch of lines like this:
Dunno! spec/other_inbox_spec_helpers.rb
Dunno! app/views/layouts/main/_footer.erb
Which show all the files for which autotest doesn't have a mapping.  With ZenTest 3.8.0 out, it's easy to add mappings (which tell autotest which tests to run when a matching file changes) and exceptions (which tell autotest which files to ignore).  You can also set up .autotest files for particular projects, or for your whole development machine (~/.autotest).

Here's an example of a per-project .autotest I use, sitting in the Rails root directory.  I've got a custom spec helper and I want to rerun all my tests if this file ever changes:
Autotest.add_hook :initialize do |at|
%w{ domain_regexp perfdata coverage reports }.each { |exception| at.add_exception(exception) }

at.add_mapping(/spec\/app_spec_helper.rb/) do |_, m|
at.files_matching %r%^spec/(controllers|helpers|lib|models|views)/.*\.rb$%
end

end
And here's part of my site-wide .autotest file, mostly cribbed from David's blog, where I'm ignoring other kinds of cruft that pile up in projects.  Also note the mapping for spec/defaults.rb, a file I commonly setup in my specs containing default parameters for different models.
Autotest.add_hook :initialize do |at|
%w{.hg .git .svn stories tmtags Rakefile Capfile README spec/spec.opts spec/rcov.opts vendor/gems autotest svn-commit .DS_Store }.each {|exception|at.add_exception(exception)}

at.add_mapping(/spec\/defaults.rb/) do |f, _|
at.files_matching %r%^spec/(controllers|helpers|lib|models|views)/.*\.rb$%
end

end

4 comments:

Andrzej Krzywda said...

Nice article, thanks!

Do you know how to force autotest to run my 'stories/all.rb' file?

Any other way of running all of my RSpec stories whenever I change anything?

andrzejkrzywda.com

Mike Subelsky said...

Something like:

at.add_mapping(/spec\/stories\/all.rb/) do |f, _|
at.files_matching %r%^spec/(controllers|helpers|lib|models|views)/.*\.rb$%
end

should work...

Anonymous said...

"It's a mystery," replied the Lion. "I suppose I was born
that way. All the other animals in the forest naturally expect me
to be brave, for the Lion is everywhere thought to be the King of
Beasts. I learned that if I roared very loudly every living thing
was frightened and got out of my way.

Nike shoes
MBT
supra footwear
famous footwear
shoe dept
nike air max

Unknown said...

ED Hardy Shoes
ED Hardy Dresses
ED Hardy Sunglasses
ED Hardy T-Shirts
ED Hardy Bags
Ed Hardy Caps
ED Hardy Watches
ED Hardy Long Sleeve Shirts