2011-06-10 14:04:21 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
require 'fakefs/spec_helpers'
|
|
|
|
require 'coffee-script'
|
|
|
|
|
2011-11-16 20:28:02 +00:00
|
|
|
describe Jasmine::Headless::FilesList do
|
2011-10-17 14:07:24 +00:00
|
|
|
let(:files_list) { described_class.new }
|
2011-06-10 14:04:21 +00:00
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
describe '#initialize' do
|
|
|
|
before do
|
|
|
|
described_class.any_instance.stubs(:load_initial_assets)
|
2011-11-18 03:16:04 +00:00
|
|
|
end
|
2011-11-17 21:18:25 +00:00
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
describe '#spec_file_line_numbers' do
|
|
|
|
include FakeFS::SpecHelpers
|
|
|
|
|
2011-11-17 21:18:25 +00:00
|
|
|
before do
|
2011-12-30 16:34:30 +00:00
|
|
|
files_list.stubs(:spec_files).returns(['test.coffee', 'test2.coffee'])
|
|
|
|
|
|
|
|
File.open('test.coffee', 'w') { |fh| fh.print "describe('cat')\ndescribe('cat')" }
|
|
|
|
File.open('test2.coffee', 'w') { |fh| fh.print "no matches" }
|
2011-11-17 21:18:25 +00:00
|
|
|
end
|
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
it 'should generate filenames and line number info' do
|
|
|
|
files_list.spec_file_line_numbers.should == {
|
|
|
|
'test.coffee' => { 'cat' => [ 1, 2 ] }
|
|
|
|
}
|
2011-11-18 03:16:04 +00:00
|
|
|
end
|
|
|
|
end
|
2011-11-20 00:15:38 +00:00
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
describe '#search_paths' do
|
|
|
|
let(:files_list) { described_class.new(:config => config) }
|
2011-11-20 00:15:38 +00:00
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
let(:config) { {
|
|
|
|
'src_dir' => src_dir,
|
|
|
|
'spec_dir' => spec_dir,
|
|
|
|
'asset_paths' => asset_paths
|
|
|
|
} }
|
2011-11-20 00:15:38 +00:00
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
let(:src_dir) { 'src dir' }
|
|
|
|
let(:spec_dir) { 'spec dir' }
|
|
|
|
let(:asset_paths) { [] }
|
|
|
|
let(:path) { 'path' }
|
|
|
|
|
|
|
|
before do
|
|
|
|
Jasmine::Headless::FilesList.stubs(:asset_paths).returns([])
|
2011-12-01 21:52:01 +00:00
|
|
|
end
|
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
let(:vendor_path) { Jasmine::Headless.root.join('vendor/assets/javascripts').to_s }
|
2011-12-01 21:52:01 +00:00
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
context 'no vendored gem paths' do
|
2011-12-01 21:52:01 +00:00
|
|
|
it 'should take the src dir and spec dirs' do
|
2011-12-30 16:34:30 +00:00
|
|
|
files_list.search_paths.should == [ Jasmine::Core.path, vendor_path, File.expand_path(src_dir), File.expand_path(spec_dir) ]
|
2011-12-01 21:52:01 +00:00
|
|
|
end
|
2011-11-20 00:15:38 +00:00
|
|
|
end
|
2011-11-18 03:16:04 +00:00
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
context 'vendored gem paths' do
|
|
|
|
before do
|
|
|
|
Jasmine::Headless::FilesList.stubs(:asset_paths).returns([ path ])
|
|
|
|
end
|
2011-11-18 03:16:04 +00:00
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
it 'should add the vendor gem paths to the list' do
|
|
|
|
files_list.search_paths.should == [ Jasmine::Core.path, vendor_path, path, File.expand_path(src_dir), File.expand_path(spec_dir) ]
|
|
|
|
end
|
|
|
|
end
|
2011-11-18 03:16:04 +00:00
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
context 'multiple dirs' do
|
|
|
|
let(:dir_1) { 'dir 1' }
|
|
|
|
let(:dir_2) { 'dir 2' }
|
2011-11-18 03:16:04 +00:00
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
context 'src_dir is an array' do
|
|
|
|
let(:src_dir) { [ dir_1, dir_2 ] }
|
2011-11-18 03:16:04 +00:00
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
it 'should take the src dir and spec dirs' do
|
|
|
|
files_list.search_paths.should == [ Jasmine::Core.path, vendor_path, File.expand_path(dir_1), File.expand_path(dir_2), File.expand_path(spec_dir) ]
|
|
|
|
end
|
|
|
|
end
|
2011-11-18 03:16:04 +00:00
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
context 'asset_paths has entries' do
|
|
|
|
let(:src_dir) { dir_1 }
|
|
|
|
let(:asset_paths) { [ dir_2 ] }
|
2011-11-17 21:18:25 +00:00
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
it 'should take the src dir and spec dirs' do
|
|
|
|
files_list.search_paths.should == [ Jasmine::Core.path, vendor_path, File.expand_path(dir_1), File.expand_path(dir_2), File.expand_path(spec_dir) ]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-11-18 03:16:04 +00:00
|
|
|
end
|
2011-11-20 00:15:38 +00:00
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
describe '#files' do
|
|
|
|
let(:path_one) { 'one' }
|
|
|
|
let(:path_two) { 'two' }
|
|
|
|
let(:path_three) { 'three' }
|
2011-11-22 15:36:42 +00:00
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
let(:file_one) { stub(:to_a => [ asset_one, asset_two ] ) }
|
|
|
|
let(:file_two) { stub(:to_a => [ asset_two, asset_three ] ) }
|
2011-11-18 03:16:04 +00:00
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
let(:asset_one) { stub(:pathname => Pathname(path_one), :to_ary => nil) }
|
|
|
|
let(:asset_two) { stub(:pathname => Pathname(path_two), :to_ary => nil) }
|
|
|
|
let(:asset_three) { stub(:pathname => Pathname(path_three), :to_ary => nil) }
|
2011-11-20 00:15:38 +00:00
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
before do
|
|
|
|
files_list.stubs(:required_files).returns(Jasmine::Headless::UniqueAssetList.new([ file_one, file_two ]))
|
|
|
|
end
|
2011-11-18 03:16:04 +00:00
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
subject { files_list.files }
|
2011-11-18 03:16:04 +00:00
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
it { should == [ path_one, path_two, path_three ] }
|
2011-11-20 00:15:38 +00:00
|
|
|
end
|
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
describe '#filtered_files' do
|
|
|
|
let(:spec_dir) { 'spec' }
|
|
|
|
|
|
|
|
let(:file_one) { "#{spec_dir}/one" }
|
|
|
|
let(:file_two) { "#{spec_dir}/two" }
|
|
|
|
let(:file_three) { "#{spec_dir}/three" }
|
|
|
|
let(:file_four) { 'other/four' }
|
2011-11-20 00:15:38 +00:00
|
|
|
|
2011-11-21 15:32:49 +00:00
|
|
|
before do
|
2011-12-30 16:34:30 +00:00
|
|
|
files_list.stubs(:files).returns([
|
|
|
|
file_one,
|
|
|
|
file_two,
|
|
|
|
file_three,
|
|
|
|
file_four
|
|
|
|
])
|
|
|
|
|
|
|
|
files_list.stubs(:potential_files_to_filter).returns([ file_one, file_two, file_three ])
|
2011-11-21 15:32:49 +00:00
|
|
|
end
|
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
subject { files_list.filtered_files }
|
2011-11-20 00:15:38 +00:00
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
context 'empty filter' do
|
|
|
|
before do
|
|
|
|
files_list.stubs(:spec_filter).returns([])
|
|
|
|
end
|
|
|
|
|
|
|
|
it { should == [ file_one, file_two, file_three, file_four ] }
|
2011-11-21 15:32:49 +00:00
|
|
|
end
|
2011-11-20 00:15:38 +00:00
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
context 'with filter' do
|
|
|
|
before do
|
|
|
|
files_list.stubs(:spec_filter).returns([ "#{spec_dir}/one", '**/tw*' ])
|
|
|
|
end
|
|
|
|
|
|
|
|
it { should == [ file_one, file_two, file_four ] }
|
|
|
|
end
|
2011-11-17 21:18:25 +00:00
|
|
|
end
|
2011-11-25 23:11:21 +00:00
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
describe '#add_files' do
|
|
|
|
let(:files_list) { described_class.new(:seed => 100) }
|
2011-11-28 16:47:05 +00:00
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
let(:dir) { 'tmp' }
|
2011-11-25 23:11:21 +00:00
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
before do
|
|
|
|
FileUtils.mkdir_p dir
|
2011-11-25 23:11:21 +00:00
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
10.times do |index|
|
|
|
|
File.open(File.join(dir, "file-#{index}.js"), 'wb')
|
|
|
|
end
|
2011-11-25 23:11:21 +00:00
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
File.open(File.join(dir, 'file.js.erb'), 'wb')
|
2011-11-25 23:11:21 +00:00
|
|
|
end
|
2011-12-06 14:31:23 +00:00
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
before do
|
|
|
|
files_list.send(:add_files, [ '*' ], 'spec_files', [ dir ])
|
|
|
|
end
|
2011-11-25 23:11:21 +00:00
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
it 'should load spec files in a random order' do
|
|
|
|
files_list.files.collect { |name| name[%r{\d+}] }.should == %w{6 7 1 0 5 3 4 8 2 9}
|
2011-11-25 23:11:21 +00:00
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
FileUtils.rm_rf dir
|
|
|
|
end
|
2011-12-06 14:31:23 +00:00
|
|
|
|
2011-12-30 16:34:30 +00:00
|
|
|
it 'should not load an excluded format' do
|
|
|
|
files_list.files.any? { |file| file['.erb'] }.should be_false
|
|
|
|
end
|
2011-12-06 14:31:23 +00:00
|
|
|
end
|
2012-01-22 23:15:45 +00:00
|
|
|
|
|
|
|
describe "#register_engine!" do
|
|
|
|
|
|
|
|
before(:each) do
|
|
|
|
Jasmine::Headless::FilesList.reset!
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should register code added via configure blocks" do
|
|
|
|
template_class = mock()
|
|
|
|
described_class.register_engine ".foo", template_class
|
|
|
|
Sprockets.expects(:register_engine).with(".foo", template_class)
|
|
|
|
described_class.new
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2011-11-25 23:11:21 +00:00
|
|
|
end
|
2011-06-10 14:04:21 +00:00
|
|
|
end
|
|
|
|
|