more work on making sprockets support better, oh yeah

This commit is contained in:
John Bintz 2011-11-18 11:50:48 -05:00
parent a2e3ea90c9
commit 537b2e437d
6 changed files with 62 additions and 15 deletions

View File

@ -20,6 +20,10 @@ module Jasmine::Headless
File.directory?(path) ? path : nil
}.compact
end
def reset!
@vendor_asset_paths = nil
end
end
DEFAULT_FILES = %w{jasmine.js jasmine-html jasmine.css jasmine-extensions intense headless_reporter_result jasmine.HeadlessConsoleReporter jsDump beautify-html}
@ -32,7 +36,7 @@ module Jasmine::Headless
@files = []
@filtered_files = []
DEFAULT_FILES.each { |file| add_dependency('require', file) }
DEFAULT_FILES.each { |file| add_dependency('require', file, nil) }
@spec_outside_scope = false
@spec_files = []
@ -85,16 +89,20 @@ module Jasmine::Headless
end
def add_dependencies(file, source_root)
TestFile.new(file, source_root).dependencies.each { |type, name| add_dependency(type, name) }
TestFile.new(file, source_root).dependencies.each { |type, name| add_dependency(type, name, source_root) }
end
def add_dependency(type, file)
if result = find_dependency(file)
path, source_root = result
def add_dependency(type, file, source_root)
case type
when 'require'
add_file(path, source_root)
if result = find_dependency(file)
add_file(*result)
end
when 'require_tree'
Dir[File.join(source_root, file, '**/*.{js,css,coffee}')].each do |tree_path|
if result = find_dependency(tree_path.gsub(%r{^#{source_root}/}, ''))
add_file(*result)
end
end
end
end
@ -103,11 +111,11 @@ module Jasmine::Headless
search_paths.each do |dir|
if file[%r{\.(js|css|coffee)$}]
if File.file?(path = File.join(dir, file))
return [ File.expand_path(path), dir ]
return [ File.expand_path(path), File.expand_path(dir) ]
end
else
if path = Dir[File.join(dir, "#{file}.*")].first
return [ File.expand_path(path), dir ]
return [ File.expand_path(path), File.expand_path(dir) ]
end
end
end
@ -163,6 +171,7 @@ module Jasmine::Headless
def add_files(searches, type)
searches.each do |search|
dir = @config[SEARCH_ROOTS[type]] || Dir.pwd
dir = File.expand_path(dir)
path = File.expand_path(File.join(dir, search))

View File

@ -66,6 +66,8 @@ module Jasmine
def run
Jasmine::Headless::CacheableAction.enabled = @options[:enable_cache]
Jasmine::Headless::FilesList.reset!
files_list = Jasmine::Headless::FilesList.new(
:config => jasmine_config,
:only => @options[:files]

View File

@ -46,7 +46,7 @@ module Jasmine::Headless
processor = Sprockets::DirectiveProcessor.new(path)
@dependencies = processor.directives.collect do |_, type, name|
if name[%r{^./}]
if name[%r{^\.}]
name = File.expand_path(File.join(File.dirname(path), name)).gsub(%r{^#{source_root}/}, '')
end

View File

@ -237,7 +237,7 @@ describe Jasmine::Headless::FilesList do
end
it 'should do nothing' do
files_list.add_dependency('', other_file)
files_list.add_dependency('', other_file, nil)
end
end
@ -247,7 +247,29 @@ describe Jasmine::Headless::FilesList do
end
it 'should add the file to the front' do
files_list.add_dependency('require', file)
files_list.add_dependency('require', file, nil)
end
end
context 'require_tree' do
include FakeFS::SpecHelpers
let(:paths) { %w{one.js dir/two.coffee dir/three.css dir/subdir/four.js.erb other/five.css.erb} }
before do
paths.each do |path|
FileUtils.mkdir_p File.dirname(path)
File.open(path, 'wb')
if path[%r{\.(js|css|coffee)$}]
files_list.expects(:find_dependency).with(path).returns(other_file)
files_list.expects(:add_file).with(other_file, nil)
end
end
end
it 'should add the file to the front' do
files_list.add_dependency('require_tree', '.', File.expand_path('.'))
end
end
end

View File

@ -99,5 +99,15 @@ describe Jasmine::Headless::TestFile do
it { should == [ [ 'require', 'subdir/subsubdir/test' ] ] }
end
context 'dot' do
let(:path) { File.join(source_root, 'subdir/subsubdir/path.js') }
let(:req) { '.' }
subject { file.dependencies }
it { should == [ [ 'require', 'subdir/subsubdir' ] ] }
end
end
end

View File

@ -6,7 +6,7 @@ RSpec.configure do |c|
c.before(:each) do
Jasmine::Headless::CacheableAction.enabled = false
Jasmine::Headless::FilesList.instance_variable_set(:@vendor_asset_paths, nil)
Jasmine::Headless::FilesList.reset!
end
end
@ -67,6 +67,10 @@ module RSpec::Matchers
file_list.length == 0
end
failure_message_for_should do |lines|
%{expected\n#{lines.join("\n")}\nto contain the following files, in order:\n#{files.join("\n")}}
end
end
end