Commit d6b73121 authored by Samuel E. Giddins's avatar Samuel E. Giddins

[Downloader::Cache] Add specs for cached downloads

parent dcc87e5e
......@@ -7,6 +7,7 @@ module Pod
@spec = fixture_spec('banana-lib/BananaLib.podspec')
@spec.source = { :git => SpecHelper.fixture('banana-lib') }
@request = Downloader::Request.new(:spec => @spec, :released => true)
@unreleased_request = Downloader::Request.new(:name => 'BananaLib', :params => @spec.source)
@stub_download = lambda do |cache, &blk|
cache.define_singleton_method(:download) do |name, target, params, head|
FileUtils.mkdir_p target
......@@ -15,6 +16,10 @@ module Pod
end
end
after do
@cache.root.rmtree
end
it 'returns the root' do
@cache.root.should.be.directory?
end
......@@ -31,7 +36,6 @@ module Pod
describe 'when downloading an un-released pod' do
before do
@request = Downloader::Request.new(:name => 'BananaLib', :params => @spec.source)
@stub_download.call @cache do
File.open('BananaLib.podspec.json', 'w') { |f| f << @spec.to_pretty_json }
File.open('OrangeLib.podspec.json', 'w') { |f| f << @spec.to_pretty_json.sub(/"name": "BananaLib"/, '"name": "OrangeLib"') }
......@@ -41,18 +45,45 @@ module Pod
it 'downloads the source' do
@cache.expects(:copy_and_clean).twice
response = @cache.download_pod(@request)
response.should == Downloader::Response.new(@cache.root + @request.slug, @spec, @spec.source)
response = @cache.download_pod(@unreleased_request)
response.should == Downloader::Response.new(@cache.root + @unreleased_request.slug, @spec, @spec.source)
end
end
end
describe 'when the download is cached' do
before do
[@request, @unreleased_request].each do |request|
path_for_spec = @cache.send(:path_for_spec, request)
path_for_spec.dirname.mkpath
path_for_spec.open('w') { |f| f << @spec.to_pretty_json }
end
path_for_pod = @cache.send(:path_for_pod, request)
path_for_pod.mkpath
Dir.chdir(path_for_pod) do
FileUtils.mkdir_p 'Classes'
File.open('Classes/a.m', 'w') { }
end
end
end
after do
@cache.root.rmtree
describe 'when downloading a released pod' do
it 'does not download the source' do
Downloader::Git.any_instance.expects(:download).never
@cache.expects(:uncached_pod).never
response = @cache.download_pod(@request)
response.should == Downloader::Response.new(@cache.root + @request.slug, @spec, @spec.source)
end
end
describe 'when downloading an unreleased pod' do
it 'does not download the source' do
Downloader::Git.any_instance.expects(:download).never
@cache.expects(:uncached_pod).never
response = @cache.download_pod(@unreleased_request)
response.should == Downloader::Response.new(@cache.root + @unreleased_request.slug, @spec, @spec.source)
end
end
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment