Created
October 16, 2012 16:47
-
-
Save viddo/3900487 to your computer and use it in GitHub Desktop.
Allow custom rack build on top of jasmine-gem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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