Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Break asset pipeline manifest files into src

  • Loading branch information...
commit 0795ad4f5334ea030318e3657aa8e93a0aeccfa9 1 parent c5d39ff
Rajan Agaskar ragaskar authored
3  lib/jasmine.rb
View
@@ -6,7 +6,8 @@
'selenium_driver',
'spec_builder',
'command_line_tool',
- 'page']
+ 'page',
+ 'asset_pipeline_mapper']
jasmine_files.each do |file|
require File.join('jasmine', file)
20 lib/jasmine/asset_pipeline_mapper.rb
View
@@ -0,0 +1,20 @@
+class Jasmine::AssetPipelineMapper
+
+ def self.context
+ context = ::Rails.application.assets.context_class
+ context.extend(::Sprockets::Helpers::IsolatedHelper)
+ context.extend(::Sprockets::Helpers::RailsHelper)
+ end
+
+ def initialize(src_files, context = Jasmine::AssetPipelineMapper.context)
+ @src_files = src_files
+ @context = context
+ end
+
+ def files
+ @src_files.map do |src_file|
+ filename = src_file.gsub(/^assets\//, '').gsub(/\.js$/, '')
+ @context.asset_paths.asset_for(filename, 'js').to_a.map { |p| @context.asset_path(p).gsub(/^\//, '') + "?body=true" }
+ end.flatten.uniq
+ end
+end
4 lib/jasmine/config.rb
View
@@ -75,7 +75,9 @@ def helpers
end
def src_files
- if simple_config['src_files']
+ if simple_config['src_files'] && Jasmine::Dependencies.rails_3_asset_pipeline?
+ Jasmine::AssetPipelineMapper.new(simple_config['src_files']).files
+ elsif simple_config['src_files']
match_files(src_dir, simple_config['src_files'])
else
[]
18 spec/asset_pipeline_mapper_spec.rb
View
@@ -0,0 +1,18 @@
+require 'spec_helper'
+
+describe Jasmine::AssetPipelineMapper do
+ describe "mapping files" do
+ it "should retrieve asset paths from the asset pipeline for passed files" do
+ #TODO: this expects all src files to be asset pipeline files
+ src_files = ["assets/application.js", "assets/other_manifest.js"]
+ asset_context = double("asset context")
+ asset_context.stub_chain(:asset_paths, :asset_for).with("application", "js").and_return(['asset1.js', 'asset2.js'])
+ asset_context.stub_chain(:asset_paths, :asset_for).with("other_manifest", "js").and_return(['asset1.js', 'asset3.js'])
+ asset_context.stub(:asset_path) do |asset|
+ "/some_location/#{asset}"
+ end
+ mapper = Jasmine::AssetPipelineMapper.new(src_files, asset_context)
+ mapper.files.should == ['some_location/asset1.js?body=true', 'some_location/asset2.js?body=true', 'some_location/asset3.js?body=true']
+ end
+ end
+end
25 spec/config_spec.rb
View
@@ -4,6 +4,8 @@
describe Jasmine::Config do
describe "configuration" do
before :each do
+ Jasmine::Dependencies.stub(:rails_3_asset_pipeline?) { false }
+
temp_dir_before
Dir::chdir @tmp
@@ -254,4 +256,27 @@
Jasmine::Config.new.jasmine_javascripts.should == ["/__JASMINE_ROOT__/my_js_file1.js", "/__JASMINE_ROOT__/my_js_file2.js"]
end
end
+
+ describe "when the asset pipeline is active" do
+ before do
+ Jasmine::Dependencies.stub(:rails_3_asset_pipeline?) { true }
+ end
+ let(:src_files) { ["assets/some.js", "assets/files.js"] }
+ let(:config) do
+ Jasmine::Config.new.tap do |config|
+ #TODO: simple_config should be a passed in hash
+ config.stub(:simple_config) { { 'src_files' => src_files} }
+ end
+ end
+ it "should use AssetPipelineMapper to return src_files" do
+ mapped_files = ["some.js", "files.js"]
+ Jasmine::AssetPipelineMapper.stub_chain(:new, :files).and_return(mapped_files)
+ config.src_files.should == mapped_files
+ end
+ it "should pass the config src_files to the AssetPipelineMapper" do
+ Jasmine::Config.stub(:simple_config)
+ Jasmine::AssetPipelineMapper.should_receive(:new).with(src_files) { double("mapper").as_null_object }
+ config.src_files
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.