Commit d1ef7c73 authored by Fabio Pelosin's avatar Fabio Pelosin

[Specs] Fix for master repo update & small performance improvements.

parent dc84ad04
......@@ -82,7 +82,7 @@ module Pod
lint_argv = ["lint"]
lint_argv << "--only-errors" if @allow_warnings
lint_argv << "--silent" if config.silent
all_valid = true
# all_valid = true
podspec_files.each do |podspec|
Spec.new(ARGV.new(lint_argv + [podspec.to_s])).run
end
......
......@@ -153,6 +153,8 @@ module Pod
is_compatilbe(versions)
end
#--------------------------------------#
private
def versions(dir)
......
......@@ -8,7 +8,6 @@ Pod::Spec.new do |s|
s.source = { :git => 'http://banana-corp.local/banana-lib.git', :tag => 'v1.0' }
s.source_files = 'Classes/*.{h,m}', 'Vendor'
s.xcconfig = { 'OTHER_LDFLAGS' => '-framework SystemConfiguration' }
s.clean_paths = "sub-dir"
s.prefix_header_file = 'Classes/BananaLib.pch'
s.resources = "Resources/*.png"
s.dependency 'monkey', '~> 1.0.1', '< 1.0.9'
......
......@@ -2,41 +2,36 @@ require File.expand_path('../../../spec_helper', __FILE__)
describe "Pod::Command::List" do
extend SpecHelper::TemporaryRepos
extend SpecHelper::TemporaryDirectory
def command(arguments = argv)
command = Pod::Command::List.new(arguments)
end
it "complains for wrong parameters" do
lambda { command(argv('wrong')).run }.should.raise Pod::Command::Help
lambda { command(argv('--wrong')).run }.should.raise Pod::Command::Help
before do
set_up_test_repo
config.repos_dir = SpecHelper.tmp_repos_path
end
it "presents the known pods" do
list = command()
list.run
[ /ZBarSDK/,
/TouchJSON/,
/SDURLCache/,
/MagicalRecord/,
/A2DynamicDelegate/,
command.run
Pod::UI.output
[ /BananaLib/,
/JSONKit/,
/\d+ pods were found/
].each { |regex| Pod::UI.output.should =~ regex }
end
it "returns the new pods" do
Time.stubs(:now).returns(Time.mktime(2012,2,3))
list = command(argv('new'))
list.run
[ 'iCarousel',
'libPusher',
'SSCheckBoxView',
'KKPasscodeLock',
'SOCKit',
'FileMD5Hash',
'cocoa-oauth',
'iRate'
].each {|s| Pod::UI.output.should.include s }
sets = Pod::Source.all_sets
jsonkit_set = sets.find { |s| s.name == 'JSONKit' }
dates = {
'BananaLib' => Time.now,
'JSONKit' => Time.parse('01/01/1970') }
Pod::Specification::Statistics.any_instance.stubs(:creation_dates).returns(dates)
command(argv('new')).run
Pod::UI.output.should.include('BananaLib')
Pod::UI.output.should.not.include('JSONKit')
end
end
......
......@@ -9,43 +9,38 @@ describe Pod::Command::Push do
config.repos_dir = SpecHelper.tmp_repos_path
end
def master_repo
fixture('spec-repos/master')
end
it "complains for wrong parameters" do
lambda { run_command('push') }.should.raise Pod::Command::Help
lambda { run_command('push', '--allow-warnings') }.should.raise Pod::Command::Help
lambda { run_command('push', '--wrong-option') }.should.raise Pod::Command::Help
end
it "complains if it can't find the repo" do
repo1 = add_repo('repo1', master_repo)
Dir.chdir(fixture('banana-lib')) do
lambda { run_command('push', 'repo2') }.should.raise Pod::Informative
cmd = command('push', 'missing_repo')
cmd.expects(:validate_podspec_files).returns(true)
e = lambda { cmd.run }.should.raise Pod::Informative
e.message.should.match(/repo not found/)
end
end
it "complains if it can't find a spec" do
repo1 = add_repo('repo1', master_repo)
lambda { run_command('push', 'repo1') }.should.raise Pod::Informative
repo_make('test_repo')
e = lambda { run_command('push', 'test_repo') }.should.raise Pod::Informative
e.message.should.match(/Couldn't find any .podspec/)
end
it "it raises if the pod is not validated" do
repo1 = add_repo('repo1', master_repo)
repo2 = add_repo('repo2', repo1.dir)
git_config('repo2', 'remote.origin.url').should == (tmp_repos_path + 'repo1').to_s
Dir.chdir(fixture('banana-lib')) do
lambda { command('push', 'repo2', '--silent').run }.should.raise Pod::Informative
# TODO: the validation should not use the pod spec command
xit "it raises if the specification doesn't validates" do
repo_make('test_repo')
Dir.chdir(temporary_directory) do
spec = "Spec.new do |s|; s.name = 'Broken'; end"
File.open('Broken.podspec', 'w') {|f| f.write(spec) }
cmd = command('push', 'test_repo')
cmd.expects(:validate_podspec_files).returns(true)
e = lambda { cmd.run }.should.raise Pod::Informative
e.message.should.match(/repo not clean/)
end
# (repo1.dir + 'BananaLib/1.0/BananaLib.podspec').read.should.include 'Added!'
end
before do
# prepare the repos
@upstream = add_repo('upstream', master_repo)
@local_repo = add_repo('local_repo', @upstream.dir)
git_config('local_repo', 'remote.origin.url').should == (tmp_repos_path + 'upstream').to_s
repo_make('upstream')
repo_clone('upstream', 'local_repo')
# prepare the spec
spec = (fixture('spec-repos') + 'master/JSONKit/1.4/JSONKit.podspec').read
......@@ -56,25 +51,28 @@ describe Pod::Command::Push do
end
it "refuses to push if the repo is not clean" do
File.open(@local_repo.dir + 'README', 'w') {|f| f.write('Added!') }
(@local_repo.dir + 'README').read.should.include 'Added!'
repo_make_readme_change('local_repo', 'dirty')
Dir.chdir(temporary_directory) do
cmd = command('push', 'local_repo')
cmd.expects(:validate_podspec_files).returns(true)
Dir.chdir(temporary_directory) { lambda { cmd.run }.should.raise Pod::Informative }
(@upstream.dir + 'PushTest/1.4/PushTest.podspec').should.not.exist?
e = lambda { cmd.run }.should.raise Pod::Informative
e.message.should.match(/repo not clean/)
end
(repo_path('upstream') + 'PushTest/1.4/PushTest.podspec').should.not.exist?
end
it "sucessfully pushes a spec" do
git('upstream', 'checkout master') # checkout master, to allow push in a non-bare repository
cmd = command('push', 'local_repo')
Dir.chdir(repo_path 'upstream') { `git checkout -b tmp_for_push -q` }
cmd.expects(:validate_podspec_files).returns(true)
Dir.chdir(temporary_directory) { cmd.run }
Pod::UI.output.should.include('[Add] PushTest (1.4)')
Pod::UI.output.should.include('[Fix] JSONKit (1.4)')
Pod::UI.output.should.include('[Add] JSONKit (1.4)')
# TODO check the commit messages
# Pod::UI.output.should.include('[Fix] JSONKit (1.4)')
git('upstream', 'checkout test') # checkout because test because is it the branch used in the specs.
(@upstream.dir + 'PushTest/1.4/PushTest.podspec').read.should.include('PushTest')
Dir.chdir(repo_path 'upstream') { `git checkout master -q` }
(repo_path('upstream') + 'PushTest/1.4/PushTest.podspec').read.should.include('PushTest')
end
end
require File.expand_path('../../../spec_helper', __FILE__)
describe "Pod::Command::Repo" do
module Pod
describe Command::Repo do
describe "In general" do
extend SpecHelper::Command
extend SpecHelper::TemporaryDirectory
extend SpecHelper::TemporaryRepos
before do
set_up_test_repo
config.repos_dir = SpecHelper.tmp_repos_path
end
describe "In general" do
extend SpecHelper::Command
extend SpecHelper::TemporaryDirectory
extend SpecHelper::TemporaryRepos
it "updates a repository" do
upstream = SpecHelper.temporary_directory + 'upstream'
FileUtils.cp_r(test_repo_path, upstream)
Dir.chdir(test_repo_path) do
`git remote add origin #{upstream}`
`git remote -v`
`git fetch -q`
`git branch --set-upstream master origin/master`
end
lambda { command('repo', 'update').run }.should.not.raise
end
it "runs with correct parameters" do
lambda { run_command('repo', 'update') }.should.not.raise
it "lints a repository" do
lambda { run_command('repo', 'lint', temporary_directory.to_s) }.should.not.raise
end
it "complains for wrong parameters" do
lambda { run_command('repo', 'add') }.should.raise Pod::Informative
lambda { run_command('repo', 'add', 'NAME') }.should.raise Pod::Informative
lambda { run_command('repo', 'add') }.should.raise Informative
lambda { run_command('repo', 'add', 'NAME') }.should.raise Informative
end
it "adds a spec-repo" do
run_command('repo', 'add', 'private', fixture('spec-repos/master'))
git_config('private', 'remote.origin.url').should == fixture('spec-repos/master').to_s
run_command('repo', 'add', 'private', test_repo_path)
Dir.chdir(config.repos_dir + 'private') do
`git config --get remote.origin.url`.chomp.should == test_repo_path.to_s
end
end
it "adds a spec-repo with on a specified branch" do
repo1 = add_repo('repo1', fixture('spec-repos/master'))
Dir.chdir(repo1.dir) do
it "adds a spec-repo with a specified branch" do
repo1 = repo_make('repo1')
Dir.chdir(repo1) do
`git checkout -b my-branch >/dev/null 2>&1`
`git checkout master >/dev/null 2>&1`
end
repo2 = command( 'repo' ,'add', 'repo2', repo1.dir, 'my-branch')
repo2 = command( 'repo' ,'add', 'repo2', repo1.to_s, 'my-branch')
repo2.run
Dir.chdir(repo2.dir) { `git symbolic-ref HEAD` }.should.include? 'my-branch'
end
it "updates a spec-repo" do
repo1 = add_repo('repo1', fixture('spec-repos/master'))
repo2 = add_repo('repo2', repo1.dir)
make_change(repo1, 'repo1')
repo1 = repo_make('repo1')
repo2 = repo_clone('repo1', 'repo2')
repo_make_readme_change(repo1, 'Updated')
Dir.chdir(repo1) {`git commit -a -m "Update"`}
run_command('repo', 'update', 'repo2')
(repo2.dir + 'README').read.should.include 'Added!'
end
it "updates all the spec-repos" do
repo1 = add_repo('repo1', fixture('spec-repos/master'))
repo2 = add_repo('repo2', repo1.dir)
repo3 = add_repo('repo3', repo1.dir)
make_change(repo1, 'repo1')
run_command('repo', 'update')
(repo2.dir + 'README').read.should.include 'Added!'
(repo3.dir + 'README').read.should.include 'Added!'
end
before do
config.repos_dir = fixture('spec-repos')
end
it "lints a repo" do
cmd = command('repo', 'lint', 'master')
lambda { cmd.run }.should.raise Pod::Informative
Pod::UI.output.should.include "Missing license type"
(repo2 + 'README').read.should.include 'Updated'
end
end
describe "Concerning a repo support" do
describe "CocoaPods version" do
extend SpecHelper::Command
extend SpecHelper::TemporaryDirectory
extend SpecHelper::TemporaryRepos
before do
add_repo('repo1', fixture('spec-repos/master'))
FileUtils.rm_rf(versions_file)
versions_file.should.not.exist?
end
require 'yaml'
def versions_file
tmp_repos_path + "repo1/CocoaPods-version.yml"
before do
config.repos_dir = SpecHelper.tmp_repos_path
@repo = repo_make('repo1')
end
def write_version_file(hash)
yaml = YAML.dump(hash)
File.open(versions_file, 'w') {|f| f.write(yaml) }
@versions_file = tmp_repos_path + "repo1/CocoaPods-version.yml"
File.open(@versions_file, 'w') {|f| f.write(yaml) }
end
it "it doesn't requires CocoaPods-version.yml" do
cmd = command('repo', 'update')
lambda { cmd.check_versions(versions_file.dirname) }.should.not.raise
lambda { cmd.check_versions(@repo) }.should.not.raise
end
it "runs with a compatible repo" do
write_version_file({'min' => "0.0.1"})
cmd = command('repo', 'update')
lambda { cmd.check_versions(versions_file.dirname) }.should.not.raise
lambda { cmd.check_versions(@repo) }.should.not.raise
end
it "raises if a repo is not compatible" do
write_version_file({'min' => "999.0.0"})
cmd = command('repo', 'update')
lambda { cmd.check_versions(versions_file.dirname) }.should.raise Pod::Informative
lambda { cmd.check_versions(@repo) }.should.raise Informative
end
it "informs about a higher known CocoaPods version" do
write_version_file({'last' => "999.0.0"})
cmd = command('repo', 'update')
cmd.check_versions(versions_file.dirname)
Pod::UI.output.should.include "Cocoapods 999.0.0 is available"
cmd.check_versions(@repo)
UI.output.should.include "Cocoapods 999.0.0 is available"
end
it "has a class method that returns if a repo is supported" do
write_version_file({'min' => "999.0.0"})
Pod::Command::Repo.compatible?('repo1').should == false
Command::Repo.compatible?('repo1').should == false
write_version_file({'min' => "0.0.1"})
Pod::Command::Repo.compatible?('repo1').should == true
Command::Repo.compatible?('repo1').should == true
end
end
end
end
require File.expand_path('../../../spec_helper', __FILE__)
describe "Pod::Command::Setup" do
describe Pod::Command::Setup do
extend SpecHelper::Command
extend SpecHelper::TemporaryDirectory
extend SpecHelper::TemporaryRepos
......@@ -10,16 +10,7 @@ describe "Pod::Command::Setup" do
config.repos_dir = SpecHelper.tmp_repos_path
end
it "runs with correct parameters" do
lambda { run_command('setup') }.should.not.raise
end
it "complains for wrong parameters" do
lambda { run_command('setup', 'wrong') }.should.raise Pod::Command::Help
lambda { run_command('setup', '--wrong') }.should.raise Pod::Command::Help
end
it "returns the read only URL of the `master' spec-repo" do
it "returns the read only URL of the `master` spec-repo" do
cmd = Pod::Command::Setup.new(argv)
cmd.url.should == 'https://github.com/CocoaPods/Specs.git'
end
......@@ -30,21 +21,33 @@ describe "Pod::Command::Setup" do
cmd.url.should == 'git@github.com:CocoaPods/Specs.git'
end
class Pod::Command::Setup
def read_only_url; SpecHelper.fixture('spec-repos/master'); end
before do
set_up_test_repo
Pod::Command::Setup.any_instance.stubs(:read_only_url).returns(test_repo_path.to_s)
config.repos_dir = SpecHelper.temporary_directory
end
it "runs with correct parameters" do
lambda { run_command('setup') }.should.not.raise
end
it "complains for wrong parameters" do
lambda { run_command('setup', 'wrong') }.should.raise Pod::Command::Help
lambda { run_command('setup', '--wrong') }.should.raise Pod::Command::Help
end
it "creates the local spec-repos directory and creates a clone of the `master' repo" do
output = run_command('setup')
output.should.include "Setup completed"
output.should.not.include "push"
git_config('master', 'remote.origin.url').should == fixture('spec-repos/master').to_s
url = Dir.chdir(config.repos_dir + 'master') { `git config --get remote.origin.url`.chomp }
url.should == test_repo_path.to_s
end
it "preserves push access for the `master' repo" do
output = run_command('setup')
output.should.not.include "push"
git('master', 'remote set-url origin git@github.com:CocoaPods/Specs.git')
Dir.chdir(config.repos_dir + 'master') { `git remote set-url origin git@github.com:CocoaPods/Specs.git` }
command('setup').url.should == 'git@github.com:CocoaPods/Specs.git'
end
......
......@@ -15,17 +15,12 @@ describe Pod::UI do
output.should.include? 'CocoaLumberjack'
output.should.include? '1.0'
output.should.include? '1.1'
output.should.include? '[master repo]'
output.should.include? 'A fast & simple, yet powerful & flexible logging framework for Mac and iOS.'
output.should.include? 'https://github.com/robbiehanson/CocoaLumberjack'
output.should.include? 'https://github.com/robbiehanson/CocoaLumberjack.git'
end
it "presents the name, version, description, homepage and source of a specification set" do
Pod::UI.pod(@set)
output = Pod::UI.output
output.should.include? 'Versions: 1.6, 1.3.3, 1.3.2, 1.3.1, 1.3, 1.2.3, 1.2.2, 1.2.1, 1.2, 1.1, 1.0 [master repo]'
end
it "presents the stats of a specification set" do
repo = { "forks"=>42, "watchers"=>318, "pushed_at"=>"2011-01-26T19:06:43Z" }
Octokit.expects(:repo).with("robbiehanson/CocoaLumberjack").returns(repo)
......
......@@ -196,15 +196,19 @@ else
result = installer.lockfile.to_hash
result['PODS'].should == [
{ "ASIHTTPRequest (1.8.1)" => ["ASIHTTPRequest/ASIWebPageRequest (= 1.8.1)",
{ "ASIHTTPRequest (1.8.1)" =>
[ "ASIHTTPRequest/ASIWebPageRequest (= 1.8.1)",
"ASIHTTPRequest/CloudFiles (= 1.8.1)",
"ASIHTTPRequest/S3 (= 1.8.1)",
"Reachability"]},
"Reachability"
]
},
{ "ASIHTTPRequest/ASIWebPageRequest (1.8.1)" => ["Reachability"] },
{ "ASIHTTPRequest/CloudFiles (1.8.1)" => ["Reachability"] },
{ "ASIHTTPRequest/S3 (1.8.1)" => ["Reachability"] },
"JSONKit (1.4)",
"Reachability (3.0.0)"]
"Reachability (3.1.0)"
]
result['DEPENDENCIES'].should == ["ASIHTTPRequest", "JSONKit (= 1.4)"]
# TODO might be nicer looking to not show the dependencies of the top level spec for each subspec (Reachability).
......@@ -304,7 +308,7 @@ else
lockfile_contents = {
'PODS' => [
'JSONKit (999.999.999)',
'Reachability (3.0.0)',
'Reachability (3.1.0)',
'SSZipArchive (0.1.1)',
],
'DEPENDENCIES' => [
......
require 'spec_helper/temporary_directory'
# Important
# Include with temporary directory
module SpecHelper
def self.tmp_repos_path
TemporaryRepos.tmp_repos_path
......@@ -9,41 +12,64 @@ module SpecHelper
extend Pod::Executable
executable :git
def tmp_repos_path
SpecHelper.temporary_directory + 'cocoapods'
# @return [Pathname] The path for the repo with the given name.
#
def repo_path(name)
tmp_repos_path + name
end
module_function :tmp_repos_path
alias_method :git_super, :git
def git(repo, command)
Dir.chdir(tmp_repos_path + repo) do
if output = git_super(command)
output.strip
# Makes a repo with the given name.
#
def repo_make(name)
path = repo_path(name)
path.mkpath
Dir.chdir(path) do
`git init`
repo_make_readme_change(name, 'Added')
`git add .`
`git commit -m "Initialized."`
end
path
end
# Clones a repo to the given name.
#
def repo_clone(from_name, to_name)
Dir.chdir(tmp_repos_path) { `git clone #{from_name} #{to_name}` }
repo_path(to_name)
end
def git_config(repo, attr)
git repo, "config --get #{attr}"
def repo_make_readme_change(name, string)
file = repo_path(name) + 'README'
file.open('w') { |f| f << "#{string}" }
end
def add_repo(name, from)
command = command('repo', 'add', name, from)
command.run
# The test branch is used by the push specs
Dir.chdir(command.dir) do
`git checkout -b test >/dev/null 2>&1`
`git branch --set-upstream test origin/master >/dev/null 2>&1`
#--------------------------------------#
def test_repo_path
repo_path('master')
end
command
# Sets up a lighweight master repo in `tmp/cocoapods/master` with the
# contents of `spec/fixtures/spec-repos/test_repo`.
#
def set_up_test_repo
require 'fileutils'
test_repo_path.mkpath
origin = ROOT + 'spec/fixtures/spec-repos/test_repo/.'
destination = tmp_repos_path + 'master'
FileUtils.cp_r(origin, destination)
repo_make('master')
end
def make_change(repo, name)
(repo.dir + 'README').open('w') { |f| f << 'Added!' }
git(name, 'add README')
git(name, 'commit -m "changed"')
#--------------------------------------#
def tmp_repos_path
SpecHelper.temporary_directory + 'cocoapods'
end
module_function :tmp_repos_path
def self.extended(base)
base.before do
tmp_repos_path.mkpath
......
......@@ -5,8 +5,8 @@ module Pod
before do
config.repos_dir = fixture('spec-repos')
@podfile = Podfile.new do
platform :ios
pod 'BlocksKit'
platform :ios, '6.0'
pod 'BlocksKit', '1.8.0'
end
@resolver = Resolver.new(@podfile, nil, stub('sandbox'))
end
......@@ -14,7 +14,6 @@ module Pod
it "holds the context state, such as cached specification sets" do
@resolver.resolve
@resolver.cached_sets.values.sort_by(&:name).should == [
Pod::Source.search_by_name('A2DynamicDelegate').first,
Pod::Source.search_by_name('BlocksKit').first,
Pod::Source.search_by_name('libffi').first
].sort_by(&:name)
......@@ -23,13 +22,13 @@ module Pod
it "returns all specs needed for the dependency" do
specs = @resolver.resolve.values.flatten
specs.map(&:class).uniq.should == [Specification]
specs.map(&:name).sort.should == %w{ A2DynamicDelegate BlocksKit libffi }
specs.map(&:name).sort.should == %w{ BlocksKit libffi }
end
it "does not raise if all dependencies match the platform of the root spec (Podfile)" do
@podfile.platform :ios
@podfile.platform :ios, '6.0'
lambda { @resolver.resolve }.should.not.raise
@podfile.platform :osx
@podfile.platform :osx, '10.7'
lambda { @resolver.resolve }.should.not.raise
end
......@@ -259,7 +258,7 @@ module Pod
platform :ios
pod 'JSONKit'
pod 'BlocksKit'
pod 'libPusher' # New pod
pod 'libPusher', '1.3' # New pod
end
@resolver = Resolver.new(podfile, @lockfile, stub('sandbox'))
installed = @resolver.resolve.values.flatten.map(&:to_s)
......@@ -348,7 +347,7 @@ module Pod
before do
config.repos_dir = fixture('spec-repos')
@podfile = Podfile.new do
platform :ios
platform :ios, '6.0'
pod 'BlocksKit'
pod 'JSONKit'
pod 'libPusher'
......@@ -376,7 +375,7 @@ module Pod
it "respects the constraints of the podfile" do
podfile = Podfile.new do
platform :ios
platform :ios, '6.0'
pod 'BlocksKit'
pod 'JSONKit', '1.4'
end
......
......@@ -16,7 +16,9 @@ describe "Pod::Source" do
end
it "returns the available versions of a Pod" do
@source.versions('Reachability').map(&:to_s).should == %w| 3.0.0 2.0.5 2.0.4 |
known = %w| 3.0.0 2.0.5 2.0.4 |
computed = @source.versions('Reachability').map(&:to_s)
(known - computed).should.be.empty?
end
it "returns the specification of a given version of a Pod" do
......
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