Using Rcov to measure the test coverage of Rails plugins

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: require ‘rcov/rcovtask’ desc ‘Measures test coverage using rcov’ namespace :rcov do desc ‘Output unit test coverage of plugin.’ Rcov::RcovTask.new(:unit) do […]

Disabling plugin code in generators/migrations

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’ && […]