Using Rcov to measure the test coverage of Rails plugins

Posted by jamie Fri, 24 Aug 2007 18:44:35 GMT

To view the coverage of your plugins using Rcov, first install the rcov gem with sudo gem install rcov, then copy and paste the following onto the end of the Rakefile inside your plugin directory:

desc 'Measures test coverage using rcov'
task :rcov do
  rm_f "coverage"
  rm_f "coverage.data"
  rcov = "rcov --rails --aggregate coverage.data --text-summary -Ilib"
  system("#{rcov} --html #{Dir.glob('test/**/*_test.rb').join(' ')}")
  system("open coverage/index.html") if PLATFORM['darwin']
end

You can now simply run rake rcov from inside your plugin directory which will generate a coverage directory with the results. Open coverage/index.html (if you are on OSX this will open automatically) in a browser to view the results.

Thanks to Mike Clark for his Rcov rake task for Rails which this task is based on.

Posted in , ,  | Tags , , , ,  | 1 comment

Autotest Growl Fail/Pass Smilies

Posted by jamie Mon, 30 Jul 2007 14:19:37 GMT

John Nunemaker posted a handy tip on setting up autotest to work with Growl

I use this all the time now however I didn’t like the ugly smilies (call me shallow if you like). I used Wolfgang Bartelme’s Smily Devkit to make a couple of PNG’s slightly more pleasing to the eye.

Autotest Fail image Autotest Pending image Autotest Pass image

The zip file can be downloaded here: autotest_images.zip

Update 17-08-07: Added ‘pending’ image for RSpec as requested by Aslak Hellesøy

Posted in , , ,  | Tags , , , ,  | 6 comments

Rails Edge: Getting your view extensions ready for edge

Posted by jamie Wed, 16 May 2007 13:07:43 GMT

Following my previous post, below is a modified version of John Nunemaker’s ‘Renaming RHTML to ERB to take into account the format in the extension, and handle the RJS issues I was having.

namespace 'views' do
  desc 'Renames all .rhtml views to .html.erb, .rjs to .js.rjs, .rxml to .xml.builder and .haml to .html.haml'
  task 'rename' do
    Dir.glob('app/views/**/[^_]*.rhtml').each do |file|
      puts `svn mv #{file} #{file.gsub(/\.rhtml$/, '.html.erb')}`
    end

    Dir.glob('app/views/**/[^_]*.rjs').each do |file|
      puts `svn mv #{file} #{file.gsub(/\.rjs$/, '.js.rjs')}`
    end

    Dir.glob('app/views/**/[^_]*.rxml').each do |file|
      puts `svn mv #{file} #{file.gsub(/\.rxml$/, '.xml.builder')}`
    end

    Dir.glob('app/views/**/[^_]*.haml').each do |file|
      puts `svn mv #{file} #{file.gsub(/\.haml$/, '.html.haml')}`
    end
  end
end

Update

Added haml conversion.

Posted in , , ,  | Tags , , , ,  | 8 comments

Disabling plugin code in generators/migrations

Posted by jamie Thu, 21 Sep 2006 10:48:50 GMT

I have found on numerous occasions that I need to disable certain plugin functionality if running a generator / rake db:migrate etc.

An easy way to disable certain functionality follows:

def method_that_shouldnt_be_run_in_migrations_or_generators
  # Return if we are using a generator or migrations
  script = File.basename($0)
  return if (script == 'generate') || (script == 'rake' && ARGV[0] =~ /migrate$/)
end

Posted in ,  | Tags , ,  | 4 comments

Handy Subversion Rake task

Posted by jamie Sat, 29 Jul 2006 09:22:07 GMT

Just read a post from David at Planet Argon showing a way to add un-added files in your Subversion working copy.

I have made this into a simple rake task:
namespace :svn do
  desc "Adds all files with an svn status flag of '?'"
  task(:add_new) { `svn status | awk '/\\?/ {print $2}' | xargs svn add` }
end

Just drop this code in a file called subversion.rake inside the tasks directory. Now you can run rake svn:add_new which will add all new files with an svn status flag of ’?’ in your working copy.

Posted in , ,  | 7 comments