Commit e7de2605 authored by Kyle Fuller's avatar Kyle Fuller

[linter] Validate screenshots are valid

Closes #2010
parent 2b500a99
......@@ -20,6 +20,11 @@ To install or update CocoaPods see this [guide](http://docs.cocoapods.org/guides
[Piet Brauer](https://github.com/pietbrauer)
[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
[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)
......
......@@ -197,6 +197,7 @@ module Pod
#
def perform_extensive_analysis(spec)
validate_homepage(spec)
validate_screenshots(spec)
spec.available_platforms.each do |platform|
UI.message "\n\n#{spec} - Analyzing on #{platform} platform.".green.reversed
......@@ -222,22 +223,36 @@ module Pod
attr_accessor :consumer
attr_accessor :subspec_name
# Performs validations related to the `homepage` attribute.
# Performs validation of a URL
#
def validate_homepage(spec)
def validate_url(url)
require 'rest'
homepage = spec.homepage
return unless homepage
begin
resp = ::REST.head(homepage)
resp = ::REST.head(url)
rescue
warning "There was a problem validating the homepage."
warning "There was a problem validating the URL #{url}."
resp = nil
end
if resp && !resp.success?
warning "The homepage is not reachable."
warning "The URL (#{url}) is not reachable."
end
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|
validate_url(screenshot)
end
end
......
......@@ -99,14 +99,41 @@ module Pod
WebMock::API.stub_request(:head, /not-found/).to_return(:status => 404)
Specification.any_instance.stubs(:homepage).returns('http://banana-corp.local/not-found/')
@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
it "indicates if it was not able to validate the homepage" do
WebMock::API.stub_request(:head, 'banana-corp.local').to_raise(SocketError)
Specification.any_instance.stubs(:homepage).returns('http://banana-corp.local/')
@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)
end
it "checks if the screenshots are valid" do
WebMock::API.stub_request(:head, /banana-corp.local/).to_return(:status => 200)
Specification.any_instance.stubs(:screenshots).returns(['http://banana-corp.local/first.png', 'http://banana-corp.local/second.png'])
@sut.validate
@sut.results.should.be.empty?
end
it "should fail if any of the screenshots is not valid" do
WebMock::API.stub_request(:head, /not-found/).to_raise(SocketError)
Specification.any_instance.stubs(:screenshots).returns(['http://banana-corp.local/first.png', 'http://banana-corp.local/not-found/second.png'])
@sut.validate
@sut.results.map(&:to_s).first.should.match /There was a problem validating the URL/
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