Skip to content

Instantly share code, notes, and snippets.

@sgonyea
Created June 12, 2011 01:11
Show Gist options
  • Save sgonyea/1021144 to your computer and use it in GitHub Desktop.
Save sgonyea/1021144 to your computer and use it in GitHub Desktop.
How to get jasmine to work with CoffeeScript
begin
require 'bundler'
rescue => e
puts 'Bundler could not be loaded. Please run `gem install bundler` from the command-line, and then `bundle install`.'
raise e
end
Bundler.require :default
load 'jasmine/tasks/jasmine.rake'
namespace :compile do
require 'sprockets'
@env = Sprockets::Environment.new
@compiler = proc {|resources_path, compiled_path, ext|
@env.paths << resources_path
resources_pn = Pathname(resources_path)
compiled_pn = Pathname(compiled_path)
resources = Dir.glob(resources_pn.join("**/*.#{ext}*"))
resources.each {|file|
in_file = Pathname(file).relative_path_from(resources_pn).to_s
out_name = in_file.gsub(/(.*)\.#{ext}\b.*$/, "\\1.#{ext}")
out_file = compiled_pn.join(out_name)
out_file.dirname.mkpath unless Dir.exist?(out_file.dirname)
File.open(out_file, 'w') do |out|
out.write @env[in_file]
end
}
}
task :js do
@compiler['resources/javascripts', 'compiled/javascripts', 'js']
end
task :css do
@compiler['resources/stylesheets', 'compiled/stylesheets', 'css']
end
task :jasmine do
@compiler['spec/javascripts', 'spec/compiled/javascripts', 'js']
end
end
desc 'Compile all of your javascript and css assets, through Sprockets'
task :compile => ['compile:js', 'compile:css']
desc 'Compile all of your assets and run jasmine'
task :spec => ['compile', 'compile:jasmine', 'jasmine']
# src_files
#
# Return an array of filepaths relative to src_dir to include before jasmine specs.
# Default: []
#
# EXAMPLE:
#
# src_files:
# - lib/source1.js
# - lib/source2.js
# - dist/**/*.js
#
src_files:
- compiled/javascripts/**/*.js
# stylesheets
#
# Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs.
# Default: []
#
# EXAMPLE:
#
# stylesheets:
# - css/style.css
# - stylesheets/*.css
#
stylesheets:
# helpers
#
# Return an array of filepaths relative to spec_dir to include before jasmine specs.
# Default: ["helpers/**/*.js"]
#
# EXAMPLE:
#
# helpers:
# - helpers/**/*.js
#
helpers:
# spec_files
#
# Return an array of filepaths relative to spec_dir to include.
# Default: ["**/*[sS]pec.js"]
#
# EXAMPLE:
#
# spec_files:
# - **/*[sS]pec.js
#
spec_files:
# src_dir
#
# Source directory path. Your src_files must be returned relative to this path. Will use root if left blank.
# Default: project root
#
# EXAMPLE:
#
# src_dir: public
#
src_dir:
# spec_dir
#
# Spec directory path. Your spec_files must be returned relative to this path.
# Default: spec/javascripts
#
# EXAMPLE:
#
# spec_dir: spec/javascripts
#
spec_dir: spec/compiled/javascripts
@sgonyea
Copy link
Author

sgonyea commented Jun 12, 2011

If you stumble upon this via google, check out: https://github.com/sgonyea/sprockets_jasmine_coffeescript-example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment