2011-08-04 14:18:05 +00:00
|
|
|
# encoding: UTF-8
|
|
|
|
|
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
|
|
|
|
|
|
|
|
describe '#use_config' do
|
2011-10-17 14:07:24 +00:00
|
|
|
let(:files_list) { described_class.new(:config => config) }
|
2011-06-10 14:04:21 +00:00
|
|
|
|
|
|
|
include FakeFS::SpecHelpers
|
|
|
|
|
|
|
|
let(:src_dir) { 'src' }
|
|
|
|
let(:spec_dir) { 'spec' }
|
|
|
|
|
2011-06-11 13:54:15 +00:00
|
|
|
let(:first_file) { File.join(src_dir, 'js/first_file.js') }
|
2011-06-10 14:04:21 +00:00
|
|
|
let(:src_file) { File.join(src_dir, 'js/src_file.js') }
|
|
|
|
let(:spec_file) { File.join(spec_dir, 'spec_file_spec.js') }
|
|
|
|
let(:helper_file) { File.join(spec_dir, 'helper/helper_file.js') }
|
|
|
|
let(:stylesheet_file) { File.join(src_dir, 'stylesheet/blah.css') }
|
|
|
|
|
|
|
|
before do
|
2011-06-11 13:54:15 +00:00
|
|
|
[ first_file, src_file, spec_file, helper_file, stylesheet_file ].each do |file|
|
2011-09-09 15:49:17 +00:00
|
|
|
FileUtils.mkdir_p File.split(file).first
|
2011-06-10 14:04:21 +00:00
|
|
|
File.open(file, 'w')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-08-10 17:11:05 +00:00
|
|
|
shared_examples_for :reading_data do
|
2011-11-17 21:18:25 +00:00
|
|
|
let(:expected_files) do
|
2011-11-18 03:16:04 +00:00
|
|
|
[
|
2011-08-10 17:11:05 +00:00
|
|
|
File.expand_path(first_file),
|
|
|
|
File.expand_path(src_file),
|
|
|
|
File.expand_path(stylesheet_file),
|
|
|
|
File.expand_path(helper_file),
|
|
|
|
File.expand_path(spec_file)
|
|
|
|
]
|
2011-11-17 21:18:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should read the data from the jasmine.yml file and add the files' do
|
|
|
|
files_list.files.should == expected_files
|
2011-09-09 15:49:17 +00:00
|
|
|
|
|
|
|
files_list.spec_files.should == [ File.expand_path(spec_file) ]
|
2011-08-10 17:11:05 +00:00
|
|
|
end
|
|
|
|
end
|
2011-06-10 14:04:21 +00:00
|
|
|
|
2011-08-10 17:11:05 +00:00
|
|
|
context 'with normal list' do
|
|
|
|
let(:config) { {
|
|
|
|
'src_dir' => src_dir,
|
|
|
|
'spec_dir' => spec_dir,
|
|
|
|
'src_files' => [ 'js/first_file.js', 'js/*.js' ],
|
|
|
|
'spec_files' => [ '*_spec.js' ],
|
|
|
|
'helpers' => [ 'helper/*.js' ],
|
|
|
|
'stylesheets' => [ 'stylesheet/*.css' ]
|
|
|
|
} }
|
|
|
|
|
|
|
|
it_should_behave_like :reading_data
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with multidimensional list' do
|
|
|
|
let(:config) { {
|
|
|
|
'src_dir' => src_dir,
|
|
|
|
'spec_dir' => spec_dir,
|
|
|
|
'src_files' => [ [ 'js/first_file.js', 'js/*.js' ] ],
|
|
|
|
'spec_files' => [ '*_spec.js' ],
|
|
|
|
'helpers' => [ 'helper/*.js' ],
|
|
|
|
'stylesheets' => [ 'stylesheet/*.css' ]
|
|
|
|
} }
|
|
|
|
|
|
|
|
it_should_behave_like :reading_data
|
2011-06-10 14:04:21 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with filtered specs' do
|
2011-11-16 20:28:02 +00:00
|
|
|
let(:files_list) { Jasmine::Headless::FilesList.new(:only => filter, :config => config) }
|
2011-06-10 14:04:21 +00:00
|
|
|
let(:spec_dir) { 'spec' }
|
|
|
|
|
|
|
|
include FakeFS::SpecHelpers
|
|
|
|
|
|
|
|
let(:config) { {
|
|
|
|
'spec_files' => [ '*_spec.js' ],
|
|
|
|
'spec_dir' => spec_dir
|
|
|
|
} }
|
2011-06-10 15:02:26 +00:00
|
|
|
|
2011-09-09 15:49:17 +00:00
|
|
|
let(:spec_files) { %w{one_spec.js two_spec.js whatever.js} }
|
|
|
|
|
2011-06-10 14:04:21 +00:00
|
|
|
before do
|
2011-09-09 15:49:17 +00:00
|
|
|
spec_files.each do |file|
|
|
|
|
FileUtils.mkdir_p spec_dir
|
2011-06-10 14:04:21 +00:00
|
|
|
File.open(File.join(spec_dir, file), 'w')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-29 14:38:15 +00:00
|
|
|
context 'empty filter' do
|
|
|
|
let(:filter) { [] }
|
|
|
|
|
|
|
|
it 'should return all files for filtered and all files' do
|
|
|
|
files_list.files.any? { |file| file['two_spec.js'] }.should be_true
|
|
|
|
files_list.filtered?.should be_false
|
|
|
|
files_list.should_not have_spec_outside_scope
|
2011-09-09 15:49:17 +00:00
|
|
|
files_list.spec_files.sort.should == %w{one_spec.js two_spec.js}.sort.collect { |file| File.expand_path(File.join(spec_dir, file)) }
|
2011-06-29 14:38:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-23 13:29:07 +00:00
|
|
|
context 'filter with a file that is matchable' do
|
|
|
|
let(:filter) { [ File.expand_path('spec/one_spec.js') ] }
|
2011-06-10 14:04:21 +00:00
|
|
|
|
2011-06-23 13:29:07 +00:00
|
|
|
it 'should return all files for files' do
|
|
|
|
files_list.files.any? { |file| file['two_spec.js'] }.should be_true
|
|
|
|
files_list.filtered?.should be_true
|
|
|
|
files_list.should_not have_spec_outside_scope
|
2011-09-09 15:49:17 +00:00
|
|
|
files_list.spec_files.should == filter
|
2011-06-23 13:29:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return only filtered files for filtered_files' do
|
|
|
|
files_list.filtered_files.any? { |file| file['two_spec.js'] }.should be_false
|
|
|
|
files_list.should_not have_spec_outside_scope
|
|
|
|
end
|
2011-06-10 14:04:21 +00:00
|
|
|
end
|
|
|
|
|
2011-06-30 10:41:32 +00:00
|
|
|
context 'filter with a glob' do
|
|
|
|
let(:filter) { [ File.expand_path('spec/one*') ] }
|
|
|
|
|
|
|
|
it 'should return all files for files' do
|
|
|
|
files_list.files.any? { |file| file['two_spec.js'] }.should be_true
|
|
|
|
files_list.filtered?.should be_true
|
|
|
|
files_list.should_not have_spec_outside_scope
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return only filtered files for filtered_files' do
|
|
|
|
files_list.filtered_files.any? { |file| file['two_spec.js'] }.should be_false
|
|
|
|
files_list.should_not have_spec_outside_scope
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-23 13:29:07 +00:00
|
|
|
context 'filter with a file that is not even there' do
|
|
|
|
let(:filter) { [ File.expand_path('spec/whatever.js') ] }
|
|
|
|
|
|
|
|
it 'should use the provided file' do
|
|
|
|
files_list.filtered_files.any? { |file| file['whatever.js'] }.should be_true
|
|
|
|
files_list.should have_spec_outside_scope
|
|
|
|
end
|
2011-06-10 14:04:21 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-07-13 18:42:47 +00:00
|
|
|
describe '#spec_file_line_numbers' do
|
|
|
|
include FakeFS::SpecHelpers
|
|
|
|
|
|
|
|
before do
|
|
|
|
files_list.instance_variable_set(:@spec_files, [
|
|
|
|
'test.coffee',
|
|
|
|
'test2.coffee'
|
|
|
|
])
|
|
|
|
|
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 '#add_dependency' do
|
|
|
|
let(:file) { 'file' }
|
|
|
|
let(:other_file) { 'other' }
|
|
|
|
let(:path) { 'path' }
|
2011-11-17 21:18:25 +00:00
|
|
|
|
|
|
|
before do
|
2011-11-18 03:16:04 +00:00
|
|
|
files_list.stubs(:find_dependency).with(file).returns(path)
|
|
|
|
files_list.stubs(:find_dependency).with(other_file).returns(false)
|
2011-11-17 21:18:25 +00:00
|
|
|
end
|
|
|
|
|
2011-11-18 03:16:04 +00:00
|
|
|
context 'not found' do
|
2011-11-17 21:18:25 +00:00
|
|
|
before do
|
|
|
|
files_list.expects(:add_file).never
|
|
|
|
end
|
|
|
|
|
2011-11-18 03:16:04 +00:00
|
|
|
it 'should do nothing' do
|
2011-11-18 16:50:48 +00:00
|
|
|
files_list.add_dependency('', other_file, nil)
|
2011-11-17 21:18:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'require' do
|
2011-11-18 03:16:04 +00:00
|
|
|
before do
|
|
|
|
files_list.expects(:add_file).with(path, nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should add the file to the front' do
|
2011-11-18 16:50:48 +00:00
|
|
|
files_list.add_dependency('require', file, nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'require_tree' do
|
|
|
|
include FakeFS::SpecHelpers
|
|
|
|
|
|
|
|
let(:paths) { %w{one.js dir/two.coffee dir/three.css dir/subdir/four.js.erb other/five.css.erb} }
|
|
|
|
|
|
|
|
before do
|
|
|
|
paths.each do |path|
|
|
|
|
FileUtils.mkdir_p File.dirname(path)
|
|
|
|
File.open(path, 'wb')
|
|
|
|
|
|
|
|
if path[%r{\.(js|css|coffee)$}]
|
|
|
|
files_list.expects(:find_dependency).with(path).returns(other_file)
|
|
|
|
files_list.expects(:add_file).with(other_file, nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should add the file to the front' do
|
|
|
|
files_list.add_dependency('require_tree', '.', File.expand_path('.'))
|
2011-11-18 03:16:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#search_paths' do
|
|
|
|
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' }
|
|
|
|
|
|
|
|
context 'no vendored gem paths' do
|
|
|
|
before do
|
|
|
|
Jasmine::Headless::FilesList.stubs(:vendor_asset_paths).returns([])
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
|
|
|
describe '#find_dependency' do
|
|
|
|
include FakeFS::SpecHelpers
|
|
|
|
|
|
|
|
let(:dir) { File.expand_path('dir') }
|
|
|
|
let(:filename) { 'file' }
|
|
|
|
let(:file) { "#{filename}.js" }
|
|
|
|
|
|
|
|
before do
|
|
|
|
files_list.stubs(:search_paths).returns([ dir ])
|
|
|
|
|
|
|
|
FileUtils.mkdir_p dir
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'does not exist' do
|
|
|
|
it 'should not be found' do
|
|
|
|
files_list.find_dependency(file).should be_false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'exists' do
|
|
|
|
let(:path) { File.join(dir, file) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
File.open(path, 'wb')
|
|
|
|
end
|
2011-11-17 21:18:25 +00:00
|
|
|
|
2011-11-18 03:16:04 +00:00
|
|
|
it 'should be found' do
|
|
|
|
files_list.find_dependency(filename).should == [ File.expand_path(path), dir ]
|
2011-11-17 21:18:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-06-10 14:04:21 +00:00
|
|
|
end
|
|
|
|
|