Merge pull request #1339 from reitermarkus/test-helper
Use `test/lib/config` for tests.
This commit is contained in:
commit
f56e410ebf
@ -31,11 +31,11 @@ Hbc.appdir = Pathname.new(TEST_TMPDIR).join("Applications").tap(&:mkpath)
|
|||||||
Hbc.cache.mkpath
|
Hbc.cache.mkpath
|
||||||
Hbc.caskroom.mkpath
|
Hbc.caskroom.mkpath
|
||||||
Hbc.default_tap = Tap.fetch("caskroom", "spec").tap do |tap|
|
Hbc.default_tap = Tap.fetch("caskroom", "spec").tap do |tap|
|
||||||
tap.path.dirname.mkpath
|
# link test casks
|
||||||
|
FileUtils.mkdir_p tap.path.dirname
|
||||||
|
FileUtils.ln_s Pathname.new(__FILE__).dirname.join("support"), tap.path
|
||||||
end
|
end
|
||||||
|
|
||||||
FileUtils.ln_s Pathname.new(__FILE__).dirname.join("support"), Hbc.default_tap.path
|
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.order = :random
|
config.order = :random
|
||||||
config.include(Test::Helper::Env)
|
config.include(Test::Helper::Env)
|
||||||
|
@ -3,15 +3,17 @@ 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
|
it "adds an error if response is empty" do
|
||||||
cask = TestHelper.test_cask
|
cask = Hbc.load("basic-cask")
|
||||||
TestHelper.fake_response_for(cask.url, "")
|
Hbc::FakeFetcher.fake_response_for(cask.url, "")
|
||||||
checker = Hbc::UrlChecker.new(cask, TestHelper.fake_fetcher)
|
checker = Hbc::UrlChecker.new(cask, Hbc::FakeFetcher)
|
||||||
checker.run
|
checker.run
|
||||||
checker.errors.must_include "timeout while requesting #{cask.url}"
|
checker.errors.must_include "timeout while requesting #{cask.url}"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "properly populates the response code and headers from an http response" do
|
it "properly populates the response code and headers from an http response" do
|
||||||
TestHelper.fake_response_for(TestHelper.test_cask.url, <<-EOS.undent)
|
cask = Hbc.load("basic-cask")
|
||||||
|
|
||||||
|
Hbc::FakeFetcher.fake_response_for(cask.url, <<-EOS.undent)
|
||||||
HTTP/1.1 200 OK
|
HTTP/1.1 200 OK
|
||||||
Content-Type: application/x-apple-diskimage
|
Content-Type: application/x-apple-diskimage
|
||||||
ETag: "b4208f3e84967be4b078ecaa03fba941"
|
ETag: "b4208f3e84967be4b078ecaa03fba941"
|
||||||
@ -19,7 +21,7 @@ describe Hbc::UrlChecker do
|
|||||||
Last-Modified: Sun, 12 Aug 2012 21:17:21 GMT
|
Last-Modified: Sun, 12 Aug 2012 21:17:21 GMT
|
||||||
EOS
|
EOS
|
||||||
|
|
||||||
checker = Hbc::UrlChecker.new(TestHelper.test_cask, TestHelper.fake_fetcher)
|
checker = Hbc::UrlChecker.new(cask, Hbc::FakeFetcher)
|
||||||
checker.run
|
checker.run
|
||||||
checker.response_status.must_equal "HTTP/1.1 200 OK"
|
checker.response_status.must_equal "HTTP/1.1 200 OK"
|
||||||
checker.headers.must_equal("Content-Type" => "application/x-apple-diskimage",
|
checker.headers.must_equal("Content-Type" => "application/x-apple-diskimage",
|
||||||
|
@ -2,20 +2,16 @@ require "bundler"
|
|||||||
require "bundler/setup"
|
require "bundler/setup"
|
||||||
require "pathname"
|
require "pathname"
|
||||||
|
|
||||||
if ENV["HOMEBREW_TESTS_COVERAGE"]
|
require "simplecov" if ENV["HOMEBREW_TESTS_COVERAGE"]
|
||||||
require "simplecov"
|
|
||||||
end
|
|
||||||
|
|
||||||
project_root = Pathname.new(File.expand_path("../..", __FILE__))
|
|
||||||
tap_root = Pathname.new(ENV["HOMEBREW_LIBRARY"]).join("Taps", "caskroom", "homebrew-cask")
|
|
||||||
|
|
||||||
# add Homebrew to load path
|
# add Homebrew to load path
|
||||||
$LOAD_PATH.unshift(File.expand_path("#{ENV["HOMEBREW_REPOSITORY"]}/Library/Homebrew"))
|
$LOAD_PATH.unshift(File.expand_path("#{ENV["HOMEBREW_REPOSITORY"]}/Library/Homebrew"))
|
||||||
|
$LOAD_PATH.unshift(File.expand_path("#{ENV["HOMEBREW_REPOSITORY"]}/Library/Homebrew/test/lib"))
|
||||||
|
|
||||||
require "global"
|
require "global"
|
||||||
|
|
||||||
# add Homebrew-Cask to load path
|
# add Homebrew-Cask to load path
|
||||||
$LOAD_PATH.push(project_root.join("lib").to_s)
|
$LOAD_PATH.push(HOMEBREW_LIBRARY_PATH.join("cask", "lib").to_s)
|
||||||
|
|
||||||
require "test/helper/env"
|
require "test/helper/env"
|
||||||
require "test/helper/shutup"
|
require "test/helper/shutup"
|
||||||
@ -23,12 +19,7 @@ include Test::Helper::Env
|
|||||||
include Test::Helper::Shutup
|
include Test::Helper::Shutup
|
||||||
|
|
||||||
def sudo(*args)
|
def sudo(*args)
|
||||||
%w[/usr/bin/sudo -E --] + Array(args).flatten
|
%w[/usr/bin/sudo -E --] + args.flatten
|
||||||
end
|
|
||||||
|
|
||||||
TEST_TMPDIR = Dir.mktmpdir("homebrew_cask_tests")
|
|
||||||
at_exit do
|
|
||||||
FileUtils.remove_entry(TEST_TMPDIR)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# must be called after testing_env so at_exit hooks are in proper order
|
# must be called after testing_env so at_exit hooks are in proper order
|
||||||
@ -46,30 +37,20 @@ Mocha::Integration::MiniTest.activate
|
|||||||
# our baby
|
# our baby
|
||||||
require "hbc"
|
require "hbc"
|
||||||
|
|
||||||
# override Homebrew locations
|
module Hbc
|
||||||
Hbc.homebrew_prefix = Pathname.new(TEST_TMPDIR).join("prefix")
|
class TestCask < Cask; end
|
||||||
Hbc.homebrew_repository = Hbc.homebrew_prefix
|
|
||||||
|
|
||||||
# Override Tap::TAP_DIRECTORY to use our test Tap directory.
|
|
||||||
class Tap
|
|
||||||
send(:remove_const, :TAP_DIRECTORY)
|
|
||||||
TAP_DIRECTORY = Hbc.homebrew_prefix.join("Library", "Taps")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Hbc.default_tap = Tap.fetch("caskroom", "testcasks")
|
Hbc.cache.mkpath
|
||||||
|
Hbc.caskroom.mkpath
|
||||||
# also jack in some test Casks
|
Hbc.default_tap = Tap.fetch("caskroom", "test").tap do |tap|
|
||||||
FileUtils.ln_s project_root.join("test", "support"), Tap::TAP_DIRECTORY.join("caskroom").tap(&:mkpath).join("homebrew-testcasks")
|
# link test casks
|
||||||
|
FileUtils.mkdir_p tap.path.dirname
|
||||||
|
FileUtils.ln_s Pathname.new(__FILE__).dirname.join("support"), tap.path
|
||||||
|
end
|
||||||
|
|
||||||
# pretend that the caskroom/cask Tap is installed
|
# pretend that the caskroom/cask Tap is installed
|
||||||
FileUtils.ln_s tap_root, Tap::TAP_DIRECTORY.join("caskroom").tap(&:mkpath).join("homebrew-cask")
|
FileUtils.ln_s HOMEBREW_LIBRARY.join("Taps", "caskroom", "homebrew-cask"), Tap.fetch("caskroom", "cask").path
|
||||||
|
|
||||||
# create cache directory
|
|
||||||
Hbc.homebrew_cache = Pathname.new(TEST_TMPDIR).join("cache")
|
|
||||||
Hbc.cache.mkpath
|
|
||||||
|
|
||||||
# our own testy caskroom
|
|
||||||
Hbc.caskroom = Hbc.homebrew_prefix.join("TestCaskroom")
|
|
||||||
|
|
||||||
class TestHelper
|
class TestHelper
|
||||||
# helpers for test Casks to reference local files easily
|
# helpers for test Casks to reference local files easily
|
||||||
@ -81,18 +62,6 @@ class TestHelper
|
|||||||
"file://" + local_binary_path(name)
|
"file://" + local_binary_path(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.test_cask
|
|
||||||
@test_cask ||= Hbc.load("basic-cask")
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.fake_fetcher
|
|
||||||
Hbc::FakeFetcher
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.fake_response_for(*args)
|
|
||||||
Hbc::FakeFetcher.fake_response_for(*args)
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.valid_alias?(candidate)
|
def self.valid_alias?(candidate)
|
||||||
return false unless candidate.symlink?
|
return false unless candidate.symlink?
|
||||||
candidate.readlink.exist?
|
candidate.readlink.exist?
|
||||||
@ -138,8 +107,3 @@ require "support/cleanup"
|
|||||||
require "support/never_sudo_system_command"
|
require "support/never_sudo_system_command"
|
||||||
require "tmpdir"
|
require "tmpdir"
|
||||||
require "tempfile"
|
require "tempfile"
|
||||||
|
|
||||||
# Common superclass for test Casks for when we need to filter them out
|
|
||||||
module Hbc
|
|
||||||
class TestCask < Cask; end
|
|
||||||
end
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user