CARVIEW |
autotest
Here’s how to use autotest with rspec-2 (as of 2.0.0.beta.4):
Add an autotest
directory to the root of your project, and add a discover.rb
file in that directory with:
#./autotest/discover.rb
Autotest.add_discovery { "rspec2" }
Now you should be able to run autotest
from the project root.
$ autotest
loading autotest/rspec2
style: Rspec2
Advanced autotest configuration
You can add an ./.autotest
file in the root of your project to define hooks used by autotest in your project. This lets you set up exceptions (files to ignore) and mappings (which files to specifically monitor for changes).
# ./.autotest
Autotest.add_hook(:initialize) {|at|
at.add_exception %r{^\.git} # ignore Version Control System
at.add_exception %r{^./tmp} # ignore temp files, lest autotest will run again, and again...
# at.clear_mappings # take out the default (test/test*rb)
at.add_mapping(%r{^lib/.*\.rb$}) {|f, _|
Dir['spec/**/*.rb']
}
nil
}
The project specific autotest file overrides any system wide autotest file, located in ~/.autotest
.
An example of the system wide ~/.autotest
configuration file could look like this.
Here fsevent and growl notifications are added.
# Include plugins
require 'autotest/fsevent'
require 'autotest/growl'
# Skip some paths
Autotest.add_hook :initialize do |autotest|
%w{.git .DS_Store ._* vendor}.each { |exception| autotest.add_exception(exception) }
false
end
Autotest supporting gems
You will have to install some gems to get this configuration working
$ gem install ZenTest autotest-growl autotest-fsevent
If you are using rails also install the autotest rails integration gem
$ gem install autotest-rails
Rspec 2 configuration
You will likely want to setup a default rspec execution profile in /.rspec
and/or a system wide configuration in ~/.rspec
. Here is an example to configure RSpec 2 to format spec results nested and with color (red/green).
Note: This configuration takes effect any time you run rspec, whether explicit or implicit using autotest.
# /.rspec
--format nested
--color
Rspec and cucumber configuration
If you use Cucumber with RSpec 2, you likely want to add a cucumber configuration file in config/cucumber.yml with some
cucumber execution profiles. For example:
default: --format profile features
html_report: --format progress --format html --out=features_report.html features
If you want to run the rspec specs and ignore the cucumber features, run autotest with environment variable AUTOFEATURE=false.
$ AUTOFEATURE=false autotest
(Not running features. To run features in autotest, set AUTOFEATURE=true.)
loading autotest/rspec2
style: Rspec2