Speed up Rails tests when using Compass

So here’s a little tidbit.  When you’re using Compass with Rails, check to see if it slowed down your tests.  I used test_benchmark, and saw that it increased my test times 3 fold.  I narrowed it down to the initializer/compass.rb files that gets loaded.  Tests should need to use Compass at all to make it work, and just wrap its contents, like so:

if RAILS_ENV != "test"
  require 'compass'
  # If you have any compass plugins, require them here.
  Compass.configuration.parse(File.join(RAILS_ROOT, "config", "compass.config"))
  Compass.configuration.environment = RAILS_ENV.to_sym
  Compass.configure_sass_plugin!
end

And that’ll do it.  

I got too lazy to put this in a gist.  It’d be really nice if posterous let you edit gists in-place in their editor.

Advertisements

2 thoughts on “Speed up Rails tests when using Compass

  1. I suggest turning off Sass entirely in tests with Sass::Plugin.options[:never_update] = true. Your change is basically changing the sass location to a place where there are not stylesheets anyway.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s