From c96cbd4aac43abccb5a3dd4d6dc0582f0a131e6b Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 8 Feb 2012 09:07:54 -0500 Subject: [PATCH] move sprockets gem finding to separate gem that enforces rubygems version, implements #116 in a different way --- jasmine-headless-webkit.gemspec | 6 ++- lib/jasmine/headless/files_list.rb | 25 +---------- spec/lib/jasmine/headless/files_list_spec.rb | 44 -------------------- 3 files changed, 6 insertions(+), 69 deletions(-) diff --git a/jasmine-headless-webkit.gemspec b/jasmine-headless-webkit.gemspec index 56d70af..451e58c 100644 --- a/jasmine-headless-webkit.gemspec +++ b/jasmine-headless-webkit.gemspec @@ -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 + diff --git a/lib/jasmine/headless/files_list.rb b/lib/jasmine/headless/files_list.rb index caac47f..5e1acc9 100644 --- a/lib/jasmine/headless/files_list.rb +++ b/lib/jasmine/headless/files_list.rb @@ -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! diff --git a/spec/lib/jasmine/headless/files_list_spec.rb b/spec/lib/jasmine/headless/files_list_spec.rb index bd24076..b0e56a5 100644 --- a/spec/lib/jasmine/headless/files_list_spec.rb +++ b/spec/lib/jasmine/headless/files_list_spec.rb @@ -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)