diff --git a/lib/jasmine/headless/files_list.rb b/lib/jasmine/headless/files_list.rb index 4d45d51..8b4f51b 100644 --- a/lib/jasmine/headless/files_list.rb +++ b/lib/jasmine/headless/files_list.rb @@ -1,6 +1,7 @@ require 'jasmine-core' require 'time' require 'multi_json' +require 'set' module Jasmine::Headless class FilesList @@ -35,6 +36,7 @@ module Jasmine::Headless @files = [] @filtered_files = [] + @checked_dependency = Set.new DEFAULT_FILES.each { |file| add_dependency('require', file, nil) } @@ -96,7 +98,12 @@ module Jasmine::Headless end def add_dependencies(file, source_root) - TestFile.new(file, source_root).dependencies.each { |type, name| add_dependency(type, name, source_root) } + TestFile.new(file, source_root).dependencies.each do |type, name| + if !@checked_dependency.include?(name) + @checked_dependency << name + add_dependency(type, name, source_root) + end + end end EXTENSION_FILTER = %r{(#{(%w{.js .css} + Sprockets.engine_extensions).join('|')})$} @@ -124,7 +131,11 @@ module Jasmine::Headless ok = (root == file) ok ||= File.basename(path.gsub("#{file}.", '')).split('.').all? { |part| ".#{part}"[EXTENSION_FILTER] } - return [ File.expand_path(path), File.expand_path(dir) ] if ok + expanded_path = File.expand_path(path) + + if ok + return [ expanded_path, File.expand_path(dir) ] + end end end diff --git a/lib/jasmine/headless/test_file.rb b/lib/jasmine/headless/test_file.rb index 03fbda6..6e3bbb9 100644 --- a/lib/jasmine/headless/test_file.rb +++ b/lib/jasmine/headless/test_file.rb @@ -24,6 +24,8 @@ module Jasmine::Headless @dependencies = processor.directives.collect do |_, type, name| if name[%r{^\.}] name = File.expand_path(File.join(File.dirname(path), name)).gsub(%r{^#{source_root}/}, '') + else + raise Sprockets::ArgumentError.new("require_tree needs a relative path: ./#{path}") if type == 'require_tree' end [ type, name ] diff --git a/spec/jasmine/with_sprockets_includes/assets/things/code.js b/spec/jasmine/with_sprockets_includes/assets/things/code.js index 89bab5e..d437925 100644 --- a/spec/jasmine/with_sprockets_includes/assets/things/code.js +++ b/spec/jasmine/with_sprockets_includes/assets/things/code.js @@ -1,5 +1,5 @@ //= require 'jquery' -//= require_tree 'things/templates' +//= require_tree './templates' //= require 'things/required' window.a = '1'; diff --git a/spec/lib/jasmine/headless/test_file_spec.rb b/spec/lib/jasmine/headless/test_file_spec.rb index 6302fb2..9c47a20 100644 --- a/spec/lib/jasmine/headless/test_file_spec.rb +++ b/spec/lib/jasmine/headless/test_file_spec.rb @@ -82,9 +82,11 @@ describe Jasmine::Headless::TestFile do describe '#dependencies' do include FakeFS::SpecHelpers + let(:directive) { 'require' } + before do FileUtils.mkdir_p File.dirname(path) - File.open(path, 'wb') { |fh| fh.print "//= require '#{req}'\njavascript" } + File.open(path, 'wb') { |fh| fh.print "//= #{directive} '#{req}'\njavascript" } end context 'absolute' do @@ -92,7 +94,17 @@ describe Jasmine::Headless::TestFile do subject { file.dependencies } - it { should == [ [ 'require', req ] ] } + context 'require' do + it { should == [ [ 'require', req ] ] } + end + + context 'require_tree' do + let(:directive) { 'require_tree' } + + it 'should raise an error' do + expect { subject }.to raise_error(Sprockets::ArgumentError, /relative/) + end + end end context 'relative' do