You've got a lot of Gal

Yet another blog about Ruby, Rails, Javascript, Apple, Malteses and Shih-Tzus by Gal Steinitz

This site is completely static. It was last generated with Octopress and Jekyll on Sep 02, 2013 and hosted on github pages.

Jasmine Debugging: Actual Line Numbers in Error Messages

If you’re using Pivotal Labs’ excellent Jasmine javascript BDD testing framework you may run into this. With Rails 3 Asset Pipeline, jasmine concatenates your js files into a single file - and therefore the line numbers on your stack traces are not useful (they will show the concatenated line numbers).

For example, you may see an error from the concatenated application.js line #17,403 instead of home.js line #15. To get jasmine to reference the javascript files individually and thereby provide more informative error messages, add this in config/initializers/jasmine.rb:

1
2
3
4
5
6
7
8
9
module Jasmine
  class Config
    def src_files
      Rails.application.assets["application"].dependencies.map do |asset|
        "assets/" + asset.logical_path
      end
    end
  end
end

NOTE: This only works if your application.js requires all your javascript files and doesn’t include any javascript itself.