Skip to content
Snippets Groups Projects
Commit c551252d authored by Josh Hagins's avatar Josh Hagins Committed by GitHub
Browse files

Merge pull request #1356 from reitermarkus/refactor-url-checker-test

Refactor Hbc::UrlChecker test.
parents 0c140f09 1bcaad6f
No related branches found
No related tags found
No related merge requests found
......@@ -15,14 +15,15 @@ group :test do
# - https://github.com/colszowka/simplecov/pull/520
gem "simplecov", "0.12.0",
git: "https://github.com/colszowka/simplecov.git",
branch: "master", # commit 83d8031ddde0927f87ef9327200a98583ca18d77
branch: "master",
ref: "83d8031ddde0927f87ef9327200a98583ca18d77",
require: false
gem "codecov", require: false
gem "minitest", "5.4.1"
gem "minitest", "~> 5.9"
gem "minitest-reporters"
gem "mocha", "1.1.0", require: false
gem "mocha", "~> 1.1", require: false
gem "parallel_tests"
gem "rspec", "~> 3.0.0"
gem "rspec", "~> 3.5"
gem "rspec-its", require: false
gem "rspec-wait", require: false
end
GIT
remote: https://github.com/colszowka/simplecov.git
revision: 83d8031ddde0927f87ef9327200a98583ca18d77
ref: 83d8031ddde0927f87ef9327200a98583ca18d77
branch: master
specs:
simplecov (0.12.0)
......@@ -13,8 +14,8 @@ GEM
specs:
ansi (1.5.0)
builder (3.2.2)
byebug (9.0.5)
codecov (0.1.5)
byebug (9.0.6)
codecov (0.1.6)
json
simplecov
url
......@@ -24,16 +25,16 @@ GEM
json (2.0.2)
metaclass (0.0.4)
method_source (0.8.2)
minitest (5.4.1)
minitest (5.9.1)
minitest-reporters (1.1.11)
ansi
builder
minitest (>= 5.0)
ruby-progressbar
mocha (1.1.0)
mocha (1.2.1)
metaclass (~> 0.0.1)
parallel (1.9.0)
parallel_tests (2.9.0)
parallel_tests (2.10.0)
parallel
pry (0.10.4)
coderay (~> 1.1.0)
......@@ -42,22 +43,23 @@ GEM
pry-byebug (3.4.0)
byebug (~> 9.0)
pry (~> 0.10)
rake (10.4.2)
rspec (3.0.0)
rspec-core (~> 3.0.0)
rspec-expectations (~> 3.0.0)
rspec-mocks (~> 3.0.0)
rspec-core (3.0.4)
rspec-support (~> 3.0.0)
rspec-expectations (3.0.4)
rake (11.3.0)
rspec (3.5.0)
rspec-core (~> 3.5.0)
rspec-expectations (~> 3.5.0)
rspec-mocks (~> 3.5.0)
rspec-core (3.5.4)
rspec-support (~> 3.5.0)
rspec-expectations (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.0.0)
rspec-support (~> 3.5.0)
rspec-its (1.2.0)
rspec-core (>= 3.0.0)
rspec-expectations (>= 3.0.0)
rspec-mocks (3.0.4)
rspec-support (~> 3.0.0)
rspec-support (3.0.4)
rspec-mocks (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-support (3.5.0)
rspec-wait (0.0.9)
rspec (>= 3, < 4)
ruby-progressbar (1.8.1)
......@@ -70,17 +72,17 @@ PLATFORMS
DEPENDENCIES
codecov
minitest (= 5.4.1)
minitest (~> 5.9)
minitest-reporters
mocha (= 1.1.0)
mocha (~> 1.1)
parallel_tests
pry
pry-byebug
rake
rspec (~> 3.0.0)
rspec (~> 3.5)
rspec-its
rspec-wait
simplecov (= 0.12.0)!
BUNDLED WITH
1.13.1
1.13.6
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)
checker.run
checker.errors.must_include "timeout while requesting #{cask.url}"
end
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
instance_eval(&block)
end
}
}
describe "with an empty response" do
let(:response) { "" }
it "properly populates the response code and headers from an http response" do
cask = Hbc.load("basic-cask")
it "adds an error" do
with_stubbed_fetcher.call do
expect(checker.errors).must_include("timeout while requesting #{cask.url}")
end
end
end
Hbc::FakeFetcher.fake_response_for(cask.url, <<-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
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",
"ETag" => '"b4208f3e84967be4b078ecaa03fba941"',
"Content-Length" => "23726161",
"Last-Modified" => "Sun, 12 Aug 2012 21:17:21 GMT")
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"
)
end
end
end
end
end
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"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment