Refactor Hbc::UrlChecker test.
This commit is contained in:
parent
0c140f0970
commit
c7a535de22
@ -1,4 +1,5 @@
|
|||||||
require "hbc/checkable"
|
require "hbc/checkable"
|
||||||
|
require "hbc/fetcher"
|
||||||
|
|
||||||
module Hbc
|
module Hbc
|
||||||
class UrlChecker
|
class UrlChecker
|
||||||
|
|||||||
@ -2,32 +2,50 @@ require "test_helper"
|
|||||||
|
|
||||||
describe Hbc::UrlChecker do
|
describe Hbc::UrlChecker do
|
||||||
describe "request processing" do
|
describe "request processing" do
|
||||||
it "adds an error if response is empty" do
|
let(:cask) { Hbc.load("basic-cask") }
|
||||||
cask = Hbc.load("basic-cask")
|
let(:checker) { Hbc::UrlChecker.new(cask) }
|
||||||
Hbc::FakeFetcher.fake_response_for(cask.url, "")
|
let(:with_stubbed_fetcher) {
|
||||||
checker = Hbc::UrlChecker.new(cask, Hbc::FakeFetcher)
|
lambda { |&block|
|
||||||
checker.run
|
Hbc::Fetcher.stub(:head, response) do
|
||||||
checker.errors.must_include "timeout while requesting #{cask.url}"
|
checker.run
|
||||||
|
instance_eval(&block)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
describe "with an empty response" do
|
||||||
|
let(:response) { "" }
|
||||||
|
|
||||||
|
it "adds an error" do
|
||||||
|
with_stubbed_fetcher.call do
|
||||||
|
expect(checker.errors).must_include("timeout while requesting #{cask.url}")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "properly populates the response code and headers from an http response" do
|
describe "with a valid http response" do
|
||||||
cask = Hbc.load("basic-cask")
|
let(:response) {
|
||||||
|
<<-EOS.undent
|
||||||
|
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
|
||||||
|
EOS
|
||||||
|
}
|
||||||
|
|
||||||
Hbc::FakeFetcher.fake_response_for(cask.url, <<-EOS.undent)
|
it "properly populates the response code and headers" do
|
||||||
HTTP/1.1 200 OK
|
with_stubbed_fetcher.call do
|
||||||
Content-Type: application/x-apple-diskimage
|
expect(checker.errors).must_be_empty
|
||||||
ETag: "b4208f3e84967be4b078ecaa03fba941"
|
expect(checker.response_status).must_equal("HTTP/1.1 200 OK")
|
||||||
Content-Length: 23726161
|
expect(checker.headers).must_equal(
|
||||||
Last-Modified: Sun, 12 Aug 2012 21:17:21 GMT
|
"Content-Type" => "application/x-apple-diskimage",
|
||||||
EOS
|
"ETag" => '"b4208f3e84967be4b078ecaa03fba941"',
|
||||||
|
"Content-Length" => "23726161",
|
||||||
checker = Hbc::UrlChecker.new(cask, Hbc::FakeFetcher)
|
"Last-Modified" => "Sun, 12 Aug 2012 21:17:21 GMT"
|
||||||
checker.run
|
)
|
||||||
checker.response_status.must_equal "HTTP/1.1 200 OK"
|
end
|
||||||
checker.headers.must_equal("Content-Type" => "application/x-apple-diskimage",
|
end
|
||||||
"ETag" => '"b4208f3e84967be4b078ecaa03fba941"',
|
|
||||||
"Content-Length" => "23726161",
|
|
||||||
"Last-Modified" => "Sun, 12 Aug 2012 21:17:21 GMT")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,39 +0,0 @@
|
|||||||
module Hbc
|
|
||||||
class FakeFetcher
|
|
||||||
def self.fake_response_for(url, response)
|
|
||||||
@responses[url] = response
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.head(url)
|
|
||||||
@responses ||= {}
|
|
||||||
raise("no response faked for #{url.inspect}") unless @responses.key?(url)
|
|
||||||
@responses[url]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.init
|
|
||||||
@responses = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.clear
|
|
||||||
@responses = {}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
module FakeFetcherHooks
|
|
||||||
def before_setup
|
|
||||||
super
|
|
||||||
Hbc::FakeFetcher.init
|
|
||||||
end
|
|
||||||
|
|
||||||
def after_teardown
|
|
||||||
super
|
|
||||||
Hbc::FakeFetcher.clear
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
module MiniTest
|
|
||||||
class Spec
|
|
||||||
include FakeFetcherHooks
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -100,7 +100,6 @@ require "support/shared_examples"
|
|||||||
require "support/shared_examples/dsl_base.rb"
|
require "support/shared_examples/dsl_base.rb"
|
||||||
require "support/shared_examples/staged.rb"
|
require "support/shared_examples/staged.rb"
|
||||||
|
|
||||||
require "support/fake_fetcher"
|
|
||||||
require "support/fake_dirs"
|
require "support/fake_dirs"
|
||||||
require "support/fake_system_command"
|
require "support/fake_system_command"
|
||||||
require "support/cleanup"
|
require "support/cleanup"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user