Commit 266f42e1 authored by Eloy Durán's avatar Eloy Durán Committed by Samuel E. Giddins

[Analyzer] Cleanup and improve tests for lockfile checkout options.

parent d1d7fd8c
......@@ -64,9 +64,13 @@ module Pod
# @return [Lockfile] the manifest which contains the information about the
# installed pods.
#
attr_accessor :manifest
def manifest
@manifest ||= begin
Lockfile.from_file(manifest_path) if manifest_path.exist?
end
end
# @return [Project] the Pods project.
#
......
......@@ -26,7 +26,9 @@ require 'bacon'
require 'mocha-on-bacon'
require 'pretty_bacon'
require 'pathname'
require 'active_support/core_ext/string/strip'
require 'active_support/core_ext/object/deep_dup'
ROOT = Pathname.new(File.expand_path('../../', __FILE__))
$:.unshift((ROOT + 'lib').to_s)
......
require File.expand_path('../../../spec_helper', __FILE__)
# @return [Analyzer] the sample analyzer.
#
def create_analyzer
#-----------------------------------------------------------------------------#
module Pod
describe Installer::Analyzer do
describe 'Analysis' do
before do
@podfile = Pod::Podfile.new do
platform :ios, '6.0'
xcodeproj 'SampleProject/SampleProject'
......@@ -17,23 +21,12 @@ def create_analyzer
hash['DEPENDENCIES'] = %w(JSONKit NUI SVPullToRefresh)
hash['SPEC CHECKSUMS'] = {}
hash['COCOAPODS'] = Pod::VERSION
lockfile = Pod::Lockfile.new(hash)
@lockfile = Pod::Lockfile.new(hash)
SpecHelper.create_sample_app_copy_from_fixture('SampleProject')
analyzer = Pod::Installer::Analyzer.new(config.sandbox, @podfile, lockfile)
end
#-----------------------------------------------------------------------------#
module Pod
describe Installer::Analyzer do
before do
@analyzer = create_analyzer
@analyzer = Pod::Installer::Analyzer.new(config.sandbox, @podfile, @lockfile)
end
describe 'Analysis' do
it 'returns whether an installation should be performed' do
@analyzer.needs_install?.should.be.true
end
......@@ -185,57 +178,6 @@ module Pod
@analyzer.send(:fetch_external_sources)
end
it 'raises when dependencies with the same name have different ' \
'external sources' do
podfile = Podfile.new do
source 'https://github.com/CocoaPods/Specs.git'
xcodeproj 'SampleProject/SampleProject'
platform :ios
pod 'SEGModules', :git => 'https://github.com/segiddins/SEGModules.git'
pod 'SEGModules', :git => 'https://github.com/segiddins/Modules.git'
end
analyzer = Pod::Installer::Analyzer.new(config.sandbox, podfile, nil)
e = should.raise(Informative) { analyzer.analyze }
e.message.should.match /different sources for `SEGModules`/
e.message.should.match %r{SEGModules \(from `https://github.com/segiddins/SEGModules.git`\)}
e.message.should.match %r{SEGModules \(from `https://github.com/segiddins/Modules.git`\)}
end
it 'raises when dependencies with the same root name have different ' \
'external sources' do
podfile = Podfile.new do
source 'https://github.com/CocoaPods/Specs.git'
xcodeproj 'SampleProject/SampleProject'
platform :ios
pod 'RestKit/Core', :git => 'https://github.com/RestKit/RestKit.git'
pod 'RestKit', :git => 'https://github.com/segiddins/RestKit.git'
end
analyzer = Pod::Installer::Analyzer.new(config.sandbox, podfile, nil)
e = should.raise(Informative) { analyzer.analyze }
e.message.should.match /different sources for `RestKit`/
e.message.should.match %r{RestKit/Core \(from `https://github.com/RestKit/RestKit.git`\)}
e.message.should.match %r{RestKit \(from `https://github.com/segiddins/RestKit.git`\)}
end
it 'raises when dependencies with the same name have different ' \
'external sources with one being nil' do
podfile = Podfile.new do
source 'https://github.com/CocoaPods/Specs.git'
xcodeproj 'SampleProject/SampleProject'
platform :ios
pod 'RestKit', :git => 'https://github.com/RestKit/RestKit.git'
pod 'RestKit', '~> 0.23.0'
end
analyzer = Pod::Installer::Analyzer.new(config.sandbox, podfile, nil)
e = should.raise(Informative) { analyzer.analyze }
e.message.should.match /different sources for `RestKit`/
e.message.should.match %r{RestKit \(from `https://github.com/RestKit/RestKit.git`\)}
e.message.should.match %r{RestKit \(~> 0.23.0\)}
end
xit 'it fetches the specification from either the sandbox or from the remote be default' do
dependency = Dependency.new('Name', :git => 'www.example.com')
ExternalSources::DownloaderSource.any_instance.expects(:specification_from_external).returns(Specification.new).once
......@@ -311,8 +253,6 @@ module Pod
state.added.sort.should == %w(AFNetworking JSONKit SVPullToRefresh libextobjc)
end
end
#-------------------------------------------------------------------------#
describe 'Private helpers' do
......@@ -609,4 +549,141 @@ module Pod
end
end
end
describe 'Analysis, concerning naming' do
before do
SpecHelper.create_sample_app_copy_from_fixture('SampleProject')
end
it 'raises when dependencies with the same name have different ' \
'external sources' do
podfile = Podfile.new do
source 'https://github.com/CocoaPods/Specs.git'
xcodeproj 'SampleProject/SampleProject'
platform :ios
pod 'SEGModules', :git => 'https://github.com/segiddins/SEGModules.git'
pod 'SEGModules', :git => 'https://github.com/segiddins/Modules.git'
end
analyzer = Pod::Installer::Analyzer.new(config.sandbox, podfile, nil)
e = should.raise(Informative) { analyzer.analyze }
e.message.should.match /different sources for `SEGModules`/
e.message.should.match %r{SEGModules \(from `https://github.com/segiddins/SEGModules.git`\)}
e.message.should.match %r{SEGModules \(from `https://github.com/segiddins/Modules.git`\)}
end
it 'raises when dependencies with the same root name have different ' \
'external sources' do
podfile = Podfile.new do
source 'https://github.com/CocoaPods/Specs.git'
xcodeproj 'SampleProject/SampleProject'
platform :ios
pod 'RestKit/Core', :git => 'https://github.com/RestKit/RestKit.git'
pod 'RestKit', :git => 'https://github.com/segiddins/RestKit.git'
end
analyzer = Pod::Installer::Analyzer.new(config.sandbox, podfile, nil)
e = should.raise(Informative) { analyzer.analyze }
e.message.should.match /different sources for `RestKit`/
e.message.should.match %r{RestKit/Core \(from `https://github.com/RestKit/RestKit.git`\)}
e.message.should.match %r{RestKit \(from `https://github.com/segiddins/RestKit.git`\)}
end
it 'raises when dependencies with the same name have different ' \
'external sources with one being nil' do
podfile = Podfile.new do
source 'https://github.com/CocoaPods/Specs.git'
xcodeproj 'SampleProject/SampleProject'
platform :ios
pod 'RestKit', :git => 'https://github.com/RestKit/RestKit.git'
pod 'RestKit', '~> 0.23.0'
end
analyzer = Pod::Installer::Analyzer.new(config.sandbox, podfile, nil)
e = should.raise(Informative) { analyzer.analyze }
e.message.should.match /different sources for `RestKit`/
e.message.should.match %r{RestKit \(from `https://github.com/RestKit/RestKit.git`\)}
e.message.should.match %r{RestKit \(~> 0.23.0\)}
end
end
describe 'using lockfile checkout options' do
before do
@podfile = Pod::Podfile.new do
pod 'BananaLib', :git => 'example.com'
end
@dependency = @podfile.dependencies.first
@lockfile_checkout_options = { :git => 'example.com', :commit => 'commit' }
hash = {}
hash['PODS'] = ['BananaLib (1.0.0)']
hash['CHECKOUT OPTIONS'] = { 'BananaLib' => @lockfile_checkout_options }
hash['SPEC CHECKSUMS'] = {}
hash['COCOAPODS'] = Pod::VERSION
@lockfile = Pod::Lockfile.new(hash)
@analyzer = Pod::Installer::Analyzer.new(config.sandbox, @podfile, @lockfile)
end
it 'returns that an update is required when there is no sandbox manifest' do
@analyzer.sandbox.stubs(:manifest).returns(nil)
@analyzer.should.send(:checkout_requires_update?, @dependency)
end
before do
@sandbox_manifest = Pod::Lockfile.new(@lockfile.internal_data.deep_dup)
@analyzer.sandbox.manifest = @sandbox_manifest
end
it 'returns whether or not an update is required' do
@analyzer.send(:checkout_requires_update?, @dependency).should == false
@sandbox_manifest.send(:checkout_options_data).delete('BananaLib')
@analyzer.send(:checkout_requires_update?, @dependency).should == true
end
before do
@analyzer.result = Installer::Analyzer::AnalysisResult.new
@analyzer.result.podfile_state = Installer::Analyzer::SpecsState.new
end
it 'uses lockfile checkout options when no source exists in the sandbox' do
@analyzer.result.podfile_state.unchanged << 'BananaLib'
@sandbox_manifest.send(:checkout_options_data).delete('BananaLib')
downloader = stub('DownloaderSource')
ExternalSources.stubs(:from_params).with(@lockfile_checkout_options, @dependency, @podfile.defined_in_file).returns(downloader)
downloader.expects(:fetch)
@analyzer.send(:fetch_external_sources)
end
it 'uses lockfile checkout options when a different checkout exists in the sandbox' do
@analyzer.result.podfile_state.unchanged << 'BananaLib'
@sandbox_manifest.send(:checkout_options_data)['BananaLib'] = @lockfile_checkout_options.merge(:commit => 'other commit')
downloader = stub('DownloaderSource')
ExternalSources.stubs(:from_params).with(@lockfile_checkout_options, @dependency, @podfile.defined_in_file).returns(downloader)
downloader.expects(:fetch)
@analyzer.send(:fetch_external_sources)
end
it 'ignores lockfile checkout options when the podfile state has changed' do
@analyzer.result.podfile_state.changed << 'BananaLib'
downloader = stub('DownloaderSource')
ExternalSources.stubs(:from_params).with(@dependency.external_source, @dependency, @podfile.defined_in_file).returns(downloader)
downloader.expects(:fetch)
@analyzer.send(:fetch_external_sources)
end
it 'does not re-fetch the external source when the sandbox has the correct revision of the source' do
@analyzer.result.podfile_state.unchanged << 'BananaLib'
@analyzer.expects(:fetch_external_source).never
@analyzer.send(:fetch_external_sources)
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