Commit 9cc299a9 authored by Kyle Fuller's avatar Kyle Fuller

[linter] Check social_media_url is valid HTTP URL

parent 2659252f
...@@ -4,6 +4,13 @@ To install or update CocoaPods see this [guide](http://docs.cocoapods.org/guides ...@@ -4,6 +4,13 @@ To install or update CocoaPods see this [guide](http://docs.cocoapods.org/guides
## Master ## Master
##### Enhancements
* Validate the reachability of social media URLs in podspecs while linting a
specification.
[Kyle Fuller](https://github.com/kylef)
[#2025](https://github.com/CocoaPods/CocoaPods/issues/2025)
##### Bug Fixes ##### Bug Fixes
* Fixed support for file references in the workspace generated by CocoaPods. * Fixed support for file references in the workspace generated by CocoaPods.
......
...@@ -198,6 +198,7 @@ module Pod ...@@ -198,6 +198,7 @@ module Pod
def perform_extensive_analysis(spec) def perform_extensive_analysis(spec)
validate_homepage(spec) validate_homepage(spec)
validate_screenshots(spec) validate_screenshots(spec)
validate_social_media_url(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
...@@ -256,6 +257,12 @@ module Pod ...@@ -256,6 +257,12 @@ module Pod
end end
end end
# Performs validations related to the `social_media_url` attribute.
#
def validate_social_media_url(spec)
validate_url(spec.social_media_url) if spec.social_media_url
end
def setup_validation_environment def setup_validation_environment
validation_dir.rmtree if validation_dir.exist? validation_dir.rmtree if validation_dir.exist?
validation_dir.mkpath validation_dir.mkpath
......
...@@ -104,12 +104,12 @@ module Pod ...@@ -104,12 +104,12 @@ module Pod
@sut.stubs(:build_pod) @sut.stubs(:build_pod)
@sut.stubs(:check_file_patterns) @sut.stubs(:check_file_patterns)
@sut.stubs(:tear_down_validation_environment) @sut.stubs(:tear_down_validation_environment)
WebMock::API.stub_request(:head, /not-found/).to_return(:status => 404)
WebMock::API.stub_request(:get, /not-found/).to_return(:status => 404)
end end
describe "Homepage validation" do describe "Homepage validation" do
it "checks if the homepage is valid" do it "checks if the homepage is valid" do
WebMock::API.stub_request(:head, /not-found/).to_return(:status => 404)
WebMock::API.stub_request(:get, /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 URL (.*) is not reachable/ @sut.results.map(&:to_s).first.should.match /The URL (.*) is not reachable/
...@@ -189,6 +189,26 @@ module Pod ...@@ -189,6 +189,26 @@ module Pod
@sut.results.map(&:to_s).first.should.match /The screenshot .* is not a valid image/ @sut.results.map(&:to_s).first.should.match /The screenshot .* is not a valid image/
end end
end end
describe "social media URL validation" do
before do
@sut.stubs(:validate_homepage)
end
it "checks if the social media URL is valid" do
Specification.any_instance.stubs(:social_media_urlon_url).returns('http://banana-corp.local/')
WebMock::API.stub_request(:head, /banana-corp.local/).to_return(:status => 200)
@sut.validate
@sut.results.should.be.empty?
end
it "should fail validation if it wasn't able to validate the URL" do
Specification.any_instance.stubs(:social_media_url).returns('http://banana-corp.local/not-found/')
WebMock::API.stub_request(:head, /banana-corp.local/).to_return(:status => 404)
@sut.validate
@sut.results.map(&:to_s).first.should.match /The URL \(.*\) is not reachable/
end
end
end end
it "respects the no clean option" do it "respects the no clean option" 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