DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Rake Task To Run A Single Rails Unit Or Functional Test
// stolen from here: http://nubyonrails.com/articles/2006/07/28/foscon-and-living-dangerously-with-rake
##
# Run a single test in Rails.
#
# rake blogs_list
# => Runs test_list for BlogsController (functional test)
#
# rake blog_create
# => Runs test_create for BlogTest (unit test)
rule "" do |t|
if /(.*)_([^.]+)$/.match(t.name)
file_name = $1
test_name = $2
if File.exist?("test/unit/#{file_name}_test.rb")
file_name = "unit/#{file_name}_test.rb"
elsif File.exist?("test/functional/#{file_name}_controller_test.rb")
file_name = "functional/#{file_name}_controller_test.rb"
else
raise "No file found for #{file_name}"
end
sh "ruby -Ilib:test test/#{file_name} -n /^test_#{test_name}/"
end
end






Comments
Snippets Manager replied on Wed, 2008/03/19 - 5:38pm
Snippets Manager replied on Wed, 2008/03/19 - 5:38pm