Andrew CantinoAndrew Cantino
Standup 2/11/2010: Sass with Jasmine
edit Posted by Andrew Cantino on Thursday February 11, 2010 at 09:24AM

Interesting Things

  • If you are testing with jasmine, it's a good idea to include your CSS files in the test runner. This prevents, for example, issues where you've hidden an element in the CSS and expect it to be visible in your JavaScript. If you are using Sass, then you should regenerate your CSS from the Sass before running the jasmine tests. The current version of haml-edge updates the sass command-line tool with an update command. On one of our client projects, we added the following to our jasmine_config.rb file:
  def update_sass
    puts "Updating sass files..."
    rails_root = File.expand_path(File.dirname(__FILE__) + "/../../../")
    sass_path = "#{rails_root}/vendor/bundler_gems/ruby/1.8/gems/haml-edge-2.*/bin/sass"
    puts `#{sass_path} --update #{rails_root}/app/stylesheets:#{rails_root}/public/stylesheets/generated`
    puts "done."
  end

  alias_method :old_start, :start
  def start(*args)
    update_sass
    old_start(*args)
  end

  alias_method :old_start_server, :start_server
  def start_server(*args)
    update_sass
    old_start_server *args
  end

Comments

  1. Chris Eppstein Chris Eppstein on February 11, 2010 at 01:57PM

    Sass provides a method for doing the same thing within ruby:

    Sass::Plugin.update_stylesheets
    

    If you're running within your app container you won't need to configure anything, otherwise you'll need to set the Sass::Plugin.options accordingly first.

  2. Andrew Cantino Andrew Cantino on February 11, 2010 at 03:34PM

    Thanks, Chris!

  3. Rajan Agaskar Rajan Agaskar on February 14, 2010 at 03:31AM

    FWIW, Jasmine, in most cases, will no longer have a jasmine_config.rb. New users would probably be best off adding functionality to the jasmine:ci or jasmine rake tasks that jasmine-ruby provides.