diff --git a/Gemfile b/Gemfile
index d6151f4..1679aed 100644
--- a/Gemfile
+++ b/Gemfile
@@ -15,3 +15,5 @@ gem 'mocha', '0.9.12'
gem 'guard-jasmine-headless-webkit', :git => 'git://github.com/johnbintz/guard-jasmine-headless-webkit.git'
gem 'facter'
+gem 'jquery-rails'
+
diff --git a/bin/jasmine-headless-webkit b/bin/jasmine-headless-webkit
index 5495d33..3796599 100755
--- a/bin/jasmine-headless-webkit
+++ b/bin/jasmine-headless-webkit
@@ -1,21 +1,23 @@
#!/usr/bin/env ruby
require 'rubygems'
-require 'rainbow'
def gem_dir
File.expand_path('../..', __FILE__)
end
$:.unshift(File.join(gem_dir, 'lib'))
+
require 'jasmine-headless-webkit'
+require 'coffee-script'
+require 'rainbow'
begin
options = Jasmine::Headless::Options.from_command_line
runner = Jasmine::Headless::Runner.new(options)
if options[:do_list]
- files_list = Jasmine::FilesList.new(:config => runner.jasmine_config)
+ files_list = Jasmine::Headless::FilesList.new(:config => runner.jasmine_config)
files_list.files.each { |file| puts file }
else
exit runner.run
diff --git a/jasmine-headless-webkit.gemspec b/jasmine-headless-webkit.gemspec
index 834f207..627b159 100644
--- a/jasmine-headless-webkit.gemspec
+++ b/jasmine-headless-webkit.gemspec
@@ -24,4 +24,5 @@ Gem::Specification.new do |s|
s.add_dependency 'coffee-script', '>= 2.2'
s.add_dependency 'rainbow'
s.add_dependency 'multi_json'
+ s.add_dependency 'sprockets', '~> 2.0'
end
diff --git a/lib/jasmine-headless-webkit.rb b/lib/jasmine-headless-webkit.rb
index c279e93..556c370 100644
--- a/lib/jasmine-headless-webkit.rb
+++ b/lib/jasmine-headless-webkit.rb
@@ -1,7 +1,3 @@
-module Jasmine
- autoload :FilesList, 'jasmine/files_list'
-end
-
require 'jasmine/headless'
require 'jasmine/headless/railtie' if defined?(Rails) && Rails::VERSION::MAJOR >= 3
diff --git a/lib/jasmine/headless.rb b/lib/jasmine/headless.rb
index b35ff93..664ccc0 100644
--- a/lib/jasmine/headless.rb
+++ b/lib/jasmine/headless.rb
@@ -8,6 +8,8 @@ module Jasmine::Headless
autoload :Runner, 'jasmine/headless/runner'
autoload :Options, 'jasmine/headless/options'
autoload :Task, 'jasmine/headless/task'
+ autoload :FilesList, 'jasmine/headless/files_list'
+ autoload :TestFile, 'jasmine/headless/test_file'
autoload :TemplateWriter, 'jasmine/headless/template_writer'
diff --git a/lib/jasmine/files_list.rb b/lib/jasmine/headless/files_list.rb
similarity index 95%
rename from lib/jasmine/files_list.rb
rename to lib/jasmine/headless/files_list.rb
index 828637d..97b05d3 100644
--- a/lib/jasmine/files_list.rb
+++ b/lib/jasmine/headless/files_list.rb
@@ -2,7 +2,7 @@ require 'jasmine-core'
require 'time'
require 'multi_json'
-module Jasmine
+module Jasmine::Headless
class FilesList
attr_reader :files, :spec_files, :filtered_files, :spec_outside_scope
@@ -60,7 +60,7 @@ module Jasmine
def spec_file_line_numbers
@spec_file_line_numbers ||= Hash[@spec_files.collect { |file|
- if File.exist?(file)
+ if ::File.exist?(file)
if !(lines = Jasmine::Headless::SpecFileAnalyzer.for(file)).empty?
[ file, lines ]
end
@@ -82,6 +82,8 @@ module Jasmine
source = nil
+ next file.to_html
+
result = case File.extname(file)
when '.coffee'
begin
@@ -162,6 +164,9 @@ module Jasmine
end
end
end
+
+ @files.collect! { |file| Jasmine::Headless::TestFile.new(file) }
+ @filtered_files.collect! { |file| Jasmine::Headless::TestFile.new(file) }
end
def config?
diff --git a/lib/jasmine/headless/runner.rb b/lib/jasmine/headless/runner.rb
index c82a30d..d742cd4 100644
--- a/lib/jasmine/headless/runner.rb
+++ b/lib/jasmine/headless/runner.rb
@@ -66,7 +66,7 @@ module Jasmine
def run
Jasmine::Headless::CacheableAction.enabled = @options[:enable_cache]
- files_list = Jasmine::FilesList.new(
+ files_list = Jasmine::Headless::FilesList.new(
:config => jasmine_config,
:only => @options[:files]
)
diff --git a/lib/jasmine/headless/test_file.rb b/lib/jasmine/headless/test_file.rb
new file mode 100644
index 0000000..afaeac3
--- /dev/null
+++ b/lib/jasmine/headless/test_file.rb
@@ -0,0 +1,9 @@
+module Jasmine::Headless
+ class TestFile
+ attr_reader :path
+
+ def initialize(path)
+ @path = path
+ end
+ end
+end
diff --git a/spec/bin/jasmine-headless-webkit_spec.rb b/spec/bin/jasmine-headless-webkit_spec.rb
index 72845c0..9105391 100644
--- a/spec/bin/jasmine-headless-webkit_spec.rb
+++ b/spec/bin/jasmine-headless-webkit_spec.rb
@@ -138,5 +138,21 @@ describe "jasmine-headless-webkit" do
File.size(runner_path.path).should_not == 0
end
end
+
+ describe 'sprockets' do
+ it 'should pull in the code via sprockets' do
+ files = %x{bin/jasmine-headless-webkit -l -j spec/jasmine/with_sprockets_includes/with_sprockets_includes.yml}
+ $?.exitstatus.should == 0
+
+ puts files
+
+ files.lines.to_a.should include('vendor/assets/javascripts/jquery.js')
+ files.lines.to_a.should include('assets/code.js')
+ files.lines.to_a.should include('assets/required.js')
+ files.lines.to_a.should include('assets/subcode/more_code.js')
+ files.lines.to_a.should include('spec/spec_helper.js')
+ files.lines.to_a.should include('spec/code_spec.js')
+ end
+ end
end
diff --git a/spec/jasmine/with_sprockets_includes/assets/application.js b/spec/jasmine/with_sprockets_includes/assets/application.js
new file mode 100644
index 0000000..5d11335
--- /dev/null
+++ b/spec/jasmine/with_sprockets_includes/assets/application.js
@@ -0,0 +1,2 @@
+//= require 'jquery'
+//= require_tree '.'
diff --git a/spec/jasmine/with_sprockets_includes/assets/code.js b/spec/jasmine/with_sprockets_includes/assets/code.js
new file mode 100644
index 0000000..bd8cb0d
--- /dev/null
+++ b/spec/jasmine/with_sprockets_includes/assets/code.js
@@ -0,0 +1,2 @@
+window.a = '1';
+
diff --git a/spec/jasmine/with_sprockets_includes/assets/required.js b/spec/jasmine/with_sprockets_includes/assets/required.js
new file mode 100644
index 0000000..e69de29
diff --git a/spec/jasmine/with_sprockets_includes/assets/subcode/more_code.js b/spec/jasmine/with_sprockets_includes/assets/subcode/more_code.js
new file mode 100644
index 0000000..fbe3c2f
--- /dev/null
+++ b/spec/jasmine/with_sprockets_includes/assets/subcode/more_code.js
@@ -0,0 +1,2 @@
+//= require 'required'
+
diff --git a/spec/jasmine/with_sprockets_includes/spec/code_spec.js b/spec/jasmine/with_sprockets_includes/spec/code_spec.js
new file mode 100644
index 0000000..d60428c
--- /dev/null
+++ b/spec/jasmine/with_sprockets_includes/spec/code_spec.js
@@ -0,0 +1,9 @@
+//= require 'code'
+
+describe('code', function() {
+ it('should equal 1', function() {
+ expect(window.a).toEqual(1)
+ expect(jQuery).not.toBeUndefined()
+ });
+});
+
diff --git a/spec/jasmine/with_sprockets_includes/spec/spec_helper.js b/spec/jasmine/with_sprockets_includes/spec/spec_helper.js
new file mode 100644
index 0000000..18241c9
--- /dev/null
+++ b/spec/jasmine/with_sprockets_includes/spec/spec_helper.js
@@ -0,0 +1,2 @@
+//= require 'jquery'
+
diff --git a/spec/jasmine/with_sprockets_includes/with_sprockets_includes.yml b/spec/jasmine/with_sprockets_includes/with_sprockets_includes.yml
new file mode 100644
index 0000000..3b859d0
--- /dev/null
+++ b/spec/jasmine/with_sprockets_includes/with_sprockets_includes.yml
@@ -0,0 +1,12 @@
+src_dir: spec/jasmine/with_sprockets_includes/assets
+spec_dir: spec/jasmine/with_sprockets_includes/spec
+
+spec_files:
+ - "*_spec.js"
+
+src_files:
+ - "*.js"
+
+helpers:
+ - "spec_helper.js"
+
diff --git a/spec/lib/jasmine/files_list_spec.rb b/spec/lib/jasmine/headless/files_list_spec.rb
similarity index 97%
rename from spec/lib/jasmine/files_list_spec.rb
rename to spec/lib/jasmine/headless/files_list_spec.rb
index bb39811..b5674bc 100644
--- a/spec/lib/jasmine/files_list_spec.rb
+++ b/spec/lib/jasmine/headless/files_list_spec.rb
@@ -1,11 +1,10 @@
# encoding: UTF-8
require 'spec_helper'
-require 'jasmine/files_list'
require 'fakefs/spec_helpers'
require 'coffee-script'
-describe Jasmine::FilesList do
+describe Jasmine::Headless::FilesList do
let(:files_list) { described_class.new }
describe '#initialize' do
@@ -47,7 +46,7 @@ describe Jasmine::FilesList do
shared_examples_for :reading_data do
it 'should read the data from the jasmine.yml file and add the files' do
- files_list.files.should == Jasmine::FilesList::DEFAULT_FILES + [
+ files_list.files.should == Jasmine::Headless::FilesList::DEFAULT_FILES + [
File.expand_path(first_file),
File.expand_path(src_file),
File.expand_path(stylesheet_file),
@@ -114,7 +113,7 @@ describe Jasmine::FilesList do
end
context 'with filtered specs' do
- let(:files_list) { Jasmine::FilesList.new(:only => filter, :config => config) }
+ let(:files_list) { Jasmine::Headless::FilesList.new(:only => filter, :config => config) }
let(:spec_dir) { 'spec' }
include FakeFS::SpecHelpers
diff --git a/spec/lib/jasmine/headless/test_file_spec.rb b/spec/lib/jasmine/headless/test_file_spec.rb
new file mode 100644
index 0000000..8a25edc
--- /dev/null
+++ b/spec/lib/jasmine/headless/test_file_spec.rb
@@ -0,0 +1,52 @@
+require 'spec_helper'
+
+describe Jasmine::Headless::TestFile do
+ let(:file) { described_class.new(path) }
+ let(:path) { 'path' }
+
+ subject { file }
+
+ its(:path) { should == path }
+
+ describe '#to_html' do
+ subject { file.to_html }
+
+ context '.js' do
+ let(:path) { 'path.js' }
+
+ it { should == %{} }
+ end
+
+ context '.css' do
+ let(:path) { 'path.css' }
+
+ it { should == %{} }
+ end
+
+ context '.coffee' do
+ let(:path) { 'path.coffee' }
+
+ let(:handle_expectation) { Jasmine::Headless::CoffeeScriptCache.any_instance.stubs(:handle) }
+
+ context 'compilation error' do
+ let(:error) { CoffeeScript::CompilationError.new("fail") }
+
+ before do
+ handle_exception.raises(error)
+ end
+
+ it 'should pass along the error' do
+ expect { subject }.to raise_error(error)
+ end
+ end
+
+ context 'compiles fine' do
+ let(:cached_expectation) { Jasmine::Headless::CoffeeScriptCache.any_instance.stubs(:cached?).returns(cache_return) }
+
+ before do
+
+ end
+ end
+ end
+ end
+end