Created
October 25, 2012 16:32
-
-
Save ngauthier/3953867 to your computer and use it in GitHub Desktop.
Coffeescript building with Rake and Jasmine testing with capybara
This file contains 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
# This is a pure rake-style build process for building coffeescript files to js | |
# using the coffee-script ruby gem and Rake's `rule` and `file` directives. | |
# That means that a js file will only be built if it is out of date. | |
require 'rubygems' | |
require 'bundler/setup' | |
require 'coffee-script' | |
require 'capybara-jasmine' | |
require 'capybara/poltergeist' | |
require 'rake/clean' | |
# This says "to make a js file, find a coffee file of the same path | |
# then run this task" | |
rule '.js' => '.coffee' do |t| | |
puts "Compiling #{t.source} => #{t.name}" | |
File.write(t.name, CoffeeScript.compile(File.read(t.source))) | |
end | |
# `rake clean` removes these files | |
CLEAN.include "app/**/*.js" | |
CLEAN.include "spec/**/*.js" | |
# Find all the coffee files, change ext to js | |
# and for each one, make the coffee task depend | |
# on the js file | |
FileList['**/*.coffee'].ext('js').each do |f| | |
task :coffee => f | |
end | |
# At this point `coffee` depends on stuff like `path/foo.js` | |
# which will be built by compiling `path/foo.coffee` | |
# Now, use Capybara::Jasmine to make a `spec` task | |
# It depends on `coffee` which is the union of all | |
# the compiled js | |
Capybara::Jasmine::TestTask.new "spec" => "coffee" do |t| | |
# let's use phantom! | |
Capybara.javascript_driver = :poltergeist | |
# order-dependent lib files | |
t.lib_files = FileList[ | |
"vendor/jquery-1.8.2.js", | |
"vendor/underscore.js", | |
"vendor/backbone.js", | |
"app/mb.js", | |
"app/**/*.js" # then the rest | |
].uniq # don't duplicate mb.js or others, they'd get overwritten | |
t.spec_files = FileList["spec/**/*Spec.js"] | |
end | |
task :test => ['coffee', 'spec'] | |
task :default => :test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment