|
|
@ -1,22 +1,37 @@ |
|
|
|
require 'test_helper' |
|
|
|
|
|
|
|
class CaskMissingUrl < Cask |
|
|
|
version '1.2.3' |
|
|
|
homepage 'http://example.com' |
|
|
|
end |
|
|
|
|
|
|
|
class CaskMissingVersion < Cask |
|
|
|
url 'http://localhost/something.dmg' |
|
|
|
homepage 'http://example.com' |
|
|
|
end |
|
|
|
|
|
|
|
class CaskMissingHomepage < Cask |
|
|
|
url 'http://localhost/something.dmg' |
|
|
|
version '1.2.3' |
|
|
|
end |
|
|
|
|
|
|
|
describe Cask::Audit do |
|
|
|
describe "result" do |
|
|
|
it "is 'failed' if there are have been any errors added" do |
|
|
|
audit = Cask::Audit.new(mock()) |
|
|
|
audit = Cask::Audit.new(TestHelper.test_cask) |
|
|
|
audit.add_error 'bad' |
|
|
|
audit.add_warning 'eh' |
|
|
|
audit.result.must_match /failed/ |
|
|
|
end |
|
|
|
|
|
|
|
it "is 'warning' if there are no errors, but there are warnings" do |
|
|
|
audit = Cask::Audit.new(mock()) |
|
|
|
audit = Cask::Audit.new(TestHelper.test_cask) |
|
|
|
audit.add_warning 'eh' |
|
|
|
audit.result.must_match /warning/ |
|
|
|
end |
|
|
|
|
|
|
|
it "is 'passed' if there are no errors or warning" do |
|
|
|
audit = Cask::Audit.new(mock()) |
|
|
|
audit = Cask::Audit.new(TestHelper.test_cask) |
|
|
|
audit.result.must_match /passed/ |
|
|
|
end |
|
|
|
end |
|
|
@ -24,19 +39,19 @@ describe Cask::Audit do |
|
|
|
describe "run!" do |
|
|
|
describe "required fields" do |
|
|
|
it "adds an error if url is missing" do |
|
|
|
audit = Cask::Audit.new(stub(:url => nil, :version => 'something', :homepage => 'something')) |
|
|
|
audit = Cask::Audit.new(CaskMissingUrl.new) |
|
|
|
audit.run! |
|
|
|
audit.errors.must_include 'url is required' |
|
|
|
end |
|
|
|
|
|
|
|
it "adds an error if version is missing" do |
|
|
|
audit = Cask::Audit.new(stub(:url => 'something', :version => nil, :homepage => 'something')) |
|
|
|
audit = Cask::Audit.new(CaskMissingVersion.new) |
|
|
|
audit.run! |
|
|
|
audit.errors.must_include 'version is required' |
|
|
|
end |
|
|
|
|
|
|
|
it "adds an error if homepage is missing" do |
|
|
|
audit = Cask::Audit.new(stub(:url => 'something', :version => 'something', :homepage => nil)) |
|
|
|
audit = Cask::Audit.new(CaskMissingHomepage.new) |
|
|
|
audit.run! |
|
|
|
audit.errors.must_include 'homepage is required' |
|
|
|
end |
|
|
@ -44,26 +59,23 @@ describe Cask::Audit do |
|
|
|
|
|
|
|
describe "request processing" do |
|
|
|
it "adds an error if response is empty" do |
|
|
|
audit = Cask::Audit.new(stub(:url => 'something', :version => 'something', :homepage => 'something')) |
|
|
|
audit.stubs(:_curl).returns('') |
|
|
|
cask = TestHelper.test_cask |
|
|
|
TestHelper.fake_response_for(cask.url, "") |
|
|
|
audit = Cask::Audit.new(cask, TestHelper.fake_fetcher) |
|
|
|
audit.run! |
|
|
|
audit.errors.must_include 'timeout while requesting something' |
|
|
|
audit.errors.must_include "timeout while requesting #{cask.url}" |
|
|
|
end |
|
|
|
|
|
|
|
it "properly populates the response code and headers from an http response" do |
|
|
|
audit = Cask::Audit.new(stub( |
|
|
|
:url => URI('http://something/file.zip'), |
|
|
|
:version => 'something', |
|
|
|
:homepage => 'something', |
|
|
|
:content_length => '123' |
|
|
|
)) |
|
|
|
audit.stubs(:_curl).returns(<<-RESPONSE.gsub(/^ /, '')) |
|
|
|
TestHelper.fake_response_for(TestHelper.test_cask.url, <<-RESPONSE.gsub(/^ /, '')) |
|
|
|
HTTP/1.1 200 OK |
|
|
|
Content-Type: application/x-apple-diskimage |
|
|
|
ETag: "b4208f3e84967be4b078ecaa03fba941" |
|
|
|
Content-Length: 23726161 |
|
|
|
Last-Modified: Sun, 12 Aug 2012 21:17:21 GMT |
|
|
|
RESPONSE |
|
|
|
|
|
|
|
audit = Cask::Audit.new(TestHelper.test_cask, TestHelper.fake_fetcher) |
|
|
|
audit.run! |
|
|
|
audit.response_status.must_equal 'HTTP/1.1 200 OK' |
|
|
|
audit.headers.must_equal({ |
|
|
|