better support for pulling in vendored helpers

This commit is contained in:
John Bintz 2011-10-17 10:34:11 -04:00
parent 2aabba2cd7
commit 065cb6a985
2 changed files with 18 additions and 11 deletions

View File

@ -119,8 +119,8 @@ module Jasmine
if data[searches] if data[searches]
case searches case searches
when 'vendored_helpers' when 'vendored_helpers'
data[searches].each do |name, version| data[searches].each do |name|
found_files = self.class.find_vendored_asset_path(name, version) found_files = self.class.find_vendored_asset_path(name)
@files += found_files @files += found_files
@filtered_files += found_files @filtered_files += found_files
@ -159,14 +159,16 @@ module Jasmine
Dir[path].collect { |file| File.expand_path(file) } Dir[path].collect { |file| File.expand_path(file) }
end end
def self.find_vendored_asset_path(name, version) def self.find_vendored_asset_path(name)
require 'rubygems' require 'rubygems'
Gem::Specification.map { |spec| all_spec_files.find_all { |file| file["vendor/assets/javascripts/#{name}.js"] }
spec.files.find_all { |file| end
file["vendor/assets/#{name}/#{version}"]
}.collect { |file| File.join(spec.gem_dir, file) } def self.all_spec_files
}.flatten.compact @all_spec_files ||= Gem::Specification.map { |spec| spec.files.find_all { |file|
file["vendor/assets/javascripts"]
}.compact.collect { |file| File.join(spec.gem_dir, file) } }.flatten
end end
end end
end end

View File

@ -90,17 +90,22 @@ describe Jasmine::FilesList do
'spec_files' => [ '*_spec.js' ], 'spec_files' => [ '*_spec.js' ],
'helpers' => [], 'helpers' => [],
'stylesheets' => [ 'stylesheet/*.css' ], 'stylesheets' => [ 'stylesheet/*.css' ],
'vendored_helpers' => { 'one' => 'version' } 'vendored_helpers' => [ 'one', 'two' ]
} } } }
let(:helper_file) { "path/one/version.js" } let(:helper_file) { "path/one.js" }
let(:other_helper_file) { "path/two.js" }
before do before do
described_class.expects(:find_vendored_asset_path).with('one', 'version').returns([ helper_file ]) described_class.expects(:find_vendored_asset_path).with('one').returns([ helper_file ])
described_class.expects(:find_vendored_asset_path).with('two').returns([ other_helper_file ])
end end
it 'should find the vendored file' do it 'should find the vendored file' do
files_list.files.should include(helper_file) files_list.files.should include(helper_file)
files_list.files.should include(other_helper_file)
files_list.files.index(helper_file).should be < files_list.files.index(other_helper_file)
end end
end end
end end