I work on a very large rails project, and rake test has become unruly mostly due to the size of our codebase. Anyway, I wrote this task to run only the tests in the products/namespace I work on.
rake test:products PRODUCTS=product1,product2
Runs all unit tests in test/**/product1/*test*.rb, test/**/product2/*test*.rb
The task:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
namespace :test do
task :products do
raise "Usage: rake test:products PRODUCTS=product1,product2" if ENV['PRODUCTS'].blank?
products = ENV['PRODUCTS'].split(/,/)
files = []
products.each do |product|
dir = "#{RAILS_ROOT}/test/**/#{product}"
files += FileList["#{dir}/*test*.rb"]
end
test_task = Rake::TestTask.new("test_products") do |t|
t.libs << "test"
t.test_files = files
t.verbose = true
end
task("test_products").execute
end
end
|
There is probably an easier way, but this works for me. Also I wouldn’t mind someone patching rake to accept opts style arguments, like –opt=blah, or -o blah. The ENV stuff seems really not so friendly.