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