Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit d5b2239d0fc68355036cbd8fb215b6306cdc87ec 1 parent d31f628
@johnbintz authored
View
1  Gemfile
@@ -24,5 +24,4 @@ gem 'jquery-rails'
gem 'ejs'
gem 'simplecov'
-#gem 'perftools.rb'
View
20 lib/jasmine/headless/files_list.rb
@@ -72,8 +72,6 @@ def reset!
def default_files
%w{jasmine.js jasmine-html jasmine.css jasmine-extensions
intense headless_reporter_result jasmine.HeadlessReporter
- jasmine.HeadlessReporter.File jasmine.HeadlessReporter.Console
- jasmine.HeadlessReporter.Tap
jsDump beautify-html}
end
@@ -91,20 +89,28 @@ def extension_filter
def initialize(options = {})
@options = options
- Kernel.srand(@options[:seed]) if @options[:seed]
+ Kernel.srand(options[:seed]) if options[:seed]
@required_files = UniqueAssetList.new
@potential_files_to_filter = []
+ load_initial_assets
+
+ use_config if config?
+ end
+
+ def load_initial_assets
self.class.default_files.each do |file|
begin
- @required_files << sprockets_environment.find_asset(file, :bundle => false)
+ add_path(file)
rescue InvalidUniqueAsset => e
raise StandardError.new("Not an asset: #{file}")
end
end
- use_config! if config?
+ (options[:reporters] || []).each do |reporter, identifier, file|
+ add_path("jasmine.HeadlessReporter.#{reporter}")
+ end
end
def files
@@ -207,7 +213,7 @@ def spec_filter
'spec_files' => 'spec_dir'
}
- def use_config!
+ def use_config
@config = @options[:config].dup
@searches = {}
@potential_files_to_filter = []
@@ -253,7 +259,7 @@ def extension_filter
self.class.extension_filter
end
- def add_path(path, type)
+ def add_path(path, type = nil)
asset = sprockets_environment.find_asset(path)
@required_files << asset
View
5 lib/jasmine/headless/runner.rb
@@ -103,8 +103,9 @@ def runner_filename
def files_list
@files_list ||= Jasmine::Headless::FilesList.new(
:config => jasmine_config,
- :only => @options[:files],
- :seed => @options[:seed]
+ :only => options[:files],
+ :seed => options[:seed],
+ :reporters => options.reporters
)
end
View
293 spec/lib/jasmine/headless/files_list_spec.rb
@@ -5,53 +5,6 @@
describe Jasmine::Headless::FilesList do
let(:files_list) { described_class.new }
- describe '#initialize' do
- it "should have default files" do
- files_list.files.should == [
- File.join(Jasmine::Core.path, "jasmine.js"),
- File.join(Jasmine::Core.path, "jasmine-html.js"),
- File.join(Jasmine::Core.path, "jasmine.css"),
- 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'),
- File.expand_path('vendor/assets/javascripts/jasmine.HeadlessReporter.js'),
- File.expand_path('vendor/assets/javascripts/jasmine.HeadlessReporter.File.js'),
- File.expand_path('vendor/assets/javascripts/jasmine.HeadlessReporter.Console.js'),
- File.expand_path('vendor/assets/javascripts/jasmine.HeadlessReporter.Tap.js'),
- File.expand_path('vendor/assets/javascripts/jsDump.js'),
- File.expand_path('vendor/assets/javascripts/beautify-html.js'),
- ]
- end
- end
-
- def self.no_default_files!
- before do
- described_class.stubs(:default_files).returns([])
- end
- end
-
- it 'should have tests for #use_config!'
- it 'should have tests for #add_files'
-
- describe '#spec_file_line_numbers' do
- include FakeFS::SpecHelpers
-
- no_default_files!
-
- 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 '.get_paths_from_gemspec' do
include FakeFS::SpecHelpers
@@ -75,177 +28,195 @@ def self.no_default_files!
it { should =~ paths }
end
- describe '#search_paths' do
- no_default_files!
-
- let(:files_list) { described_class.new(:config => config) }
+ describe '.asset_paths' do
+ include FakeFS::SpecHelpers
- let(:config) { {
- 'src_dir' => src_dir,
- 'spec_dir' => spec_dir,
- 'asset_paths' => asset_paths
- } }
+ let(:dir_one) { 'dir_one' }
+ let(:dir_two) { 'dir_two' }
- let(:src_dir) { 'src dir' }
- let(:spec_dir) { 'spec dir' }
- let(:asset_paths) { [] }
- let(:path) { 'path' }
+ let(:gem_one) { stub(:gem_dir => dir_one) }
+ let(:gem_two) { stub(:gem_dir => dir_two) }
before do
- Jasmine::Headless::FilesList.stubs(:asset_paths).returns([])
+ described_class.instance_variable_set(:@asset_paths, nil)
+ FileUtils.mkdir_p File.join(dir_two, 'vendor/assets/javascripts')
+
+ Gem::Specification.stubs(:_all).returns([gem_one, gem_two])
end
- let(:vendor_path) { Jasmine::Headless.root.join('vendor/assets/javascripts').to_s }
+ it 'should return all matching gems with vendor/assets/javascripts directories' do
+ described_class.asset_paths.should == [ File.join(dir_two, 'vendor/assets/javascripts') ]
+ end
+ end
- 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
+ describe '#initialize' do
+ before do
+ described_class.any_instance.stubs(:load_initial_assets)
end
- context 'vendored gem paths' do
+ describe '#spec_file_line_numbers' do
+ include FakeFS::SpecHelpers
+
before do
- Jasmine::Headless::FilesList.stubs(:asset_paths).returns([ path ])
+ 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 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) ]
+ it 'should generate filenames and line number info' do
+ files_list.spec_file_line_numbers.should == {
+ 'test.coffee' => { 'cat' => [ 1, 2 ] }
+ }
end
end
- context 'multiple dirs' do
- let(:dir_1) { 'dir 1' }
- let(:dir_2) { 'dir 2' }
+ describe '#search_paths' do
+ let(:files_list) { described_class.new(:config => config) }
- context 'src_dir is an array' do
- let(:src_dir) { [ dir_1, dir_2 ] }
+ let(:config) { {
+ 'src_dir' => src_dir,
+ 'spec_dir' => spec_dir,
+ 'asset_paths' => asset_paths
+ } }
- 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
+ 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
- context 'asset_paths has entries' do
- let(:src_dir) { dir_1 }
- let(:asset_paths) { [ dir_2 ] }
+ 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(dir_1), File.expand_path(dir_2), File.expand_path(spec_dir) ]
+ files_list.search_paths.should == [ Jasmine::Core.path, vendor_path, File.expand_path(src_dir), File.expand_path(spec_dir) ]
end
end
- end
- end
- describe '.asset_paths' do
- include FakeFS::SpecHelpers
+ context 'vendored gem paths' do
+ before do
+ Jasmine::Headless::FilesList.stubs(:asset_paths).returns([ path ])
+ end
- let(:dir_one) { 'dir_one' }
- let(:dir_two) { 'dir_two' }
+ 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
- let(:gem_one) { stub(:gem_dir => dir_one) }
- let(:gem_two) { stub(:gem_dir => dir_two) }
+ context 'multiple dirs' do
+ let(:dir_1) { 'dir 1' }
+ let(:dir_2) { 'dir 2' }
- before do
- described_class.instance_variable_set(:@asset_paths, nil)
+ context 'src_dir is an array' do
+ let(:src_dir) { [ dir_1, dir_2 ] }
- FileUtils.mkdir_p File.join(dir_two, 'vendor/assets/javascripts')
+ 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
- Gem::Specification.stubs(:_all).returns([gem_one, gem_two])
- end
+ context 'asset_paths has entries' do
+ let(:src_dir) { dir_1 }
+ let(:asset_paths) { [ dir_2 ] }
- it 'should return all matching gems with vendor/assets/javascripts directories' do
- described_class.asset_paths.should == [ File.join(dir_two, 'vendor/assets/javascripts') ]
+ 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
- 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 ] ) }
+ describe '#files' do
+ let(:path_one) { 'one' }
+ let(:path_two) { 'two' }
+ let(:path_three) { '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) }
+ let(:file_one) { stub(:to_a => [ asset_one, asset_two ] ) }
+ let(:file_two) { stub(:to_a => [ asset_two, asset_three ] ) }
- before do
- files_list.stubs(:required_files).returns(Jasmine::Headless::UniqueAssetList.new([ file_one, file_two ]))
- end
-
- subject { files_list.files }
+ 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) }
- it { should == [ path_one, path_two, path_three ] }
- end
-
- describe '#filtered_files' do
- let(:spec_dir) { 'spec' }
+ before do
+ files_list.stubs(:required_files).returns(Jasmine::Headless::UniqueAssetList.new([ file_one, file_two ]))
+ end
- let(:file_one) { "#{spec_dir}/one" }
- let(:file_two) { "#{spec_dir}/two" }
- let(:file_three) { "#{spec_dir}/three" }
- let(:file_four) { 'other/four' }
+ subject { files_list.files }
- 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 ])
+ it { should == [ path_one, path_two, path_three ] }
end
- subject { files_list.filtered_files }
+ 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' }
- context 'empty filter' do
before do
- files_list.stubs(:spec_filter).returns([])
+ 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
- it { should == [ file_one, file_two, file_three, file_four ] }
- end
+ subject { files_list.filtered_files }
- context 'with filter' do
- before do
- files_list.stubs(:spec_filter).returns([ "#{spec_dir}/one", '**/tw*' ])
+ context 'empty filter' do
+ before do
+ files_list.stubs(:spec_filter).returns([])
+ end
+
+ it { should == [ file_one, file_two, file_three, file_four ] }
end
- it { should == [ file_one, file_two, file_four ] }
+ 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
- end
- describe '#add_files' do
- let(:files_list) { described_class.new(:seed => 100) }
+ describe '#add_files' do
+ let(:files_list) { described_class.new(:seed => 100) }
- no_default_files!
+ let(:dir) { 'tmp' }
- let(:dir) { 'tmp' }
+ before do
+ FileUtils.mkdir_p dir
- before do
- FileUtils.mkdir_p dir
+ 10.times do |index|
+ File.open(File.join(dir, "file-#{index}.js"), 'wb')
+ end
- 10.times do |index|
- File.open(File.join(dir, "file-#{index}.js"), 'wb')
+ File.open(File.join(dir, 'file.js.erb'), 'wb')
end
- File.open(File.join(dir, 'file.js.erb'), 'wb')
- end
-
- before do
- files_list.send(:add_files, [ '*' ], 'spec_files', [ dir ])
- 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}
+ 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
+ FileUtils.rm_rf dir
+ end
- it 'should not load an excluded format' do
- files_list.files.any? { |file| file['.erb'] }.should be_false
+ it 'should not load an excluded format' do
+ files_list.files.any? { |file| file['.erb'] }.should be_false
+ end
end
end
end
View
4 spec/lib/jasmine/headless/runner_spec.rb
@@ -167,10 +167,13 @@ def self.it_should_have_basics
let(:only) { 'only' }
let(:seed) { 12345 }
let(:jasmine_config) { 'jasmine config' }
+ let(:reporters) { [] }
before do
runner.stubs(:options).returns(options)
runner.stubs(:jasmine_config).returns(jasmine_config)
+
+ options.stubs(:reporters).returns(reporters)
end
it { should be_a_kind_of(Jasmine::Headless::FilesList) }
@@ -179,6 +182,7 @@ def self.it_should_have_basics
subject.options[:config].should == jasmine_config
subject.options[:only].should == only
subject.options[:seed].should == seed
+ subject.options[:reporters].should == reporters
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.