From 2e2651d11a86a580b31150c11d609e770e0529e6 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 21 Feb 2012 09:04:00 -0500 Subject: [PATCH] may fix #119, file paths on windows --- lib/jasmine/headless/cacheable_action.rb | 6 ++++- .../jasmine/headless/cacheable_action_spec.rb | 23 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/jasmine/headless/cacheable_action.rb b/lib/jasmine/headless/cacheable_action.rb index 84e946f..ee29ffb 100644 --- a/lib/jasmine/headless/cacheable_action.rb +++ b/lib/jasmine/headless/cacheable_action.rb @@ -54,7 +54,11 @@ module Jasmine::Headless end def cache_file - @cache_file ||= File.expand_path(File.join(self.class.cache_dir, self.class.cache_type, file)) + '.js' + @cache_file ||= File.expand_path(relative_cache_file) + '.js' + end + + def relative_cache_file + File.join(self.class.cache_dir, self.class.cache_type, file.gsub(Dir.pwd + '/', '')) end def fresh? diff --git a/spec/lib/jasmine/headless/cacheable_action_spec.rb b/spec/lib/jasmine/headless/cacheable_action_spec.rb index 72b0281..b1d2d48 100644 --- a/spec/lib/jasmine/headless/cacheable_action_spec.rb +++ b/spec/lib/jasmine/headless/cacheable_action_spec.rb @@ -95,5 +95,28 @@ describe Jasmine::Headless::CacheableAction do end end end + + describe '#relative_cache_file' do + context 'file is an absolute windows file' do + let(:current_path) { 'C:/path' } + let(:filename) { "file.coffee" } + let(:windows_path) { File.join(current_path, filename) } + let(:cache_dir) { 'cache dir' } + let(:cache_type) { 'cache type' } + + before do + cache_object.stubs(:file).returns(windows_path) + + described_class.stubs(:cache_dir).returns(cache_dir) + described_class.stubs(:cache_type).returns(cache_type) + + Dir.stubs(:pwd).returns(current_path) + end + + subject { cache_object.relative_cache_file } + + it { should == File.join(cache_dir, cache_type, filename) } + end + end end