Stop running test:unit tests when using rspec
Friday, January 16th, 2009You know those 3 lines that show up every time you do an rspec run?
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -Ilib:test "/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb" /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -Ilib:test "/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb" /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -Ilib:test "/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb"
…yeah, those lines. I hate those lines.
So let’s get rid of them!
Each of those lines is rails trying to run test:unit. RSpec replaces the default rake target by doing this:
task :default => :spec
BUT If you’ve played with rake before, you know that this doesn’t actually replace the default target, it only adds to it. We need to remove the default target then point it at :spec
Turns out that’s not too hard. Put this code (got it from here) at the end of your Rakefile:
Rake::TaskManager.class_eval do def remove_task(task_name) @tasks.delete(task_name.to_s) end end Rake.application.remove_task("default") task :default => :spec
You’re all set!