Never been to DZone Snippets before?

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

About this user

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

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

   1  
   2  ##
   3  # Run a single test in Rails.
   4  #
   5  #   rake blogs_list
   6  #   => Runs test_list for BlogsController (functional test)
   7  #
   8  #   rake blog_create
   9  #   => Runs test_create for BlogTest (unit test)
  10  
  11  rule "" do |t|
  12    if /(.*)_([^.]+)$/.match(t.name)
  13      file_name = $1
  14      test_name = $2
  15      if File.exist?("test/unit/#{file_name}_test.rb")
  16        file_name = "unit/#{file_name}_test.rb" 
  17      elsif File.exist?("test/functional/#{file_name}_controller_test.rb")
  18        file_name = "functional/#{file_name}_controller_test.rb" 
  19      else
  20        raise "No file found for #{file_name}" 
  21      end
  22      sh "ruby -Ilib:test test/#{file_name} -n /^test_#{test_name}/" 
  23    end
  24  end
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS