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
d579fe46
Commit
d579fe46
authored
Apr 07, 2014
by
Fabio Pelosin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2016 from CocoaPods/screenshots
[linter] Validate screenshots are valid
parents
2b500a99
663143ce
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
9 deletions
+69
-9
CHANGELOG.md
CHANGELOG.md
+5
-0
validator.rb
lib/cocoapods/validator.rb
+27
-7
validator_spec.rb
spec/unit/validator_spec.rb
+37
-2
No files found.
CHANGELOG.md
View file @
d579fe46
...
@@ -20,6 +20,11 @@ To install or update CocoaPods see this [guide](http://docs.cocoapods.org/guides
...
@@ -20,6 +20,11 @@ To install or update CocoaPods see this [guide](http://docs.cocoapods.org/guides
[
Piet Brauer
](
https://github.com/pietbrauer
)
[
Piet Brauer
](
https://github.com/pietbrauer
)
[
Orta Therox
](
https://github.com/orta
)
[
Orta Therox
](
https://github.com/orta
)
*
Validate the reachability of screenshot URLs in podspecs while linting a
specification.
[
Kyle Fuller
](
https://github.com/kylef
)
[
#2010
](
https://github.com/CocoaPods/CocoaPods/issues/2010
)
## 0.31.1
## 0.31.1
[
CocoaPods
](
https://github.com/CocoaPods/CocoaPods/compare/0.31.1...0.31.0
)
[
CocoaPods
](
https://github.com/CocoaPods/CocoaPods/compare/0.31.1...0.31.0
)
•
[
CocoaPods-Core
](
https://github.com/CocoaPods/Core/compare/0.31.1...0.31.0
)
•
[
CocoaPods-Core
](
https://github.com/CocoaPods/Core/compare/0.31.1...0.31.0
)
...
...
lib/cocoapods/validator.rb
View file @
d579fe46
...
@@ -197,6 +197,7 @@ module Pod
...
@@ -197,6 +197,7 @@ module Pod
#
#
def
perform_extensive_analysis
(
spec
)
def
perform_extensive_analysis
(
spec
)
validate_homepage
(
spec
)
validate_homepage
(
spec
)
validate_screenshots
(
spec
)
spec
.
available_platforms
.
each
do
|
platform
|
spec
.
available_platforms
.
each
do
|
platform
|
UI
.
message
"
\n\n
#{
spec
}
- Analyzing on
#{
platform
}
platform."
.
green
.
reversed
UI
.
message
"
\n\n
#{
spec
}
- Analyzing on
#{
platform
}
platform."
.
green
.
reversed
...
@@ -222,22 +223,41 @@ module Pod
...
@@ -222,22 +223,41 @@ module Pod
attr_accessor
:consumer
attr_accessor
:consumer
attr_accessor
:subspec_name
attr_accessor
:subspec_name
# Performs validation
s related to the `homepage` attribute.
# Performs validation
of a URL
#
#
def
validate_
homepage
(
spec
)
def
validate_
url
(
url
)
require
'rest'
require
'rest'
homepage
=
spec
.
homepage
return
unless
homepage
begin
begin
resp
=
::
REST
.
head
(
homepage
)
resp
=
::
REST
.
head
(
url
)
rescue
rescue
warning
"There was a problem validating the
homepage
."
warning
"There was a problem validating the
URL
#{
url
}
."
resp
=
nil
resp
=
nil
end
end
if
resp
&&
!
resp
.
success?
if
resp
&&
!
resp
.
success?
warning
"The homepage is not reachable."
warning
"The URL (
#{
url
}
) is not reachable."
end
resp
end
# Performs validations related to the `homepage` attribute.
#
def
validate_homepage
(
spec
)
if
spec
.
homepage
validate_url
(
spec
.
homepage
)
end
end
# Performs validation related to the `screenshots` attribute.
#
def
validate_screenshots
(
spec
)
spec
.
screenshots
.
each
do
|
screenshot
|
request
=
validate_url
(
screenshot
)
if
request
&&
!
(
request
.
headers
[
'content-type'
]
&&
request
.
headers
[
'content-type'
].
first
=~
/image\/.*/i
)
warning
"The screenshot
#{
screenshot
}
is not a valid image."
end
end
end
end
end
...
...
spec/unit/validator_spec.rb
View file @
d579fe46
...
@@ -75,6 +75,7 @@ module Pod
...
@@ -75,6 +75,7 @@ module Pod
validator
=
Validator
.
new
(
file
)
validator
=
Validator
.
new
(
file
)
validator
.
quick
=
true
validator
.
quick
=
true
validator
.
stubs
(
:validate_homepage
)
validator
.
stubs
(
:validate_homepage
)
validator
.
stubs
(
:validate_screenshots
)
validator
.
validate
validator
.
validate
validator
.
validation_dir
.
should
.
be
==
Pathname
.
new
(
"/private/tmp/CocoaPods/Lint"
)
validator
.
validation_dir
.
should
.
be
==
Pathname
.
new
(
"/private/tmp/CocoaPods/Lint"
)
end
end
...
@@ -99,14 +100,41 @@ module Pod
...
@@ -99,14 +100,41 @@ module Pod
WebMock
::
API
.
stub_request
(
:head
,
/not-found/
).
to_return
(
:status
=>
404
)
WebMock
::
API
.
stub_request
(
:head
,
/not-found/
).
to_return
(
:status
=>
404
)
Specification
.
any_instance
.
stubs
(
:homepage
).
returns
(
'http://banana-corp.local/not-found/'
)
Specification
.
any_instance
.
stubs
(
:homepage
).
returns
(
'http://banana-corp.local/not-found/'
)
@sut
.
validate
@sut
.
validate
@sut
.
results
.
map
(
&
:to_s
).
first
.
should
.
match
/The
homepage
is not reachable/
@sut
.
results
.
map
(
&
:to_s
).
first
.
should
.
match
/The
URL (.*)
is not reachable/
end
end
it
"indicates if it was not able to validate the homepage"
do
it
"indicates if it was not able to validate the homepage"
do
WebMock
::
API
.
stub_request
(
:head
,
'banana-corp.local'
).
to_raise
(
SocketError
)
WebMock
::
API
.
stub_request
(
:head
,
'banana-corp.local'
).
to_raise
(
SocketError
)
Specification
.
any_instance
.
stubs
(
:homepage
).
returns
(
'http://banana-corp.local/'
)
Specification
.
any_instance
.
stubs
(
:homepage
).
returns
(
'http://banana-corp.local/'
)
@sut
.
validate
@sut
.
validate
@sut
.
results
.
map
(
&
:to_s
).
first
.
should
.
match
/There was a problem validating the homepage/
@sut
.
results
.
map
(
&
:to_s
).
first
.
should
.
match
/There was a problem validating the URL/
end
end
describe
"Screenshot validation"
do
require
'webmock'
before
do
@sut
=
Validator
.
new
(
podspec_path
)
@sut
.
stubs
(
:install_pod
)
@sut
.
stubs
(
:build_pod
)
@sut
.
stubs
(
:check_file_patterns
)
@sut
.
stubs
(
:tear_down_validation_environment
)
@sut
.
stubs
(
:validate_homepage
)
WebMock
::
API
.
stub_request
(
:head
,
'banana-corp.local/valid-image.png'
).
to_return
(
:status
=>
200
,
:headers
=>
{
'Content-Type'
=>
'image/png'
})
end
it
"checks if the screenshots are valid"
do
Specification
.
any_instance
.
stubs
(
:screenshots
).
returns
([
'http://banana-corp.local/valid-image.png'
])
@sut
.
validate
@sut
.
results
.
should
.
be
.
empty?
end
it
"should fail if any of the screenshots URLS do not return an image"
do
WebMock
::
API
.
stub_request
(
:head
,
'banana-corp.local/'
).
to_return
(
:status
=>
200
)
Specification
.
any_instance
.
stubs
(
:screenshots
).
returns
([
'http://banana-corp.local/valid-image.png'
,
'http://banana-corp.local/'
])
@sut
.
validate
@sut
.
results
.
map
(
&
:to_s
).
first
.
should
.
match
/The screenshot .* is not a valid image/
end
end
end
end
...
@@ -114,6 +142,7 @@ module Pod
...
@@ -114,6 +142,7 @@ module Pod
file
=
write_podspec
(
stub_podspec
)
file
=
write_podspec
(
stub_podspec
)
sut
=
Validator
.
new
(
file
)
sut
=
Validator
.
new
(
file
)
sut
.
stubs
(
:validate_homepage
)
sut
.
stubs
(
:validate_homepage
)
sut
.
stubs
(
:validate_screenshots
)
sut
.
no_clean
=
true
sut
.
no_clean
=
true
sut
.
validate
sut
.
validate
sut
.
validation_dir
.
should
.
exist
sut
.
validation_dir
.
should
.
exist
...
@@ -123,6 +152,7 @@ module Pod
...
@@ -123,6 +152,7 @@ module Pod
file
=
write_podspec
(
stub_podspec
)
file
=
write_podspec
(
stub_podspec
)
sut
=
Validator
.
new
(
file
)
sut
=
Validator
.
new
(
file
)
sut
.
stubs
(
:validate_homepage
)
sut
.
stubs
(
:validate_homepage
)
sut
.
stubs
(
:validate_screenshots
)
sut
.
expects
(
:install_pod
).
twice
sut
.
expects
(
:install_pod
).
twice
sut
.
expects
(
:build_pod
).
twice
sut
.
expects
(
:build_pod
).
twice
sut
.
expects
(
:check_file_patterns
).
twice
sut
.
expects
(
:check_file_patterns
).
twice
...
@@ -132,6 +162,7 @@ module Pod
...
@@ -132,6 +162,7 @@ module Pod
it
"uses the deployment target of the specification"
do
it
"uses the deployment target of the specification"
do
sut
=
Validator
.
new
(
podspec_path
)
sut
=
Validator
.
new
(
podspec_path
)
sut
.
stubs
(
:validate_homepage
)
sut
.
stubs
(
:validate_homepage
)
sut
.
stubs
(
:validate_screenshots
)
podfile
=
sut
.
send
(
:podfile_from_spec
,
:ios
,
'5.0'
)
podfile
=
sut
.
send
(
:podfile_from_spec
,
:ios
,
'5.0'
)
dependency
=
podfile
.
target_definitions
[
'Pods'
].
dependencies
.
first
dependency
=
podfile
.
target_definitions
[
'Pods'
].
dependencies
.
first
dependency
.
external_source
.
has_key?
(
:podspec
).
should
.
be
.
true
dependency
.
external_source
.
has_key?
(
:podspec
).
should
.
be
.
true
...
@@ -140,6 +171,7 @@ module Pod
...
@@ -140,6 +171,7 @@ module Pod
it
"respects the local option"
do
it
"respects the local option"
do
sut
=
Validator
.
new
(
podspec_path
)
sut
=
Validator
.
new
(
podspec_path
)
sut
.
stubs
(
:validate_homepage
)
sut
.
stubs
(
:validate_homepage
)
sut
.
stubs
(
:validate_screenshots
)
podfile
=
sut
.
send
(
:podfile_from_spec
,
:ios
,
'5.0'
)
podfile
=
sut
.
send
(
:podfile_from_spec
,
:ios
,
'5.0'
)
deployment_target
=
podfile
.
target_definitions
[
'Pods'
].
platform
.
deployment_target
deployment_target
=
podfile
.
target_definitions
[
'Pods'
].
platform
.
deployment_target
deployment_target
.
to_s
.
should
==
"5.0"
deployment_target
.
to_s
.
should
==
"5.0"
...
@@ -150,6 +182,7 @@ module Pod
...
@@ -150,6 +182,7 @@ module Pod
sut
.
stubs
(
:check_file_patterns
)
sut
.
stubs
(
:check_file_patterns
)
sut
.
stubs
(
:xcodebuild
).
returns
(
"file.m:1:1: warning: direct access to objective-c's isa is deprecated"
)
sut
.
stubs
(
:xcodebuild
).
returns
(
"file.m:1:1: warning: direct access to objective-c's isa is deprecated"
)
sut
.
stubs
(
:validate_homepage
)
sut
.
stubs
(
:validate_homepage
)
sut
.
stubs
(
:validate_screenshots
)
sut
.
validate
sut
.
validate
first
=
sut
.
results
.
map
(
&
:to_s
).
first
first
=
sut
.
results
.
map
(
&
:to_s
).
first
first
.
should
.
include
"[xcodebuild]"
first
.
should
.
include
"[xcodebuild]"
...
@@ -161,6 +194,7 @@ module Pod
...
@@ -161,6 +194,7 @@ module Pod
sut
=
Validator
.
new
(
file
)
sut
=
Validator
.
new
(
file
)
sut
.
stubs
(
:build_pod
)
sut
.
stubs
(
:build_pod
)
sut
.
stubs
(
:validate_homepage
)
sut
.
stubs
(
:validate_homepage
)
sut
.
stubs
(
:validate_screenshots
)
sut
.
validate
sut
.
validate
sut
.
results
.
map
(
&
:to_s
).
first
.
should
.
match
/source_files.*did not match/
sut
.
results
.
map
(
&
:to_s
).
first
.
should
.
match
/source_files.*did not match/
sut
.
result_type
.
should
==
:error
sut
.
result_type
.
should
==
:error
...
@@ -175,6 +209,7 @@ module Pod
...
@@ -175,6 +209,7 @@ module Pod
spec
=
Specification
.
from_file
(
file
)
spec
=
Specification
.
from_file
(
file
)
sut
=
Validator
.
new
(
spec
)
sut
=
Validator
.
new
(
spec
)
sut
.
stubs
(
:validate_homepage
)
sut
.
stubs
(
:validate_homepage
)
sut
.
stubs
(
:validate_screenshots
)
sut
.
stubs
(
:build_pod
)
sut
.
stubs
(
:build_pod
)
sut
.
validate
sut
.
validate
sut
.
validated?
.
should
.
be
.
true
sut
.
validated?
.
should
.
be
.
true
...
...
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