2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2020

10/05/2008: RCOV - Covering unit, integration, and functional testing in one analysis.

Add the following code into a file called lib/tasks/rcov.rake. Notice that I used the find to gather the relevant tests then the xargs to form them into a nice line which can be added to the rcov command.

namespace :test do

  desc 'Tracks test coverage with rcov'
  task :coverage => :environment do
    rm_f "coverage"
    rm_f "coverage.data"

    rcov = "rcov --sort coverage --rails --aggregate coverage.data --text-summary -Ilib -Itest -T -x gem/*,rcov*"

    files = `find . -name *_test.rb | xargs`

    rcov = "#{rcov} " + files
    puts rcov
    system rcov

    system("firefox coverage/index.html")
  end

end

The new rake command can be executed using rake test:coverage

09/29/2008: Advanced Rails Recipes - Chapter Two - The missing copy method.

I am reading through the Advanced Rails Recipes book. In chapter two, it refers to an Event.copy method which is not shown in the book. Shown below is the missing method from app/models/event.rb.

class Event < ActiveRecord::Base

  def self.copy(other)
    self.new(other.attributes.merge(:name => "Copy of #{other.name}"))
  end

end