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
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]
data[searches].flatten.collect do |search|
path = search
path = File.join(data[root], path) if data[root]
found_files = expanded_dir(path) - @files
case searches
when 'vendored_helpers'
data[searches].each do |name, version|
found_files = self.class.find_vendored_asset_path(name, version)
@files += found_files
if searches == 'spec_files'
@spec_files += spec_filter.empty? ? found_files : (found_files & spec_filter)
@files += found_files
@filtered_files += found_files
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
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
@files += found_files
if searches == 'spec_files'
@spec_files += spec_filter.empty? ? found_files : (found_files & spec_filter)
end
@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
@ -148,6 +158,16 @@ module Jasmine
def expanded_dir(path)
Dir[path].collect { |file| File.expand_path(file) }
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

View File

@ -6,7 +6,7 @@ require 'fakefs/spec_helpers'
require 'coffee-script'
describe Jasmine::FilesList do
let(:files_list) { Jasmine::FilesList.new }
let(:files_list) { described_class.new }
describe '#initialize' do
it "should have default files" do
@ -22,7 +22,7 @@ describe Jasmine::FilesList do
end
describe '#use_config' do
let(:files_list) { Jasmine::FilesList.new(:config => config) }
let(:files_list) { described_class.new(:config => config) }
include FakeFS::SpecHelpers
@ -81,6 +81,28 @@ describe Jasmine::FilesList do
it_should_behave_like :reading_data
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
context 'with filtered specs' do