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
|
|
|
|
|
|
|
describe '#initialize' do
|
|
|
|
it "should have default files" do
|
|
|
|
files_list.files.should == [
|
2011-06-30 19:27:57 +00:00
|
|
|
File.join(Jasmine::Core.path, "jasmine.js"),
|
|
|
|
File.join(Jasmine::Core.path, "jasmine-html.js"),
|
2011-10-10 18:11:13 +00:00
|
|
|
File.join(Jasmine::Core.path, "jasmine.css"),
|
2011-10-26 12:45:23 +00:00
|
|
|
File.expand_path('vendor/assets/javascripts/jasmine-extensions.js'),
|
|
|
|
File.expand_path('vendor/assets/javascripts/intense.js'),
|
|
|
|
File.expand_path('vendor/assets/javascripts/headless_reporter_result.js'),
|
2011-10-27 00:05:05 +00:00
|
|
|
File.expand_path('vendor/assets/javascripts/jasmine.HeadlessConsoleReporter.js'),
|
2011-10-26 12:45:23 +00:00
|
|
|
File.expand_path('vendor/assets/javascripts/jsDump.js'),
|
|
|
|
File.expand_path('vendor/assets/javascripts/beautify-html.js'),
|
2011-06-10 14:04:21 +00:00
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-11-21 15:32:49 +00:00
|
|
|
def self.no_default_files!
|
|
|
|
before do
|
|
|
|
described_class.stubs(:default_files).returns([])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-11-22 15:36:42 +00:00
|
|
|
it 'should have tests for #use_config!'
|
|
|
|
it 'should have tests for #add_files'
|
2011-06-10 14:04:21 +00:00
|
|
|
|
2011-07-13 18:42:47 +00:00
|
|
|
describe '#spec_file_line_numbers' do
|
|
|
|
include FakeFS::SpecHelpers
|
|
|
|
|
2011-11-21 15:32:49 +00:00
|
|
|
no_default_files!
|
|
|
|
|
2011-07-13 18:42:47 +00:00
|
|
|
before do
|
2011-11-21 15:32:49 +00:00
|
|
|
files_list.stubs(:spec_files).returns(['test.coffee', 'test2.coffee'])
|
2011-07-13 18:42:47 +00:00
|
|
|
|
2011-07-14 14:54:44 +00:00
|
|
|
File.open('test.coffee', 'w') { |fh| fh.print "describe('cat')\ndescribe('cat')" }
|
2011-07-13 18:42:47 +00:00
|
|
|
File.open('test2.coffee', 'w') { |fh| fh.print "no matches" }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should generate filenames and line number info' do
|
|
|
|
files_list.spec_file_line_numbers.should == {
|
2011-07-14 14:54:44 +00:00
|
|
|
'test.coffee' => { 'cat' => [ 1, 2 ] }
|
2011-07-13 18:42:47 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2011-11-17 21:18:25 +00:00
|
|
|
|
2011-11-18 03:16:04 +00:00
|
|
|
describe '#search_paths' do
|
2011-11-21 15:32:49 +00:00
|
|
|
no_default_files!
|
|
|
|
|
2011-11-18 03:16:04 +00:00
|
|
|
let(:files_list) { described_class.new(:config => config) }
|
|
|
|
|
|
|
|
let(:config) { {
|
|
|
|
'src_dir' => src_dir,
|
|
|
|
'spec_dir' => spec_dir
|
|
|
|
} }
|
|
|
|
|
|
|
|
let(:src_dir) { 'src dir' }
|
|
|
|
let(:spec_dir) { 'spec dir' }
|
|
|
|
let(:path) { 'path' }
|
|
|
|
|
2011-11-20 00:15:38 +00:00
|
|
|
before do
|
|
|
|
Jasmine::Headless::FilesList.stubs(:vendor_asset_paths).returns([])
|
|
|
|
end
|
2011-11-18 03:16:04 +00:00
|
|
|
|
2011-11-20 00:15:38 +00:00
|
|
|
context 'no vendored gem paths' do
|
2011-11-18 03:16:04 +00:00
|
|
|
it 'should take the src dir and spec dirs' do
|
2011-11-18 21:00:24 +00:00
|
|
|
files_list.search_paths.should == [ Jasmine::Core.path, File.expand_path(src_dir), File.expand_path(spec_dir) ]
|
2011-11-18 03:16:04 +00:00
|
|
|
end
|
|
|
|
end
|
2011-11-17 21:18:25 +00:00
|
|
|
|
2011-11-18 03:16:04 +00:00
|
|
|
context 'vendored gem paths' do
|
2011-11-17 21:18:25 +00:00
|
|
|
before do
|
2011-11-18 03:16:04 +00:00
|
|
|
Jasmine::Headless::FilesList.stubs(:vendor_asset_paths).returns([ path ])
|
2011-11-17 21:18:25 +00:00
|
|
|
end
|
|
|
|
|
2011-11-18 03:16:04 +00:00
|
|
|
it 'should add the vendor gem paths to the list' do
|
2011-11-18 21:00:24 +00:00
|
|
|
files_list.search_paths.should == [ Jasmine::Core.path, File.expand_path(src_dir), File.expand_path(spec_dir), path ]
|
2011-11-18 03:16:04 +00:00
|
|
|
end
|
|
|
|
end
|
2011-11-20 00:15:38 +00:00
|
|
|
|
|
|
|
context 'src_dir is an array' do
|
|
|
|
let(:dir_1) { 'dir 1' }
|
|
|
|
let(:dir_2) { 'dir 2' }
|
|
|
|
|
|
|
|
let(:src_dir) { [ dir_1, dir_2 ] }
|
|
|
|
|
|
|
|
it 'should take the src dir and spec dirs' do
|
|
|
|
files_list.search_paths.should == [ Jasmine::Core.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
|
|
|
end
|
|
|
|
|
|
|
|
describe '.vendor_asset_paths' do
|
|
|
|
include FakeFS::SpecHelpers
|
|
|
|
|
|
|
|
let(:dir_one) { 'dir_one' }
|
|
|
|
let(:dir_two) { 'dir_two' }
|
|
|
|
|
|
|
|
let(:gem_one) { stub(:gem_dir => dir_one) }
|
|
|
|
let(:gem_two) { stub(:gem_dir => dir_two) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
described_class.instance_variable_set(:@vendor_asset_paths, nil)
|
|
|
|
|
|
|
|
FileUtils.mkdir_p File.join(dir_two, 'vendor/assets/javascripts')
|
|
|
|
|
|
|
|
Gem::Specification.stubs(:_all).returns([gem_one, gem_two])
|
|
|
|
end
|
2011-11-17 21:18:25 +00:00
|
|
|
|
2011-11-18 03:16:04 +00:00
|
|
|
it 'should return all matching gems with vendor/assets/javascripts directories' do
|
|
|
|
described_class.vendor_asset_paths.should == [ File.join(dir_two, 'vendor/assets/javascripts') ]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-11-21 15:32:49 +00:00
|
|
|
describe '#files' do
|
|
|
|
let(:path_one) { 'one' }
|
|
|
|
let(:path_two) { 'two' }
|
|
|
|
let(:path_three) { 'three' }
|
2011-11-20 00:15:38 +00:00
|
|
|
|
2011-11-22 15:51:46 +00:00
|
|
|
let(:file_one) { stub(:to_a => [ asset_one, asset_two ] ) }
|
|
|
|
let(:file_two) { stub(:to_a => [ asset_two, asset_three ] ) }
|
2011-11-22 15:36:42 +00:00
|
|
|
|
|
|
|
let(:asset_one) { stub(:pathname => Pathname(path_one)) }
|
|
|
|
let(:asset_two) { stub(:pathname => Pathname(path_two)) }
|
|
|
|
let(:asset_three) { stub(:pathname => Pathname(path_three)) }
|
2011-11-18 03:16:04 +00:00
|
|
|
|
|
|
|
before do
|
2011-11-21 15:32:49 +00:00
|
|
|
files_list.stubs(:required_files).returns([ file_one, file_two ])
|
|
|
|
end
|
2011-11-18 03:16:04 +00:00
|
|
|
|
2011-11-21 15:32:49 +00:00
|
|
|
subject { files_list.files }
|
2011-11-20 00:15:38 +00:00
|
|
|
|
2011-11-21 15:32:49 +00:00
|
|
|
it { should == [ path_one, path_two, path_three ] }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#filtered_files' do
|
|
|
|
let(:spec_dir) { 'spec' }
|
2011-11-18 03:16:04 +00:00
|
|
|
|
2011-11-21 15:32:49 +00:00
|
|
|
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-18 03:16:04 +00:00
|
|
|
|
2011-11-21 15:32:49 +00:00
|
|
|
before do
|
|
|
|
files_list.stubs(:files).returns([
|
|
|
|
file_one,
|
|
|
|
file_two,
|
|
|
|
file_three,
|
|
|
|
file_four
|
|
|
|
])
|
2011-11-17 21:18:25 +00:00
|
|
|
|
2011-11-21 15:32:49 +00:00
|
|
|
files_list.stubs(:potential_files_to_filter).returns([ file_one, file_two, file_three ])
|
2011-11-20 00:15:38 +00:00
|
|
|
end
|
|
|
|
|
2011-11-21 15:32:49 +00:00
|
|
|
subject { files_list.filtered_files }
|
2011-11-20 00:15:38 +00:00
|
|
|
|
2011-11-21 15:32:49 +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-20 00:15:38 +00:00
|
|
|
end
|
|
|
|
|
2011-11-21 15:32:49 +00:00
|
|
|
context 'with filter' do
|
|
|
|
before do
|
|
|
|
files_list.stubs(:spec_filter).returns([ "#{spec_dir}/one", '**/tw*' ])
|
|
|
|
end
|
2011-11-20 00:15:38 +00:00
|
|
|
|
2011-11-21 15:32:49 +00:00
|
|
|
it { should == [ file_one, file_two, file_four ] }
|
2011-11-17 21:18:25 +00:00
|
|
|
end
|
|
|
|
end
|
2011-06-10 14:04:21 +00:00
|
|
|
end
|
|
|
|
|