move sprockets gem finding to separate gem that enforces rubygems version, implements #116 in a different way

This commit is contained in:
John Bintz 2012-02-08 09:07:54 -05:00
parent 4f11cba073
commit c96cbd4aac
3 changed files with 6 additions and 69 deletions

View File

@ -20,9 +20,11 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
s.add_runtime_dependency 'jasmine-core', '~> 1.1'
s.add_runtime_dependency 'jasmine-core'
s.add_runtime_dependency 'coffee-script'
s.add_runtime_dependency 'rainbow'
s.add_runtime_dependency 'multi_json'
s.add_runtime_dependency 'sprockets', '>= 2'
s.add_runtime_dependency 'sprockets'
s.add_runtime_dependency 'sprockets-vendor_gems'
end

View File

@ -4,6 +4,7 @@ require 'multi_json'
require 'set'
require 'sprockets'
require 'sprockets/engines'
require 'sprockets-vendor_gems'
module Jasmine::Headless
class FilesList
@ -11,29 +12,7 @@ module Jasmine::Headless
class << self
def asset_paths
return @asset_paths if @asset_paths
require 'rubygems'
raise StandardError.new("A newer version of Rubygems is required to use vendored assets. Please upgrade.") if !Gem::Specification.respond_to?(:each)
@asset_paths = []
Gem::Specification.each { |gemspec| @asset_paths += get_paths_from_gemspec(gemspec) }
@asset_paths
end
def get_paths_from_gemspec(gemspec)
%w{vendor lib app}.collect do |dir|
path = File.join(gemspec.gem_dir, dir, "assets/javascripts")
if File.directory?(path) && !@asset_paths.include?(path)
path
else
nil
end
end.compact
@asset_paths ||= Sprockets.find_gem_vendor_paths(:for => 'javascripts')
end
def reset!

View File

@ -5,50 +5,6 @@ require 'coffee-script'
describe Jasmine::Headless::FilesList do
let(:files_list) { described_class.new }
describe '.get_paths_from_gemspec' do
include FakeFS::SpecHelpers
let(:gem_dir) { "dir" }
let(:gemspec) { stub(:gem_dir => gem_dir) }
let(:paths) do
%w{vendor lib app}.collect do |dir|
File.join(gem_dir, dir, 'assets/javascripts')
end
end
before do
paths.each { |path| FileUtils.mkdir_p path }
described_class.instance_variable_set(:@asset_paths, [])
end
subject { described_class.get_paths_from_gemspec(gemspec) }
it { should =~ paths }
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 '#initialize' do
before do
described_class.any_instance.stubs(:load_initial_assets)