Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
cocoapods
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
cocoapods
Commits
8a1a5d30
Commit
8a1a5d30
authored
May 29, 2012
by
Fabio Pelosin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Repo] Class method to return if a repo is compatible.
parent
4ee2fc68
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
163 additions
and
69 deletions
+163
-69
repo.rb
lib/cocoapods/command/repo.rb
+49
-14
repo_spec.rb
spec/functional/command/repo_spec.rb
+73
-55
repo_spec.rb
spec/unit/command/repo_spec.rb
+41
-0
No files found.
lib/cocoapods/command/repo.rb
View file @
8a1a5d30
...
@@ -58,24 +58,59 @@ module Pod
...
@@ -58,24 +58,59 @@ module Pod
end
end
def
check_versions
(
dir
)
def
check_versions
(
dir
)
require
'yaml'
versions
=
versions
(
dir
)
bin_version
=
Gem
::
Version
.
new
(
VERSION
)
unless
is_compatilbe
(
versions
)
yaml_file
=
dir
+
'CocoaPods-version.yml'
min
,
max
=
versions
[
'min'
],
versions
[
'max'
]
return
unless
yaml_file
.
exist?
version_msg
=
(
min
==
max
)
?
min
:
"
#{
min
}
-
#{
max
}
"
data
=
YAML
.
load_file
(
yaml_file
)
min_version
=
Gem
::
Version
.
new
(
data
[
'min'
])
if
data
[
'min'
]
max_version
=
Gem
::
Version
.
new
(
data
[
'max'
])
if
data
[
'max'
]
last_version
=
Gem
::
Version
.
new
(
data
[
'last'
])
if
data
[
'last'
]
supports_min
=
min_version
?
bin_version
>=
min_version
:
true
supports_max
=
max_version
?
bin_version
<=
max_version
:
true
unless
supports_min
&&
supports_max
version_msg
=
(
min_version
==
max_version
)
?
min_version
:
"
#{
min_version
}
-
#{
max_version
}
"
raise
Informative
,
raise
Informative
,
"
\n
[!] The `
#{
dir
.
basename
.
to_s
}
' repo requires CocoaPods
#{
min_version
}
\n
"
.
red
+
"
\n
[!] The `
#{
dir
.
basename
.
to_s
}
' repo requires CocoaPods
#{
version_msg
}
\n
"
.
red
+
"Update Cocoapods, or checkout the appropriate tag in the repo.
\n\n
"
"Update Cocoapods, or checkout the appropriate tag in the repo.
\n\n
"
end
end
puts
"
\n
Cocoapods
#{
last_version
}
is available.
\n
"
.
green
if
last_version
&&
last_version
>
bin_version
puts
"
\n
Cocoapods
#{
versions
[
'last'
]
}
is available.
\n
"
.
green
if
has_update
(
versions
)
end
def
self
.
is_compatible
(
name
)
dir
=
Config
.
instance
.
repos_dir
+
name
versions
=
versions
(
dir
)
is_compatilbe
(
versions
)
end
private
def
versions
(
dir
)
self
.
class
.
versions
(
dir
)
end
def
self
.
versions
(
dir
)
require
'yaml'
yaml_file
=
dir
+
'CocoaPods-version.yml'
yaml_file
.
exist?
?
YAML
.
load_file
(
yaml_file
)
:
{}
end
def
is_compatilbe
(
versions
)
self
.
class
.
is_compatilbe
(
versions
)
end
def
self
.
is_compatilbe
(
versions
)
min
,
max
=
versions
[
'min'
],
versions
[
'max'
]
supports_min
=
!
min
||
bin_version
>=
Gem
::
Version
.
new
(
min
)
supports_max
=
!
max
||
bin_version
<=
Gem
::
Version
.
new
(
max
)
supports_min
&&
supports_max
end
def
has_update
(
versions
)
self
.
class
.
has_update
(
versions
)
end
end
def
self
.
has_update
(
versions
)
last
=
versions
[
'last'
]
last
&&
Gem
::
Version
.
new
(
last
)
>
bin_version
end
def
self
.
bin_version
Gem
::
Version
.
new
(
VERSION
)
end
end
end
end
end
end
end
...
...
spec/functional/command/repo_spec.rb
View file @
8a1a5d30
require
File
.
expand_path
(
'../../../spec_helper'
,
__FILE__
)
require
File
.
expand_path
(
'../../../spec_helper'
,
__FILE__
)
describe
"Pod::Command::Repo"
do
describe
"Pod::Command::Repo"
do
describe
"In general"
do
extend
SpecHelper
::
Command
extend
SpecHelper
::
Command
extend
SpecHelper
::
TemporaryDirectory
extend
SpecHelper
::
TemporaryDirectory
extend
SpecHelper
::
TemporaryRepos
extend
SpecHelper
::
TemporaryRepos
it
"runs with correct parameters"
do
it
"runs with correct parameters"
do
lambda
{
run_command
(
'repo'
,
'add'
,
'NAME'
,
'URL'
)
}.
should
.
not
.
raise
lambda
{
run_command
(
'repo'
,
'add'
,
'NAME'
,
'URL'
)
}.
should
.
not
.
raise
lambda
{
run_command
(
'repo'
,
'update'
)
}.
should
.
not
.
raise
lambda
{
run_command
(
'repo'
,
'update'
)
}.
should
.
not
.
raise
end
end
it
"complains for wrong parameters"
do
it
"complains for wrong parameters"
do
lambda
{
run_command
(
'repo'
,
'add'
)
}.
should
.
raise
Pod
::
Informative
lambda
{
run_command
(
'repo'
,
'add'
)
}.
should
.
raise
Pod
::
Informative
lambda
{
run_command
(
'repo'
,
'add'
,
'NAME'
)
}.
should
.
raise
Pod
::
Informative
lambda
{
run_command
(
'repo'
,
'add'
,
'NAME'
)
}.
should
.
raise
Pod
::
Informative
end
end
it
"adds a spec-repo"
do
it
"adds a spec-repo"
do
add_repo
(
'private'
,
fixture
(
'spec-repos/master'
))
add_repo
(
'private'
,
fixture
(
'spec-repos/master'
))
git_config
(
'private'
,
'remote.origin.url'
).
should
==
fixture
(
'spec-repos/master'
).
to_s
git_config
(
'private'
,
'remote.origin.url'
).
should
==
fixture
(
'spec-repos/master'
).
to_s
end
end
it
"updates a spec-repo"
do
it
"updates a spec-repo"
do
repo1
=
add_repo
(
'repo1'
,
fixture
(
'spec-repos/master'
))
repo1
=
add_repo
(
'repo1'
,
fixture
(
'spec-repos/master'
))
git
(
'repo1'
,
'checkout master'
)
# checkout master, because the fixture is a submodule
git
(
'repo1'
,
'checkout master'
)
# checkout master, because the fixture is a submodule
repo2
=
add_repo
(
'repo2'
,
repo1
.
dir
)
repo2
=
add_repo
(
'repo2'
,
repo1
.
dir
)
make_change
(
repo1
,
'repo1'
)
make_change
(
repo1
,
'repo1'
)
run_command
(
'repo'
,
'update'
,
'repo2'
)
run_command
(
'repo'
,
'update'
,
'repo2'
)
(
repo2
.
dir
+
'README'
).
read
.
should
.
include
'Added!'
(
repo2
.
dir
+
'README'
).
read
.
should
.
include
'Added!'
end
end
it
"updates all the spec-repos"
do
it
"updates all the spec-repos"
do
repo1
=
add_repo
(
'repo1'
,
fixture
(
'spec-repos/master'
))
repo1
=
add_repo
(
'repo1'
,
fixture
(
'spec-repos/master'
))
git
(
'repo1'
,
'checkout master'
)
# checkout master, because the fixture is a submodule
git
(
'repo1'
,
'checkout master'
)
# checkout master, because the fixture is a submodule
repo2
=
add_repo
(
'repo2'
,
repo1
.
dir
)
repo2
=
add_repo
(
'repo2'
,
repo1
.
dir
)
repo3
=
add_repo
(
'repo3'
,
repo1
.
dir
)
repo3
=
add_repo
(
'repo3'
,
repo1
.
dir
)
make_change
(
repo1
,
'repo1'
)
make_change
(
repo1
,
'repo1'
)
run_command
(
'repo'
,
'update'
)
run_command
(
'repo'
,
'update'
)
(
repo2
.
dir
+
'README'
).
read
.
should
.
include
'Added!'
(
repo2
.
dir
+
'README'
).
read
.
should
.
include
'Added!'
(
repo3
.
dir
+
'README'
).
read
.
should
.
include
'Added!'
(
repo3
.
dir
+
'README'
).
read
.
should
.
include
'Added!'
end
end
end
before
do
describe
"Concerning a repo support"
do
add_repo
(
'repo1'
,
fixture
(
'spec-repos/master'
))
extend
SpecHelper
::
Command
FileUtils
.
rm_rf
(
versions_file
)
extend
SpecHelper
::
TemporaryDirectory
versions_file
.
should
.
not
.
exist?
extend
SpecHelper
::
TemporaryRepos
end
require
'yaml'
before
do
add_repo
(
'repo1'
,
fixture
(
'spec-repos/master'
))
FileUtils
.
rm_rf
(
versions_file
)
versions_file
.
should
.
not
.
exist?
end
def
versions_file
require
'yaml'
tmp_repos_path
+
"repo1/CocoaPods-version.yml"
end
it
"it doesn't requires CocoaPods-version.yml"
do
def
versions_file
lambda
{
run_command
(
'repo'
,
'update'
)
}.
should
.
not
.
raise
tmp_repos_path
+
"repo1/CocoaPods-version.yml"
end
end
it
"runs with a compatible repo"
do
it
"it doesn't requires CocoaPods-version.yml"
do
yaml
=
YAML
.
dump
({
:min
=>
"0.0.1"
})
lambda
{
run_command
(
'repo'
,
'update'
)
}.
should
.
not
.
raise
File
.
open
(
versions_file
,
'w'
)
{
|
f
|
f
.
write
(
yaml
)
}
end
lambda
{
run_command
(
'repo'
,
'update'
)
}.
should
.
not
.
raise
end
it
"raises if a repo is not compatible"
do
it
"runs with a compatible repo"
do
yaml
=
YAML
.
dump
({
:min
=>
"999.0.0"
})
yaml
=
YAML
.
dump
({
'min'
=>
"0.0.1"
})
File
.
open
(
versions_file
,
'w'
)
{
|
f
|
f
.
write
(
yaml
)
}
File
.
open
(
versions_file
,
'w'
)
{
|
f
|
f
.
write
(
yaml
)
}
lambda
{
run_command
(
'repo'
,
'update'
)
}.
should
.
raise
Pod
::
Informative
lambda
{
run_command
(
'repo'
,
'update'
)
}.
should
.
not
.
raise
end
end
it
"raises if a repo is not compatible"
do
yaml
=
YAML
.
dump
({
'min'
=>
"999.0.0"
})
File
.
open
(
versions_file
,
'w'
)
{
|
f
|
f
.
write
(
yaml
)
}
lambda
{
run_command
(
'repo'
,
'update'
)
}.
should
.
raise
Pod
::
Informative
end
it
"informs about a higher known CocoaPods version"
do
yaml
=
YAML
.
dump
({
'last'
=>
"999.0.0"
})
File
.
open
(
versions_file
,
'w'
)
{
|
f
|
f
.
write
(
yaml
)
}
run_command
(
'repo'
,
'update'
).
should
.
include
"Cocoapods 999.0.0 is available"
end
it
"has a class method that returns if a repo is supported"
do
yaml
=
YAML
.
dump
({
'min'
=>
"999.0.0"
})
File
.
open
(
versions_file
,
'w'
)
{
|
f
|
f
.
write
(
yaml
)
}
Pod
::
Command
::
Repo
.
is_compatible
(
'repo1'
).
should
==
false
it
"informs about a higher known CocoaPods version"
do
yaml
=
YAML
.
dump
({
'min'
=>
"0.0.1"
})
yaml
=
YAML
.
dump
({
:last
=>
"999.0.0"
})
File
.
open
(
versions_file
,
'w'
)
{
|
f
|
f
.
write
(
yaml
)
}
File
.
open
(
versions_file
,
'w'
)
{
|
f
|
f
.
write
(
yaml
)
}
Pod
::
Command
::
Repo
.
is_compatible
(
'repo1'
).
should
==
true
run_command
(
'repo'
,
'update'
).
should
.
include
"Cocoapods 999.0.0 is available"
end
end
end
end
end
spec/unit/command/repo_spec.rb
0 → 100644
View file @
8a1a5d30
require
File
.
expand_path
(
'../../../spec_helper'
,
__FILE__
)
describe
"Pod::Command::Repo"
do
extend
SpecHelper
::
Command
before
do
@command
=
command
(
'repo'
,
'update'
)
@command
.
stubs
(
:bin_version
).
returns
(
Gem
::
Version
.
new
(
'0.6.0.rc1'
))
end
it
"supports a repo with a compatible minimum version"
do
versions
=
{
'min'
=>
'0.5'
}
@command
.
class
.
send
(
:is_compatilbe
,
versions
).
should
==
true
end
it
"doesn't supports a repo with a compatible minimum version"
do
versions
=
{
'min'
=>
'0.7'
}
@command
.
class
.
send
(
:is_compatilbe
,
versions
).
should
==
false
end
it
"supports a repo with a compatible maximum version"
do
versions
=
{
'max'
=>
'0.7'
}
@command
.
class
.
send
(
:is_compatilbe
,
versions
).
should
==
true
end
it
"doesn't supports a repo with a compatible maximum version"
do
versions
=
{
'max'
=>
'0.5'
}
@command
.
class
.
send
(
:is_compatilbe
,
versions
).
should
==
false
end
it
"detects if an update is available"
do
versions
=
{
'last'
=>
'0.5'
}
@command
.
class
.
send
(
:has_update
,
versions
).
should
==
false
end
it
"detects if no update is available"
do
versions
=
{
'last'
=>
'0.7'
}
@command
.
class
.
send
(
:has_update
,
versions
).
should
==
true
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment