a little cleanup work

This commit is contained in:
John Bintz 2011-11-25 16:18:06 -05:00
parent 03a381d3cc
commit 16f867af09
10 changed files with 93 additions and 72 deletions

View File

@ -10,7 +10,9 @@ module Jasmine::Headless
autoload :Runner, 'jasmine/headless/runner'
autoload :Options, 'jasmine/headless/options'
autoload :Task, 'jasmine/headless/task'
autoload :FilesList, 'jasmine/headless/files_list'
autoload :UniqueAssetList, 'jasmine/headless/unique_asset_list'
autoload :TemplateWriter, 'jasmine/headless/template_writer'

View File

@ -13,15 +13,17 @@ module Jasmine::Headless
require 'rubygems'
raise StandardError.new("A newer version of Rubygems is required to use vendored assets. Please upgrade.") if !Gem::Specification.respond_to?(:map)
raise StandardError.new("A newer version of Rubygems is required to use vendored assets. Please upgrade.") if !Gem::Specification.respond_to?(:each)
@vendor_asset_paths = []
Gem::Specification.map { |spec|
Gem::Specification.each do |spec|
path = File.join(spec.gem_dir, 'vendor/assets/javascripts')
File.directory?(path) ? path : nil
}.compact
@vendor_asset_paths << path if File.directory?(path)
end
@vendor_asset_paths
end
def reset!
@ -60,7 +62,7 @@ module Jasmine::Headless
def initialize(options = {})
@options = options
@required_files = []
@required_files = UniqueAssetList.new
@potential_files_to_filter = []
self.class.default_files.each do |file|
@ -71,7 +73,7 @@ module Jasmine::Headless
end
def files
required_files.collect { |file| file.to_a.collect { |asset| asset.pathname.to_s } }.flatten.uniq
required_files.flatten.collect { |asset| asset.pathname.to_s }.uniq
end
def spec_files
@ -88,9 +90,9 @@ module Jasmine::Headless
return @search_paths if @search_paths
@search_paths = [ Jasmine::Core.path ]
@search_paths += self.class.vendor_asset_paths
@search_paths += src_dir.collect { |dir| File.expand_path(dir) }
@search_paths += spec_dir.collect { |dir| File.expand_path(dir) }
@search_paths += self.class.vendor_asset_paths
@search_paths
end
@ -99,9 +101,7 @@ module Jasmine::Headless
return @sprockets_environment if @sprockets_environment
@sprockets_environment = Sprockets::Environment.new
search_paths.each do |path|
@sprockets_environment.append_path(path)
end
search_paths.each { |path| @sprockets_environment.append_path(path) }
@sprockets_environment.unregister_postprocessor('application/javascript', Sprockets::SafetyColons)
@sprockets_environment
@ -111,9 +111,7 @@ module Jasmine::Headless
if is_outside_scope = !spec_filter.empty?
is_outside_scope = spec_dir.any? do |dir|
spec_file_searches.any? do |search|
!spec_files.any? { |file|
File.fnmatch?(File.join(dir, search), file)
}
!spec_files.any? { |file| File.fnmatch?(File.join(dir, search), file) }
end
end
end
@ -156,19 +154,11 @@ module Jasmine::Headless
end
sprockets_environment.find_asset(file, :bundle => false).body
end.flatten.compact.reject(&:empty?)
end.compact.reject(&:empty?)
end
def spec_filter
return @spec_filter if @spec_filter
@spec_filter = begin
if @options[:only]
@options[:only].collect { |path| expanded_dir(path) }.flatten
else
[]
end
end
@spec_filter ||= (@options[:only] && @options[:only].collect { |path| expanded_dir(path) }.flatten) || []
end
SEARCH_ROOTS = {
@ -185,31 +175,15 @@ module Jasmine::Headless
%w{src_files stylesheets helpers spec_files}.each do |type|
if data = @config[type]
dirs = send(SEARCH_ROOTS[type])
add_files(@searches[type] = data.flatten, type, dirs)
add_files(@searches[type] = data.flatten, type, send(SEARCH_ROOTS[type]))
end
end
filtered_required_files = []
@required_files.each do |file|
if !filtered_required_files.any? { |other_file| other_file.logical_path == file.logical_path }
filtered_required_files << file
end
end
@required_files = filtered_required_files
end
def add_files(patterns, type, dirs)
dirs.each do |dir|
patterns.each do |search|
search = File.expand_path(File.join(dir, search))
Dir[search].find_all { |file| file[extension_filter] }.each do |path|
add_path(path, type) if File.file?(path)
end
dirs.product(patterns).each do |search|
Dir[File.join(*search)].find_all { |file| file[extension_filter] }.each do |path|
add_path(path, type) if File.file?(path)
end
end
@ -253,11 +227,7 @@ module Jasmine::Headless
end
def config_dir_or_pwd(dir)
found_dir = Dir.pwd
if @options[:config]
found_dir = @options[:config][dir] || found_dir
end
found_dir = (@options[:config] && @options[:config][dir]) || Dir.pwd
[ found_dir ].flatten.collect { |dir| File.expand_path(dir) }
end

View File

@ -0,0 +1,14 @@
module Jasmine::Headless
class UniqueAssetList < ::Array
def <<(asset)
raise StandardError.new("Not an asset") if !asset.respond_to?(:logical_path)
super if !self.any? { |other| asset.logical_path == other.logical_path }
end
def flatten
self.collect(&:to_a).flatten
end
end
end

View File

@ -138,23 +138,5 @@ describe "jasmine-headless-webkit" do
File.size(runner_path.path).should_not == 0
end
end
describe 'sprockets' do
it 'should pull in the code via sprockets' do
files = %x{bin/jasmine-headless-webkit -l -j spec/jasmine/with_sprockets_includes/with_sprockets_includes.yml}
$?.exitstatus.should == 0
files.lines.to_a.should contain_in_order_in_file_list(
'vendor/assets/javascripts/jquery.js',
'templates/that.jst.ejs',
'templates/this.jst',
'assets/things/required.js',
'assets/things/code.js',
'assets/things/subcode/more_code.js',
'spec_helper.js',
'spec/things/code_spec.js'
)
end
end
end

View File

@ -0,0 +1,19 @@
require 'spec_helper'
describe 'sprockets' do
it 'should pull in the code via sprockets' do
files = %x{bin/jasmine-headless-webkit -l -j spec/jasmine/with_sprockets_includes/with_sprockets_includes.yml}
$?.exitstatus.should == 0
files.lines.to_a.should contain_in_order_in_file_list(
'vendor/assets/javascripts/jquery.js',
'templates/that.jst.ejs',
'templates/this.jst',
'assets/things/required.js',
'assets/things/code.js',
'assets/things/subcode/more_code.js',
'spec_helper.js',
'spec/things/code_spec.js'
)
end
end

View File

@ -5,7 +5,7 @@ spec_files:
- "**/*_spec.js"
src_files:
- "things/**/*"
- "**/*"
helpers:
- "spec_helper.js"

View File

@ -79,7 +79,7 @@ describe Jasmine::Headless::FilesList do
end
it 'should add the vendor gem paths to the list' do
files_list.search_paths.should == [ Jasmine::Core.path, File.expand_path(src_dir), File.expand_path(spec_dir), path ]
files_list.search_paths.should == [ Jasmine::Core.path, path, File.expand_path(src_dir), File.expand_path(spec_dir) ]
end
end
@ -125,12 +125,12 @@ describe Jasmine::Headless::FilesList do
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)) }
let(:asset_two) { stub(:pathname => Pathname(path_two)) }
let(:asset_three) { stub(:pathname => Pathname(path_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([ file_one, file_two ])
files_list.stubs(:required_files).returns(Jasmine::Headless::UniqueAssetList.new([ file_one, file_two ]))
end
subject { files_list.files }

View File

@ -0,0 +1,22 @@
require 'spec_helper'
describe Jasmine::Headless::UniqueAssetList do
let(:list) { described_class.new }
let(:first) { stub(:logical_path => 'one') }
let(:second) { stub(:logical_path => 'two') }
let(:third) { stub(:logical_path => 'two') }
it 'should raise an exception on a non-asset' do
expect { list << "whatever" }.to raise_error(StandardError)
end
it 'should not add the same asset with the same logical path twice' do
list << first
list << second
list << third
list.to_a.should == [ first, second ]
end
end

View File

@ -14,6 +14,18 @@ RSpec.configure do |c|
Jasmine::Headless::CacheableAction.enabled = false
Jasmine::Headless::FilesList.reset!
end
c.before(:each, :type => :integration) do
let(:report) { 'spec/report.txt' }
before do
FileUtils.rm_f report
end
after do
FileUtils.rm_f report
end
end
end
specrunner = 'ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner'