Currently the posts are filtered by: 2012-05-04
Reset this filter to see all posts.

Category: Ruby on Rails
Date: 2012-05-04 22:45

Using SimpleCov with FactoryGirl

FactoryGirl is a great replacement for your Ruby-on-rails fixtures. They offer more flexibility for generating stubs and mack-ups for your automated testing.

SimpleCov is the test coverage tool for Ruby 1.9.x (Use RCov for Ruby 1.8.x).

Using both in conjunction requires two extra lines in your test/test_helper.rb file not covered by any documentation. This will prevent you from getting messages like "Factory not registered: " or "uninitialized constant Test::Unit::TestCase::FactoryGirl (NameError)".

My test_helper.rb file looks like:

Code:  Select all
require 'simplecov'
SimpleCov.start 'rails'
 
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
 
# The following two lines of code will reinitialize Factorygirl:
require 'factory_girl'
FactoryGirl.reload
 
class ActiveSupport::TestCase
...
end