Last active
December 20, 2015 22:59
-
-
Save SergXIIIth/6208940 to your computer and use it in GitHub Desktop.
Simple solution, a rake task for use CoffeeScript in Jasmine. Supported: 1. write code in CoffeeScript 2. write spec in CoffeeScript. Could be used in any Ruby application (Sinatra, Rails ...)
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
require 'bundler/gem_tasks' | |
require 'jasmine' | |
require 'coffee-script' | |
require 'fileutils' | |
load 'jasmine/tasks/jasmine.rake' | |
task 'test' do | |
pattern = '{**/*.rb,**/*.slim,**/*.coffee}' | |
system %Q(bundle exec rerun --pattern '#{pattern}' -cx rake test_engine) | |
end | |
task 'test_engine' do | |
system 'rspec' | |
# lib *.coffee -> /spec/javascripts/cache | |
# spec *.coffee -> /spec/javascripts/cache | |
# put /spec/javascripts/cache in .gitignore | |
# in jasmine.yml change | |
# src_files: | |
# - spec/javascripts/cache/lib/**/*.js | |
compile_coffee [ 'lib/redsi/views/js/**/*.coffee' ], '/spec/javascripts/cache/lib/scripts.js' | |
compile_coffee [ 'spec/javascripts/**/*.coffee' ], '/spec/javascripts/cache/spec.js' | |
system 'rake jasmine:ci' | |
end | |
private | |
def compile_coffee(dirs, target_file) | |
def path(relative) | |
root = File.dirname(__FILE__) | |
File.join(root, relative) | |
end | |
target_file = path(target_file) | |
dirs.each do |pattern| | |
js = Dir.glob(path(pattern)).map do |coffee_file_path| | |
CoffeeScript.compile(File.read(coffee_file_path)) | |
end.join(' ') | |
FileUtils.mkdir_p(File.dirname(target_file)) | |
File.write(target_file, js) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment