vendored helpers support, take a look at jasmine-spec-extras

This commit is contained in:
John Bintz 2011-10-17 10:07:24 -04:00
parent 8503d86aba
commit 2aabba2cd7
2 changed files with 60 additions and 18 deletions

View File

@ -115,27 +115,37 @@ module Jasmine
@filtered_files = @files.dup @filtered_files = @files.dup
data = @options[:config].dup data = @options[:config].dup
[ [ 'src_files', 'src_dir' ], [ 'stylesheets', 'src_dir' ], [ 'helpers', 'spec_dir' ], [ 'spec_files', 'spec_dir' ] ].each do |searches, root| [ [ 'src_files', 'src_dir' ], [ 'stylesheets', 'src_dir' ], [ 'vendored_helpers' ], [ 'helpers', 'spec_dir' ], [ 'spec_files', 'spec_dir' ] ].each do |searches, root|
if data[searches] if data[searches]
data[searches].flatten.collect do |search| case searches
path = search when 'vendored_helpers'
path = File.join(data[root], path) if data[root] data[searches].each do |name, version|
found_files = expanded_dir(path) - @files found_files = self.class.find_vendored_asset_path(name, version)
@files += found_files @files += found_files
@filtered_files += found_files
if searches == 'spec_files'
@spec_files += spec_filter.empty? ? found_files : (found_files & spec_filter)
end end
else
data[searches].flatten.collect do |search|
path = search
path = File.join(data[root], path) if data[root]
found_files = expanded_dir(path) - @files
@filtered_files += begin @files += found_files
if searches == 'spec_files'
@spec_outside_scope = ((spec_filter | found_files).sort != found_files.sort) if searches == 'spec_files'
spec_filter.empty? ? found_files : (spec_filter || found_files) @spec_files += spec_filter.empty? ? found_files : (found_files & spec_filter)
else end
found_files
@filtered_files += begin
if searches == 'spec_files'
@spec_outside_scope = ((spec_filter | found_files).sort != found_files.sort)
spec_filter.empty? ? found_files : (spec_filter || found_files)
else
found_files
end
end end
end end
end end
end end
end end
@ -148,6 +158,16 @@ module Jasmine
def expanded_dir(path) def expanded_dir(path)
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)
require 'rubygems'
Gem::Specification.map { |spec|
spec.files.find_all { |file|
file["vendor/assets/#{name}/#{version}"]
}.collect { |file| File.join(spec.gem_dir, file) }
}.flatten.compact
end
end end
end end

View File

@ -6,7 +6,7 @@ require 'fakefs/spec_helpers'
require 'coffee-script' require 'coffee-script'
describe Jasmine::FilesList do describe Jasmine::FilesList do
let(:files_list) { Jasmine::FilesList.new } let(:files_list) { described_class.new }
describe '#initialize' do describe '#initialize' do
it "should have default files" do it "should have default files" do
@ -22,7 +22,7 @@ describe Jasmine::FilesList do
end end
describe '#use_config' do describe '#use_config' do
let(:files_list) { Jasmine::FilesList.new(:config => config) } let(:files_list) { described_class.new(:config => config) }
include FakeFS::SpecHelpers include FakeFS::SpecHelpers
@ -81,6 +81,28 @@ describe Jasmine::FilesList do
it_should_behave_like :reading_data it_should_behave_like :reading_data
end end
context 'with vendored helpers' do
let(:config) { {
'src_dir' => src_dir,
'spec_dir' => spec_dir,
'src_files' => [ 'js/first_file.js', 'js/*.js' ],
'spec_files' => [ '*_spec.js' ],
'helpers' => [],
'stylesheets' => [ 'stylesheet/*.css' ],
'vendored_helpers' => { 'one' => 'version' }
} }
let(:helper_file) { "path/one/version.js" }
before do
described_class.expects(:find_vendored_asset_path).with('one', 'version').returns([ helper_file ])
end
it 'should find the vendored file' do
files_list.files.should include(helper_file)
end
end
end end
context 'with filtered specs' do context 'with filtered specs' do