Skip to content
This repository
Browse code

more clean up work, break things apart for manageability/testing

  • Loading branch information...
commit d5b2239d0fc68355036cbd8fb215b6306cdc87ec 1 parent d31f628
John Bintz authored December 30, 2011
1  Gemfile
@@ -24,5 +24,4 @@ gem 'jquery-rails'
24 24
 gem 'ejs'
25 25
 
26 26
 gem 'simplecov'
27  
-#gem 'perftools.rb'
28 27
 
20  lib/jasmine/headless/files_list.rb
@@ -72,8 +72,6 @@ def reset!
72 72
       def default_files
73 73
         %w{jasmine.js jasmine-html jasmine.css jasmine-extensions
74 74
            intense headless_reporter_result jasmine.HeadlessReporter
75  
-           jasmine.HeadlessReporter.File jasmine.HeadlessReporter.Console
76  
-           jasmine.HeadlessReporter.Tap
77 75
            jsDump beautify-html}
78 76
       end
79 77
 
@@ -91,20 +89,28 @@ def extension_filter
91 89
     def initialize(options = {})
92 90
       @options = options
93 91
 
94  
-      Kernel.srand(@options[:seed]) if @options[:seed]
  92
+      Kernel.srand(options[:seed]) if options[:seed]
95 93
 
96 94
       @required_files = UniqueAssetList.new
97 95
       @potential_files_to_filter = []
98 96
 
  97
+      load_initial_assets
  98
+
  99
+      use_config if config?
  100
+    end
  101
+
  102
+    def load_initial_assets
99 103
       self.class.default_files.each do |file|
100 104
         begin
101  
-          @required_files << sprockets_environment.find_asset(file, :bundle => false)
  105
+          add_path(file)
102 106
         rescue InvalidUniqueAsset => e
103 107
           raise StandardError.new("Not an asset: #{file}")
104 108
         end
105 109
       end
106 110
 
107  
-      use_config! if config?
  111
+      (options[:reporters] || []).each do |reporter, identifier, file|
  112
+        add_path("jasmine.HeadlessReporter.#{reporter}")
  113
+      end
108 114
     end
109 115
 
110 116
     def files
@@ -207,7 +213,7 @@ def spec_filter
207 213
       'spec_files' => 'spec_dir'
208 214
     }
209 215
 
210  
-    def use_config!
  216
+    def use_config
211 217
       @config = @options[:config].dup
212 218
       @searches = {}
213 219
       @potential_files_to_filter = []
@@ -253,7 +259,7 @@ def extension_filter
253 259
       self.class.extension_filter
254 260
     end
255 261
 
256  
-    def add_path(path, type)
  262
+    def add_path(path, type = nil)
257 263
       asset = sprockets_environment.find_asset(path)
258 264
 
259 265
       @required_files << asset
5  lib/jasmine/headless/runner.rb
@@ -103,8 +103,9 @@ def runner_filename
103 103
       def files_list
104 104
         @files_list ||= Jasmine::Headless::FilesList.new(
105 105
           :config => jasmine_config,
106  
-          :only => @options[:files],
107  
-          :seed => @options[:seed]
  106
+          :only => options[:files],
  107
+          :seed => options[:seed],
  108
+          :reporters => options.reporters
108 109
         )
109 110
       end
110 111
 
293  spec/lib/jasmine/headless/files_list_spec.rb
@@ -5,53 +5,6 @@
5 5
 describe Jasmine::Headless::FilesList do
6 6
   let(:files_list) { described_class.new }
7 7
 
8  
-  describe '#initialize' do
9  
-    it "should have default files" do
10  
-      files_list.files.should == [
11  
-        File.join(Jasmine::Core.path, "jasmine.js"),
12  
-        File.join(Jasmine::Core.path, "jasmine-html.js"),
13  
-        File.join(Jasmine::Core.path, "jasmine.css"),
14  
-        File.expand_path('vendor/assets/javascripts/jasmine-extensions.js'),
15  
-        File.expand_path('vendor/assets/javascripts/intense.js'),
16  
-        File.expand_path('vendor/assets/javascripts/headless_reporter_result.js'),
17  
-        File.expand_path('vendor/assets/javascripts/jasmine.HeadlessReporter.js'),
18  
-        File.expand_path('vendor/assets/javascripts/jasmine.HeadlessReporter.File.js'),
19  
-        File.expand_path('vendor/assets/javascripts/jasmine.HeadlessReporter.Console.js'),
20  
-        File.expand_path('vendor/assets/javascripts/jasmine.HeadlessReporter.Tap.js'),
21  
-        File.expand_path('vendor/assets/javascripts/jsDump.js'),
22  
-        File.expand_path('vendor/assets/javascripts/beautify-html.js'),
23  
-      ]
24  
-    end
25  
-  end
26  
-
27  
-  def self.no_default_files!
28  
-    before do
29  
-      described_class.stubs(:default_files).returns([])
30  
-    end
31  
-  end
32  
-
33  
-  it 'should have tests for #use_config!'
34  
-  it 'should have tests for #add_files'
35  
-
36  
-  describe '#spec_file_line_numbers' do
37  
-    include FakeFS::SpecHelpers
38  
-
39  
-    no_default_files!
40  
-
41  
-    before do
42  
-      files_list.stubs(:spec_files).returns(['test.coffee', 'test2.coffee'])
43  
-
44  
-      File.open('test.coffee', 'w') { |fh| fh.print "describe('cat')\ndescribe('cat')" }
45  
-      File.open('test2.coffee', 'w') { |fh| fh.print "no matches" }
46  
-    end
47  
-
48  
-    it 'should generate filenames and line number info' do
49  
-      files_list.spec_file_line_numbers.should == {
50  
-        'test.coffee' => { 'cat' => [ 1, 2 ] }
51  
-      }
52  
-    end
53  
-  end
54  
-
55 8
   describe '.get_paths_from_gemspec' do
56 9
     include FakeFS::SpecHelpers
57 10
 
@@ -75,177 +28,195 @@ def self.no_default_files!
75 28
     it { should =~ paths }
76 29
   end
77 30
 
78  
-  describe '#search_paths' do
79  
-    no_default_files!
80  
-
81  
-    let(:files_list) { described_class.new(:config => config) }
  31
+  describe '.asset_paths' do
  32
+    include FakeFS::SpecHelpers
82 33
 
83  
-    let(:config) { {
84  
-      'src_dir' => src_dir,
85  
-      'spec_dir' => spec_dir,
86  
-      'asset_paths' => asset_paths
87  
-    } }
  34
+    let(:dir_one) { 'dir_one' }
  35
+    let(:dir_two) { 'dir_two' }
88 36
 
89  
-    let(:src_dir) { 'src dir' }
90  
-    let(:spec_dir) { 'spec dir' }
91  
-    let(:asset_paths) { [] }
92  
-    let(:path) { 'path' }
  37
+    let(:gem_one) { stub(:gem_dir => dir_one) }
  38
+    let(:gem_two) { stub(:gem_dir => dir_two) }
93 39
 
94 40
     before do
95  
-      Jasmine::Headless::FilesList.stubs(:asset_paths).returns([])
  41
+      described_class.instance_variable_set(:@asset_paths, nil)
  42
+      FileUtils.mkdir_p File.join(dir_two, 'vendor/assets/javascripts')
  43
+
  44
+      Gem::Specification.stubs(:_all).returns([gem_one, gem_two])
96 45
     end
97 46
 
98  
-    let(:vendor_path) { Jasmine::Headless.root.join('vendor/assets/javascripts').to_s }
  47
+    it 'should return all matching gems with vendor/assets/javascripts directories' do
  48
+      described_class.asset_paths.should == [ File.join(dir_two, 'vendor/assets/javascripts') ]
  49
+    end
  50
+  end
99 51
 
100  
-    context 'no vendored gem paths' do
101  
-      it 'should take the src dir and spec dirs' do
102  
-        files_list.search_paths.should == [ Jasmine::Core.path, vendor_path, File.expand_path(src_dir), File.expand_path(spec_dir) ]
103  
-      end
  52
+  describe '#initialize' do
  53
+    before do
  54
+      described_class.any_instance.stubs(:load_initial_assets)
104 55
     end
105 56
 
106  
-    context 'vendored gem paths' do
  57
+    describe '#spec_file_line_numbers' do
  58
+      include FakeFS::SpecHelpers
  59
+
107 60
       before do
108  
-        Jasmine::Headless::FilesList.stubs(:asset_paths).returns([ path ])
  61
+        files_list.stubs(:spec_files).returns(['test.coffee', 'test2.coffee'])
  62
+
  63
+        File.open('test.coffee', 'w') { |fh| fh.print "describe('cat')\ndescribe('cat')" }
  64
+        File.open('test2.coffee', 'w') { |fh| fh.print "no matches" }
109 65
       end
110 66
 
111  
-      it 'should add the vendor gem paths to the list' do
112  
-        files_list.search_paths.should == [ Jasmine::Core.path, vendor_path, path, File.expand_path(src_dir), File.expand_path(spec_dir) ]
  67
+      it 'should generate filenames and line number info' do
  68
+        files_list.spec_file_line_numbers.should == {
  69
+          'test.coffee' => { 'cat' => [ 1, 2 ] }
  70
+        }
113 71
       end
114 72
     end
115 73
 
116  
-    context 'multiple dirs' do
117  
-      let(:dir_1) { 'dir 1' }
118  
-      let(:dir_2) { 'dir 2' }
  74
+    describe '#search_paths' do
  75
+      let(:files_list) { described_class.new(:config => config) }
119 76
 
120  
-      context 'src_dir is an array' do
121  
-        let(:src_dir) { [ dir_1, dir_2 ] }
  77
+      let(:config) { {
  78
+        'src_dir' => src_dir,
  79
+        'spec_dir' => spec_dir,
  80
+        'asset_paths' => asset_paths
  81
+      } }
122 82
 
123  
-        it 'should take the src dir and spec dirs' do
124  
-          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) ]
125  
-        end
  83
+      let(:src_dir) { 'src dir' }
  84
+      let(:spec_dir) { 'spec dir' }
  85
+      let(:asset_paths) { [] }
  86
+      let(:path) { 'path' }
  87
+
  88
+      before do
  89
+        Jasmine::Headless::FilesList.stubs(:asset_paths).returns([])
126 90
       end
127 91
 
128  
-      context 'asset_paths has entries' do
129  
-        let(:src_dir) { dir_1 }
130  
-        let(:asset_paths) { [ dir_2 ] }
  92
+      let(:vendor_path) { Jasmine::Headless.root.join('vendor/assets/javascripts').to_s }
131 93
 
  94
+      context 'no vendored gem paths' do
132 95
         it 'should take the src dir and spec dirs' do
133  
-          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) ]
  96
+          files_list.search_paths.should == [ Jasmine::Core.path, vendor_path, File.expand_path(src_dir), File.expand_path(spec_dir) ]
134 97
         end
135 98
       end
136  
-    end
137  
-  end
138 99
 
139  
-  describe '.asset_paths' do
140  
-    include FakeFS::SpecHelpers
  100
+      context 'vendored gem paths' do
  101
+        before do
  102
+          Jasmine::Headless::FilesList.stubs(:asset_paths).returns([ path ])
  103
+        end
141 104
 
142  
-    let(:dir_one) { 'dir_one' }
143  
-    let(:dir_two) { 'dir_two' }
  105
+        it 'should add the vendor gem paths to the list' do
  106
+          files_list.search_paths.should == [ Jasmine::Core.path, vendor_path, path, File.expand_path(src_dir), File.expand_path(spec_dir) ]
  107
+        end
  108
+      end
144 109
 
145  
-    let(:gem_one) { stub(:gem_dir => dir_one) }
146  
-    let(:gem_two) { stub(:gem_dir => dir_two) }
  110
+      context 'multiple dirs' do
  111
+        let(:dir_1) { 'dir 1' }
  112
+        let(:dir_2) { 'dir 2' }
147 113
 
148  
-    before do
149  
-      described_class.instance_variable_set(:@asset_paths, nil)
  114
+        context 'src_dir is an array' do
  115
+          let(:src_dir) { [ dir_1, dir_2 ] }
150 116
 
151  
-      FileUtils.mkdir_p File.join(dir_two, 'vendor/assets/javascripts')
  117
+          it 'should take the src dir and spec dirs' do
  118
+            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) ]
  119
+          end
  120
+        end
152 121
 
153  
-      Gem::Specification.stubs(:_all).returns([gem_one, gem_two])
154  
-    end
  122
+        context 'asset_paths has entries' do
  123
+          let(:src_dir) { dir_1 }
  124
+          let(:asset_paths) { [ dir_2 ] }
155 125
 
156  
-    it 'should return all matching gems with vendor/assets/javascripts directories' do
157  
-      described_class.asset_paths.should == [ File.join(dir_two, 'vendor/assets/javascripts') ]
  126
+          it 'should take the src dir and spec dirs' do
  127
+            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) ]
  128
+          end
  129
+        end
  130
+      end
158 131
     end
159  
-  end
160  
-
161  
-  describe '#files' do
162  
-    let(:path_one) { 'one' }
163  
-    let(:path_two) { 'two' }
164  
-    let(:path_three) { 'three' }
165 132
 
166  
-    let(:file_one) { stub(:to_a => [ asset_one, asset_two ] ) }
167  
-    let(:file_two) { stub(:to_a => [ asset_two, asset_three ] ) }
  133
+    describe '#files' do
  134
+      let(:path_one) { 'one' }
  135
+      let(:path_two) { 'two' }
  136
+      let(:path_three) { 'three' }
168 137
 
169  
-    let(:asset_one) { stub(:pathname => Pathname(path_one), :to_ary => nil) }
170  
-    let(:asset_two) { stub(:pathname => Pathname(path_two), :to_ary => nil) }
171  
-    let(:asset_three) { stub(:pathname => Pathname(path_three), :to_ary => nil) }
  138
+      let(:file_one) { stub(:to_a => [ asset_one, asset_two ] ) }
  139
+      let(:file_two) { stub(:to_a => [ asset_two, asset_three ] ) }
172 140
 
173  
-    before do
174  
-      files_list.stubs(:required_files).returns(Jasmine::Headless::UniqueAssetList.new([ file_one, file_two ]))
175  
-    end
176  
-
177  
-    subject { files_list.files }
  141
+      let(:asset_one) { stub(:pathname => Pathname(path_one), :to_ary => nil) }
  142
+      let(:asset_two) { stub(:pathname => Pathname(path_two), :to_ary => nil) }
  143
+      let(:asset_three) { stub(:pathname => Pathname(path_three), :to_ary => nil) }
178 144
 
179  
-    it { should == [ path_one, path_two, path_three ] }
180  
-  end
181  
-
182  
-  describe '#filtered_files' do
183  
-    let(:spec_dir) { 'spec' }
  145
+      before do
  146
+        files_list.stubs(:required_files).returns(Jasmine::Headless::UniqueAssetList.new([ file_one, file_two ]))
  147
+      end
184 148
 
185  
-    let(:file_one) { "#{spec_dir}/one" }
186  
-    let(:file_two) { "#{spec_dir}/two" }
187  
-    let(:file_three) { "#{spec_dir}/three" }
188  
-    let(:file_four) { 'other/four' }
  149
+      subject { files_list.files }
189 150
 
190  
-    before do
191  
-      files_list.stubs(:files).returns([
192  
-        file_one,
193  
-        file_two,
194  
-        file_three,
195  
-        file_four
196  
-      ])
197  
-
198  
-      files_list.stubs(:potential_files_to_filter).returns([ file_one, file_two, file_three ])
  151
+      it { should == [ path_one, path_two, path_three ] }
199 152
     end
200 153
 
201  
-    subject { files_list.filtered_files }
  154
+    describe '#filtered_files' do
  155
+      let(:spec_dir) { 'spec' }
  156
+
  157
+      let(:file_one) { "#{spec_dir}/one" }
  158
+      let(:file_two) { "#{spec_dir}/two" }
  159
+      let(:file_three) { "#{spec_dir}/three" }
  160
+      let(:file_four) { 'other/four' }
202 161
 
203  
-    context 'empty filter' do
204 162
       before do
205  
-        files_list.stubs(:spec_filter).returns([])
  163
+        files_list.stubs(:files).returns([
  164
+                                         file_one,
  165
+                                         file_two,
  166
+                                         file_three,
  167
+                                         file_four
  168
+        ])
  169
+
  170
+        files_list.stubs(:potential_files_to_filter).returns([ file_one, file_two, file_three ])
206 171
       end
207 172
 
208  
-      it { should == [ file_one, file_two, file_three, file_four ] }
209  
-    end
  173
+      subject { files_list.filtered_files }
210 174
 
211  
-    context 'with filter' do
212  
-      before do
213  
-        files_list.stubs(:spec_filter).returns([ "#{spec_dir}/one", '**/tw*' ])
  175
+      context 'empty filter' do
  176
+        before do
  177
+          files_list.stubs(:spec_filter).returns([])
  178
+        end
  179
+
  180
+        it { should == [ file_one, file_two, file_three, file_four ] }
214 181
       end
215 182
 
216  
-      it { should == [ file_one, file_two, file_four ] }
  183
+      context 'with filter' do
  184
+        before do
  185
+          files_list.stubs(:spec_filter).returns([ "#{spec_dir}/one", '**/tw*' ])
  186
+        end
  187
+
  188
+        it { should == [ file_one, file_two, file_four ] }
  189
+      end
217 190
     end
218  
-  end
219 191
 
220  
-  describe '#add_files' do
221  
-    let(:files_list) { described_class.new(:seed => 100) }
  192
+    describe '#add_files' do
  193
+      let(:files_list) { described_class.new(:seed => 100) }
222 194
 
223  
-    no_default_files!
  195
+      let(:dir) { 'tmp' }
224 196
 
225  
-    let(:dir) { 'tmp' }
  197
+      before do
  198
+        FileUtils.mkdir_p dir
226 199
 
227  
-    before do
228  
-      FileUtils.mkdir_p dir
  200
+        10.times do |index|
  201
+          File.open(File.join(dir, "file-#{index}.js"), 'wb')
  202
+        end
229 203
 
230  
-      10.times do |index|
231  
-        File.open(File.join(dir, "file-#{index}.js"), 'wb')
  204
+        File.open(File.join(dir, 'file.js.erb'), 'wb')
232 205
       end
233 206
 
234  
-      File.open(File.join(dir, 'file.js.erb'), 'wb')
235  
-    end
236  
-
237  
-    before do
238  
-      files_list.send(:add_files, [ '*' ], 'spec_files', [ dir ])
239  
-    end
  207
+      before do
  208
+        files_list.send(:add_files, [ '*' ], 'spec_files', [ dir ])
  209
+      end
240 210
 
241  
-    it 'should load spec files in a random order' do
242  
-      files_list.files.collect { |name| name[%r{\d+}] }.should == %w{6 7 1 0 5 3 4 8 2 9}
  211
+      it 'should load spec files in a random order' do
  212
+        files_list.files.collect { |name| name[%r{\d+}] }.should == %w{6 7 1 0 5 3 4 8 2 9}
243 213
 
244  
-      FileUtils.rm_rf dir
245  
-    end
  214
+        FileUtils.rm_rf dir
  215
+      end
246 216
 
247  
-    it 'should not load an excluded format' do
248  
-      files_list.files.any? { |file| file['.erb'] }.should be_false
  217
+      it 'should not load an excluded format' do
  218
+        files_list.files.any? { |file| file['.erb'] }.should be_false
  219
+      end
249 220
     end
250 221
   end
251 222
 end
4  spec/lib/jasmine/headless/runner_spec.rb
@@ -167,10 +167,13 @@ def self.it_should_have_basics
167 167
     let(:only) { 'only' }
168 168
     let(:seed) { 12345 }
169 169
     let(:jasmine_config) { 'jasmine config' }
  170
+    let(:reporters) { [] }
170 171
 
171 172
     before do
172 173
       runner.stubs(:options).returns(options)
173 174
       runner.stubs(:jasmine_config).returns(jasmine_config)
  175
+
  176
+      options.stubs(:reporters).returns(reporters)
174 177
     end
175 178
 
176 179
     it { should be_a_kind_of(Jasmine::Headless::FilesList) }
@@ -179,6 +182,7 @@ def self.it_should_have_basics
179 182
       subject.options[:config].should == jasmine_config
180 183
       subject.options[:only].should == only
181 184
       subject.options[:seed].should == seed
  185
+      subject.options[:reporters].should == reporters
182 186
     end
183 187
   end
184 188
 end

0 notes on commit d5b2239

Please sign in to comment.
Something went wrong with that request. Please try again.