Auto RSpec
Posted by Nick Sieger Wed, 13 Sep 2006 20:35:00 GMT
Update: (2 months later) If you’re reading this, you’re probably interested in my Rails plugin for this instead.
Hot off the presses, after a few hours of hacking and tweaking, may I present Auto+RSpec, otherwise known as The Mashup of RSpec on Rails and autotest. This is not an official release of any sort, but “may work for you.” It’s not a clean hack, as it exposes some areas for autotest to grow if the maintainers decide to open it up to alternatives to Test::Unit. After spending a little time looking at the autotest code, I think it would be nice to allow hooks for autotest plugins to define project conventions (i.e., @exceptions
and the #tests_for_file
method) as well as a result parsing API.
For now, if you’re an RSpec on Rails user, you can try this out as follows:
- Install ZenTest if you haven’t already:
sudo gem install ZenTest
. - Download rspec_autotest.rb and put in your
vendor/plugins/rspec/lib
directory (you did say you’re using RSpec on Rails didn’t you?) - Download rspec_autotest.rake and put in your
lib/tasks
directory - Start
autotest
with rake by typingrake spec:autotest
- Note: if you’re using RSpec 0.6, you might have better success with the files located here.
Next steps for this will be to work out whether this code should live in RSpec on Rails or autotest, or some combination of those.
Now, spec’ers, be off in search of that Red/Green/Refactor rhythm of which sage agilists speak!
Bonus tip: add the following code to your .autotest
file to run spec
with rcov
:
Autotest.add_hook :initialize do |at|
# run spec with rcov
if at.respond_to? :spec_command
at.spec_command = %{rcov --exclude "lib/spec/.*" -Ilib --rails "/usr/lib/ruby/gems/1.8/gems/rspec-0.6.0/bin/spec" -- --diff}
end
end
Nice!
May I steal this?
Please do, I was hoping you’d take notice and make autotest more extensible as a result. I realize now that I put it out there w/o a copyright notice, so I’ll relinquish it to you as long as you give me an attribution for it. Thanks!
I’m getting this error when running rake spec:autotest
Couldn’t find differ class spec/models/product_spec.rb Make sure the --require option is specified before --diff
Do you know what would cause it?
I haven’t seen that error before, could you provide the full command line that autotest is invoking? Also, which versions of RSpec and ZenTest?
This looks really sweet! I’m having the same issue as meekish though, using ZenTest 3.4.1 and RSpec 0.7.2.
Can one of you guys file a report of some sort at http://trac.caldersphere.net/projects/main/newticket ?
Thanks!
Ah, the issue looks like the change of the
--diff
argument to spec. Can you try the most recent code in svn and let me know if it works for you? Post updated with new links to http://svn.caldersphere.net/svn/main/rspec_autotest/trunk