This repository has been archived by the owner on Jun 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 99
/
files_list_spec.rb
194 lines (146 loc) · 5.66 KB
/
files_list_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
require 'spec_helper'
require 'fakefs/spec_helpers'
require 'coffee-script'
describe Jasmine::Headless::FilesList do
let(:files_list) { described_class.new }
describe '#initialize' do
before do
described_class.any_instance.stubs(:load_initial_assets)
end
describe '#spec_file_line_numbers' do
include FakeFS::SpecHelpers
before do
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" }
end
it 'should generate filenames and line number info' do
files_list.spec_file_line_numbers.should == {
'test.coffee' => { 'cat' => [ 1, 2 ] }
}
end
end
describe '#search_paths' do
let(:files_list) { described_class.new(:config => config) }
let(:config) { {
'src_dir' => src_dir,
'spec_dir' => spec_dir,
'asset_paths' => asset_paths
} }
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([])
end
let(:vendor_path) { Jasmine::Headless.root.join('vendor/assets/javascripts').to_s }
context 'no vendored gem paths' do
it 'should take the src dir and spec dirs' do
files_list.search_paths.should == [ Jasmine::Core.path, vendor_path, File.expand_path(src_dir), File.expand_path(spec_dir) ]
end
end
context 'vendored gem paths' do
before do
Jasmine::Headless::FilesList.stubs(:asset_paths).returns([ path ])
end
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
context 'multiple dirs' do
let(:dir_1) { 'dir 1' }
let(:dir_2) { 'dir 2' }
context 'src_dir is an array' do
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, vendor_path, File.expand_path(dir_1), File.expand_path(dir_2), File.expand_path(spec_dir) ]
end
end
context 'asset_paths has entries' do
let(:src_dir) { dir_1 }
let(:asset_paths) { [ dir_2 ] }
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
end
describe '#files' do
let(:path_one) { 'one' }
let(:path_two) { 'two' }
let(:path_three) { 'three' }
let(:file_one) { stub(:to_a => [ asset_one, asset_two ] ) }
let(:file_two) { stub(:to_a => [ asset_two, asset_three ] ) }
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) }
before do
files_list.stubs(:required_files).returns(Jasmine::Headless::UniqueAssetList.new([ file_one, file_two ]))
end
subject { files_list.files }
it { should == [ path_one, path_two, path_three ] }
end
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' }
before do
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 ])
end
subject { files_list.filtered_files }
context 'empty filter' do
before do
files_list.stubs(:spec_filter).returns([])
end
it { should == [ file_one, file_two, file_three, file_four ] }
end
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
end
describe '#add_files' do
let(:files_list) { described_class.new(:seed => 100) }
let(:dir) { 'tmp' }
before do
FileUtils.mkdir_p dir
10.times do |index|
File.open(File.join(dir, "file-#{index}.js"), 'wb')
end
File.open(File.join(dir, 'file.js.erb'), 'wb')
end
before do
files_list.send(:add_files, [ '*' ], 'spec_files', [ dir ])
end
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}
FileUtils.rm_rf dir
end
it 'should not load an excluded format' do
files_list.files.any? { |file| file['.erb'] }.should be_false
end
end
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
end
end