Commit 663143ce authored by Kyle Fuller's avatar Kyle Fuller

[linter] Validate screenshot URLs return a valid image

parent 8323920b
...@@ -238,6 +238,8 @@ module Pod ...@@ -238,6 +238,8 @@ module Pod
if resp && !resp.success? if resp && !resp.success?
warning "The URL (#{url}) is not reachable." warning "The URL (#{url}) is not reachable."
end end
resp
end end
# Performs validations related to the `homepage` attribute. # Performs validations related to the `homepage` attribute.
...@@ -252,7 +254,10 @@ module Pod ...@@ -252,7 +254,10 @@ module Pod
# #
def validate_screenshots(spec) def validate_screenshots(spec)
spec.screenshots.each do |screenshot| spec.screenshots.each do |screenshot|
validate_url(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
......
...@@ -121,20 +121,20 @@ module Pod ...@@ -121,20 +121,20 @@ module Pod
@sut.stubs(:check_file_patterns) @sut.stubs(:check_file_patterns)
@sut.stubs(:tear_down_validation_environment) @sut.stubs(:tear_down_validation_environment)
@sut.stubs(:validate_homepage) @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 end
it "checks if the screenshots are valid" do 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/valid-image.png'])
Specification.any_instance.stubs(:screenshots).returns(['http://banana-corp.local/first.png', 'http://banana-corp.local/second.png'])
@sut.validate @sut.validate
@sut.results.should.be.empty? @sut.results.should.be.empty?
end end
it "should fail if any of the screenshots is not valid" do it "should fail if any of the screenshots URLS do not return an image" do
WebMock::API.stub_request(:head, /not-found/).to_raise(SocketError) 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/not-found/second.png']) Specification.any_instance.stubs(:screenshots).returns(['http://banana-corp.local/valid-image.png', 'http://banana-corp.local/'])
@sut.validate @sut.validate
@sut.results.map(&:to_s).first.should.match /There was a problem validating the URL/ @sut.results.map(&:to_s).first.should.match /The screenshot .* is not a valid image/
end end
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