Skip to content

Instantly share code, notes, and snippets.

@viddo
Created October 16, 2012 16:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viddo/3900487 to your computer and use it in GitHub Desktop.
Save viddo/3900487 to your computer and use it in GitHub Desktop.
Allow custom rack build on top of jasmine-gem
# Custom jasmine config based to allow Sprockets assets (+ CoffeeScript) when writing tests on a Sinatra stack.
#
# Based heisters gist and patch which was for version 1.2.0
# https://gist.github.com/1695818
# https://github.com/heisters/jasmine-gem/commit/15277ed7885a5d08ab84d2a4a2417e0d22564c07
# Simply did a small port of this to the latest version of Jasmine.
#
# For the custom rack build to work you have to setup the gem to use the patched version to work correctly.
# E.g. using bundler put this in your Gemfile:
# gem 'jasmine', :git => 'https://github.com/viddo/jasmine-gem.git'
require 'sprockets'
require 'coffee_script'
module Jasmine
class Config
# Add your overrides or custom config code here
def custom_rack_build rack
this = self #Rack are using instance_eval, so the default receiver is about to change
rack.map '/assets' do
sprockets = Sprockets::Environment.new this.project_root
sprockets.append_path 'assets'
run sprockets
end
# Allows spec files to also be written in CoffeeScript and run through a Sprockets instance.
rack.map '/__spec__' do
sprockets = Sprockets::Environment.new this.project_root
sprockets.append_path 'spec/javascripts/specs'
run sprockets
end
end
end
end
# Example meta-config matching the custom jasmine_config.rb paths.
src_files:
- assets/javascripts/myapp/application.js
src_dir: assets/
spec_files:
- myapp/application_spec.js
spec_dir: spec/javascripts/specs
stylesheets:
helpers:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment