more clean up work, break things apart for manageability/testing
This commit is contained in:
parent
d31f628d91
commit
d5b2239d0f
1
Gemfile
1
Gemfile
@ -24,5 +24,4 @@ gem 'jquery-rails'
|
||||
gem 'ejs'
|
||||
|
||||
gem 'simplecov'
|
||||
#gem 'perftools.rb'
|
||||
|
||||
|
@ -72,8 +72,6 @@ module Jasmine::Headless
|
||||
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 @@ module Jasmine::Headless
|
||||
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 @@ module Jasmine::Headless
|
||||
'spec_files' => 'spec_dir'
|
||||
}
|
||||
|
||||
def use_config!
|
||||
def use_config
|
||||
@config = @options[:config].dup
|
||||
@searches = {}
|
||||
@potential_files_to_filter = []
|
||||
@ -253,7 +259,7 @@ module Jasmine::Headless
|
||||
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
|
||||
|
@ -103,8 +103,9 @@ module Jasmine
|
||||
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
|
||||
|
||||
|
@ -5,53 +5,6 @@ require 'coffee-script'
|
||||
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,9 +28,50 @@ describe Jasmine::Headless::FilesList do
|
||||
it { should =~ paths }
|
||||
end
|
||||
|
||||
describe '#search_paths' do
|
||||
no_default_files!
|
||||
describe '.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(:@asset_paths, nil)
|
||||
FileUtils.mkdir_p File.join(dir_two, 'vendor/assets/javascripts')
|
||||
|
||||
Gem::Specification.stubs(:_all).returns([gem_one, gem_two])
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
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) { {
|
||||
@ -136,28 +130,6 @@ describe Jasmine::Headless::FilesList do
|
||||
end
|
||||
end
|
||||
|
||||
describe '.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(:@asset_paths, nil)
|
||||
|
||||
FileUtils.mkdir_p File.join(dir_two, 'vendor/assets/javascripts')
|
||||
|
||||
Gem::Specification.stubs(:_all).returns([gem_one, gem_two])
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
describe '#files' do
|
||||
let(:path_one) { 'one' }
|
||||
let(:path_two) { 'two' }
|
||||
@ -220,8 +192,6 @@ describe Jasmine::Headless::FilesList do
|
||||
describe '#add_files' do
|
||||
let(:files_list) { described_class.new(:seed => 100) }
|
||||
|
||||
no_default_files!
|
||||
|
||||
let(:dir) { 'tmp' }
|
||||
|
||||
before do
|
||||
@ -249,4 +219,5 @@ describe Jasmine::Headless::FilesList do
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -167,10 +167,13 @@ describe Jasmine::Headless::Runner do
|
||||
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 @@ describe Jasmine::Headless::Runner do
|
||||
subject.options[:config].should == jasmine_config
|
||||
subject.options[:only].should == only
|
||||
subject.options[:seed].should == seed
|
||||
subject.options[:reporters].should == reporters
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user