a little cleanup work
This commit is contained in:
parent
03a381d3cc
commit
16f867af09
@ -10,7 +10,9 @@ module Jasmine::Headless
|
|||||||
autoload :Runner, 'jasmine/headless/runner'
|
autoload :Runner, 'jasmine/headless/runner'
|
||||||
autoload :Options, 'jasmine/headless/options'
|
autoload :Options, 'jasmine/headless/options'
|
||||||
autoload :Task, 'jasmine/headless/task'
|
autoload :Task, 'jasmine/headless/task'
|
||||||
|
|
||||||
autoload :FilesList, 'jasmine/headless/files_list'
|
autoload :FilesList, 'jasmine/headless/files_list'
|
||||||
|
autoload :UniqueAssetList, 'jasmine/headless/unique_asset_list'
|
||||||
|
|
||||||
autoload :TemplateWriter, 'jasmine/headless/template_writer'
|
autoload :TemplateWriter, 'jasmine/headless/template_writer'
|
||||||
|
|
||||||
|
@ -13,15 +13,17 @@ module Jasmine::Headless
|
|||||||
|
|
||||||
require 'rubygems'
|
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 = []
|
@vendor_asset_paths = []
|
||||||
|
|
||||||
Gem::Specification.map { |spec|
|
Gem::Specification.each do |spec|
|
||||||
path = File.join(spec.gem_dir, 'vendor/assets/javascripts')
|
path = File.join(spec.gem_dir, 'vendor/assets/javascripts')
|
||||||
|
|
||||||
File.directory?(path) ? path : nil
|
@vendor_asset_paths << path if File.directory?(path)
|
||||||
}.compact
|
end
|
||||||
|
|
||||||
|
@vendor_asset_paths
|
||||||
end
|
end
|
||||||
|
|
||||||
def reset!
|
def reset!
|
||||||
@ -60,7 +62,7 @@ module Jasmine::Headless
|
|||||||
def initialize(options = {})
|
def initialize(options = {})
|
||||||
@options = options
|
@options = options
|
||||||
|
|
||||||
@required_files = []
|
@required_files = UniqueAssetList.new
|
||||||
@potential_files_to_filter = []
|
@potential_files_to_filter = []
|
||||||
|
|
||||||
self.class.default_files.each do |file|
|
self.class.default_files.each do |file|
|
||||||
@ -71,7 +73,7 @@ module Jasmine::Headless
|
|||||||
end
|
end
|
||||||
|
|
||||||
def files
|
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
|
end
|
||||||
|
|
||||||
def spec_files
|
def spec_files
|
||||||
@ -88,9 +90,9 @@ module Jasmine::Headless
|
|||||||
return @search_paths if @search_paths
|
return @search_paths if @search_paths
|
||||||
|
|
||||||
@search_paths = [ Jasmine::Core.path ]
|
@search_paths = [ Jasmine::Core.path ]
|
||||||
|
@search_paths += self.class.vendor_asset_paths
|
||||||
@search_paths += src_dir.collect { |dir| File.expand_path(dir) }
|
@search_paths += src_dir.collect { |dir| File.expand_path(dir) }
|
||||||
@search_paths += spec_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
|
@search_paths
|
||||||
end
|
end
|
||||||
@ -99,9 +101,7 @@ module Jasmine::Headless
|
|||||||
return @sprockets_environment if @sprockets_environment
|
return @sprockets_environment if @sprockets_environment
|
||||||
|
|
||||||
@sprockets_environment = Sprockets::Environment.new
|
@sprockets_environment = Sprockets::Environment.new
|
||||||
search_paths.each do |path|
|
search_paths.each { |path| @sprockets_environment.append_path(path) }
|
||||||
@sprockets_environment.append_path(path)
|
|
||||||
end
|
|
||||||
|
|
||||||
@sprockets_environment.unregister_postprocessor('application/javascript', Sprockets::SafetyColons)
|
@sprockets_environment.unregister_postprocessor('application/javascript', Sprockets::SafetyColons)
|
||||||
@sprockets_environment
|
@sprockets_environment
|
||||||
@ -111,9 +111,7 @@ module Jasmine::Headless
|
|||||||
if is_outside_scope = !spec_filter.empty?
|
if is_outside_scope = !spec_filter.empty?
|
||||||
is_outside_scope = spec_dir.any? do |dir|
|
is_outside_scope = spec_dir.any? do |dir|
|
||||||
spec_file_searches.any? do |search|
|
spec_file_searches.any? do |search|
|
||||||
!spec_files.any? { |file|
|
!spec_files.any? { |file| File.fnmatch?(File.join(dir, search), file) }
|
||||||
File.fnmatch?(File.join(dir, search), file)
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -156,19 +154,11 @@ module Jasmine::Headless
|
|||||||
end
|
end
|
||||||
|
|
||||||
sprockets_environment.find_asset(file, :bundle => false).body
|
sprockets_environment.find_asset(file, :bundle => false).body
|
||||||
end.flatten.compact.reject(&:empty?)
|
end.compact.reject(&:empty?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def spec_filter
|
def spec_filter
|
||||||
return @spec_filter if @spec_filter
|
@spec_filter ||= (@options[:only] && @options[:only].collect { |path| expanded_dir(path) }.flatten) || []
|
||||||
|
|
||||||
@spec_filter = begin
|
|
||||||
if @options[:only]
|
|
||||||
@options[:only].collect { |path| expanded_dir(path) }.flatten
|
|
||||||
else
|
|
||||||
[]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
SEARCH_ROOTS = {
|
SEARCH_ROOTS = {
|
||||||
@ -185,33 +175,17 @@ module Jasmine::Headless
|
|||||||
|
|
||||||
%w{src_files stylesheets helpers spec_files}.each do |type|
|
%w{src_files stylesheets helpers spec_files}.each do |type|
|
||||||
if data = @config[type]
|
if data = @config[type]
|
||||||
dirs = send(SEARCH_ROOTS[type])
|
add_files(@searches[type] = data.flatten, type, send(SEARCH_ROOTS[type]))
|
||||||
|
|
||||||
add_files(@searches[type] = data.flatten, type, dirs)
|
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
def add_files(patterns, type, dirs)
|
def add_files(patterns, type, dirs)
|
||||||
dirs.each do |dir|
|
dirs.product(patterns).each do |search|
|
||||||
patterns.each do |search|
|
Dir[File.join(*search)].find_all { |file| file[extension_filter] }.each do |path|
|
||||||
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)
|
add_path(path, type) if File.file?(path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
if type == 'spec_files'
|
if type == 'spec_files'
|
||||||
spec_filter.each { |path| add_path(path, type) }
|
spec_filter.each { |path| add_path(path, type) }
|
||||||
@ -253,11 +227,7 @@ module Jasmine::Headless
|
|||||||
end
|
end
|
||||||
|
|
||||||
def config_dir_or_pwd(dir)
|
def config_dir_or_pwd(dir)
|
||||||
found_dir = Dir.pwd
|
found_dir = (@options[:config] && @options[:config][dir]) || Dir.pwd
|
||||||
|
|
||||||
if @options[:config]
|
|
||||||
found_dir = @options[:config][dir] || found_dir
|
|
||||||
end
|
|
||||||
|
|
||||||
[ found_dir ].flatten.collect { |dir| File.expand_path(dir) }
|
[ found_dir ].flatten.collect { |dir| File.expand_path(dir) }
|
||||||
end
|
end
|
||||||
|
14
lib/jasmine/headless/unique_asset_list.rb
Normal file
14
lib/jasmine/headless/unique_asset_list.rb
Normal 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
|
||||||
|
|
@ -138,23 +138,5 @@ describe "jasmine-headless-webkit" do
|
|||||||
File.size(runner_path.path).should_not == 0
|
File.size(runner_path.path).should_not == 0
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
|
19
spec/integration/sprockets_spec.rb
Normal file
19
spec/integration/sprockets_spec.rb
Normal 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
|
@ -5,7 +5,7 @@ spec_files:
|
|||||||
- "**/*_spec.js"
|
- "**/*_spec.js"
|
||||||
|
|
||||||
src_files:
|
src_files:
|
||||||
- "things/**/*"
|
- "**/*"
|
||||||
|
|
||||||
helpers:
|
helpers:
|
||||||
- "spec_helper.js"
|
- "spec_helper.js"
|
||||||
|
@ -79,7 +79,7 @@ describe Jasmine::Headless::FilesList do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'should add the vendor gem paths to the list' do
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -125,12 +125,12 @@ describe Jasmine::Headless::FilesList do
|
|||||||
let(:file_one) { stub(:to_a => [ asset_one, asset_two ] ) }
|
let(:file_one) { stub(:to_a => [ asset_one, asset_two ] ) }
|
||||||
let(:file_two) { stub(:to_a => [ asset_two, asset_three ] ) }
|
let(:file_two) { stub(:to_a => [ asset_two, asset_three ] ) }
|
||||||
|
|
||||||
let(:asset_one) { stub(:pathname => Pathname(path_one)) }
|
let(:asset_one) { stub(:pathname => Pathname(path_one), :to_ary => nil) }
|
||||||
let(:asset_two) { stub(:pathname => Pathname(path_two)) }
|
let(:asset_two) { stub(:pathname => Pathname(path_two), :to_ary => nil) }
|
||||||
let(:asset_three) { stub(:pathname => Pathname(path_three)) }
|
let(:asset_three) { stub(:pathname => Pathname(path_three), :to_ary => nil) }
|
||||||
|
|
||||||
before do
|
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
|
end
|
||||||
|
|
||||||
subject { files_list.files }
|
subject { files_list.files }
|
||||||
|
22
spec/lib/jasmine/headless/unique_asset_list_spec.rb
Normal file
22
spec/lib/jasmine/headless/unique_asset_list_spec.rb
Normal 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
|
||||||
|
|
@ -14,6 +14,18 @@ RSpec.configure do |c|
|
|||||||
Jasmine::Headless::CacheableAction.enabled = false
|
Jasmine::Headless::CacheableAction.enabled = false
|
||||||
Jasmine::Headless::FilesList.reset!
|
Jasmine::Headless::FilesList.reset!
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
specrunner = 'ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner'
|
specrunner = 'ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner'
|
||||||
|
Loading…
Reference in New Issue
Block a user