diff --git a/Gemfile b/Gemfile
index 5d44ae5..5705358 100644
--- a/Gemfile
+++ b/Gemfile
@@ -11,4 +11,4 @@ gem 'guard-shell'
gem 'guard-coffeescript'
gem 'growl'
gem 'rake', '0.8.7'
-gem 'mocha'
+gem 'mocha', '0.9.12'
diff --git a/bin/jasmine-headless-webkit b/bin/jasmine-headless-webkit
index 716008d..1bb7d69 100755
--- a/bin/jasmine-headless-webkit
+++ b/bin/jasmine-headless-webkit
@@ -8,6 +8,7 @@ end
$:.unshift(File.join(gem_dir, 'lib'))
+require 'benchmark'
require 'yaml'
require 'fileutils'
require 'getoptlong'
@@ -36,7 +37,7 @@ opts = GetoptLong.new(
)
options = {
- :colors => false,
+ :colors => false,
:remove_html_file => true,
:jasmine_config => 'spec/javascripts/support/jasmine.yml',
:report => false,
@@ -68,7 +69,7 @@ opts.each(&@process_options)
puts "Running Jasmine specs..."
files_list = Jasmine::FilesList.new(
- :config => load_config(options[:jasmine_config]),
+ :config => load_config(options[:jasmine_config]),
:only => ARGV.dup
)
diff --git a/lib/jasmine/files_list.rb b/lib/jasmine/files_list.rb
index 3b4de7d..add28e1 100644
--- a/lib/jasmine/files_list.rb
+++ b/lib/jasmine/files_list.rb
@@ -37,25 +37,42 @@ module Jasmine
private
def to_html(files)
+ coffeescript_run = []
+
files.collect { |file|
next @code_for_file[file] if @code_for_file[file]
- @code_for_file[file] = (case File.extname(file)
- when '.js'
- %{}
- when '.coffee'
- begin
- %{}
- rescue CoffeeScript::CompilationError => e
- puts "[%s] %s: %s" % [ 'coffeescript'.color(:red), file.color(:yellow), e.message.to_s.color(:white) ]
- exit 1
- ensure
- fh.close
+ coffeescript_run << file if (ext = File.extname(file)) == '.coffee'
+
+ output = []
+ if (files.last == file or ext != '.coffee') and !coffeescript_run.empty?
+ output << ensure_coffeescript_run!(coffeescript_run)
+ end
+
+ if ext != '.coffee'
+ output << case File.extname(file)
+ when '.js'
+ %{}
+ when '.css'
+ %{}
end
- when '.css'
- %{}
- end)
- }
+ end
+
+ @code_for_file[file] = output
+ }.flatten.reject(&:empty?)
+ end
+
+ def ensure_coffeescript_run!(files)
+ data = StringIO.new
+ files.each { |file| data << File.read(file) }
+ data.rewind
+
+ %{}
+ rescue CoffeeScript::CompilationError => e
+ puts "[%s] %s: %s" % [ 'coffeescript'.color(:red), file.color(:yellow), e.message.to_s.color(:white) ]
+ exit 1
+ ensure
+ files.clear
end
def spec_filter
diff --git a/spec/lib/jasmine/files_list_spec.rb b/spec/lib/jasmine/files_list_spec.rb
index 4d4211b..b11e00c 100644
--- a/spec/lib/jasmine/files_list_spec.rb
+++ b/spec/lib/jasmine/files_list_spec.rb
@@ -112,39 +112,72 @@ describe Jasmine::FilesList do
describe '#.*files_to_html' do
include FakeFS::SpecHelpers
- before do
- files_list.instance_variable_set(:@files, [
- 'test.js',
- 'test.coffee',
- 'test.css'
- ])
+ context 'one coffeescript file' do
+ before do
+ files_list.instance_variable_set(:@files, [
+ 'test.js',
+ 'test.coffee',
+ 'test.css'
+ ])
- files_list.instance_variable_set(:@filtered_files, [
- 'test.js',
- 'test.coffee'
- ])
+ files_list.instance_variable_set(:@filtered_files, [
+ 'test.js',
+ 'test.coffee'
+ ])
- File.open('test.coffee', 'w')
+ File.open('test.coffee', 'w') { |fh| fh.print "first" }
- CoffeeScript.stubs(:compile).returns("i compiled")
- end
+ CoffeeScript.stubs(:compile).with() { |field| field.read == "first" }.returns("i compiled")
+ end
- describe '#files_to_html' do
- it "should create the right HTML" do
- files_list.files_to_html.should == [
- %{},
- %{},
- %{}
- ]
+ context '#files_to_html' do
+ it "should create the right HTML" do
+ files_list.files_to_html.should == [
+ %{},
+ %{},
+ %{}
+ ]
+ end
+ end
+
+ context '#filtered_files_to_html' do
+ it "should create the right HTML" do
+ files_list.filtered_files_to_html.should == [
+ %{},
+ %{}
+ ]
+ end
end
end
- describe '#filtered_files_to_html' do
- it "should create the right HTML" do
- files_list.filtered_files_to_html.should == [
- %{},
- %{}
- ]
+ context 'two coffeescript files' do
+ before do
+ files_list.instance_variable_set(:@files, [
+ 'test.js',
+ 'test.coffee',
+ 'test2.coffee',
+ 'test.css'
+ ])
+
+ files_list.instance_variable_set(:@filtered_files, [
+ 'test.js',
+ 'test.coffee'
+ ])
+
+ File.open('test.coffee', 'w') { |fh| fh.print "first" }
+ File.open('test2.coffee', 'w') { |fh| fh.print "second" }
+
+ CoffeeScript.stubs(:compile).with() { |field| field.read == "firstsecond" }.returns("i compiled")
+ end
+
+ context '#files_to_html' do
+ it "should create the right HTML" do
+ files_list.files_to_html.should == [
+ %{},
+ %{},
+ %{}
+ ]
+ end
end
end
end