Merge pull request #2258 from reitermarkus/cask-spec-helper
Update Cask `spec_helper`.
This commit is contained in:
commit
8772b021a2
@ -7,19 +7,32 @@ describe Hbc::Artifact::Uninstall do
|
||||
Hbc::Artifact::Uninstall.new(cask, command: Hbc::FakeSystemCommand)
|
||||
}
|
||||
|
||||
let(:absolute_path) { Pathname.new("#{TEST_TMPDIR}/absolute_path") }
|
||||
let(:path_with_tilde) { Pathname.new("#{TEST_TMPDIR}/path_with_tilde") }
|
||||
let(:glob_path1) { Pathname.new("#{TEST_TMPDIR}/glob_path1") }
|
||||
let(:glob_path2) { Pathname.new("#{TEST_TMPDIR}/glob_path2") }
|
||||
let(:dir) { TEST_TMPDIR }
|
||||
let(:absolute_path) { Pathname.new("#{dir}/absolute_path") }
|
||||
let(:path_with_tilde) { Pathname.new("#{dir}/path_with_tilde") }
|
||||
let(:glob_path1) { Pathname.new("#{dir}/glob_path1") }
|
||||
let(:glob_path2) { Pathname.new("#{dir}/glob_path2") }
|
||||
|
||||
before(:each) do
|
||||
FileUtils.touch(absolute_path)
|
||||
FileUtils.touch(path_with_tilde)
|
||||
FileUtils.touch(glob_path1)
|
||||
FileUtils.touch(glob_path2)
|
||||
ENV["HOME"] = TEST_TMPDIR
|
||||
shutup do
|
||||
InstallHelper.install_without_artifacts(cask)
|
||||
around(:each) do |example|
|
||||
begin
|
||||
ENV["HOME"] = dir
|
||||
|
||||
paths = [
|
||||
absolute_path,
|
||||
path_with_tilde,
|
||||
glob_path1,
|
||||
glob_path2,
|
||||
]
|
||||
|
||||
FileUtils.touch paths
|
||||
|
||||
shutup do
|
||||
InstallHelper.install_without_artifacts(cask)
|
||||
end
|
||||
|
||||
example.run
|
||||
ensure
|
||||
FileUtils.rm_f paths
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -8,19 +8,32 @@ describe Hbc::Artifact::Zap do
|
||||
Hbc::Artifact::Zap.new(cask, command: Hbc::FakeSystemCommand)
|
||||
}
|
||||
|
||||
let(:absolute_path) { Pathname.new("#{TEST_TMPDIR}/absolute_path") }
|
||||
let(:path_with_tilde) { Pathname.new("#{TEST_TMPDIR}/path_with_tilde") }
|
||||
let(:glob_path1) { Pathname.new("#{TEST_TMPDIR}/glob_path1") }
|
||||
let(:glob_path2) { Pathname.new("#{TEST_TMPDIR}/glob_path2") }
|
||||
let(:dir) { TEST_TMPDIR }
|
||||
let(:absolute_path) { Pathname.new("#{dir}/absolute_path") }
|
||||
let(:path_with_tilde) { Pathname.new("#{dir}/path_with_tilde") }
|
||||
let(:glob_path1) { Pathname.new("#{dir}/glob_path1") }
|
||||
let(:glob_path2) { Pathname.new("#{dir}/glob_path2") }
|
||||
|
||||
before(:each) do
|
||||
FileUtils.touch(absolute_path)
|
||||
FileUtils.touch(path_with_tilde)
|
||||
FileUtils.touch(glob_path1)
|
||||
FileUtils.touch(glob_path2)
|
||||
ENV["HOME"] = TEST_TMPDIR
|
||||
shutup do
|
||||
InstallHelper.install_without_artifacts(cask)
|
||||
around(:each) do |example|
|
||||
begin
|
||||
ENV["HOME"] = dir
|
||||
|
||||
paths = [
|
||||
absolute_path,
|
||||
path_with_tilde,
|
||||
glob_path1,
|
||||
glob_path2,
|
||||
]
|
||||
|
||||
FileUtils.touch paths
|
||||
|
||||
shutup do
|
||||
InstallHelper.install_without_artifacts(cask)
|
||||
end
|
||||
|
||||
example.run
|
||||
ensure
|
||||
FileUtils.rm_f paths
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -1,5 +1,39 @@
|
||||
describe Hbc::Audit do
|
||||
include AuditMatchers
|
||||
def include_msg?(messages, msg)
|
||||
if msg.is_a?(Regexp)
|
||||
Array(messages).any? { |m| m =~ msg }
|
||||
else
|
||||
Array(messages).include?(msg)
|
||||
end
|
||||
end
|
||||
|
||||
matcher :pass do
|
||||
match do |audit|
|
||||
!audit.errors? && !audit.warnings?
|
||||
end
|
||||
end
|
||||
|
||||
matcher :fail do
|
||||
match(&:errors?)
|
||||
end
|
||||
|
||||
matcher :warn do
|
||||
match do |audit|
|
||||
audit.warnings? && !audit.errors?
|
||||
end
|
||||
end
|
||||
|
||||
matcher :fail_with do |error_msg|
|
||||
match do |audit|
|
||||
include_msg?(audit.errors, error_msg)
|
||||
end
|
||||
end
|
||||
|
||||
matcher :warn_with do |warning_msg|
|
||||
match do |audit|
|
||||
include_msg?(audit.warnings, warning_msg)
|
||||
end
|
||||
end
|
||||
|
||||
let(:cask) { instance_double(Hbc::Cask) }
|
||||
let(:download) { false }
|
||||
|
||||
@ -1,7 +1,12 @@
|
||||
describe Hbc::DSL::Version do
|
||||
include ExpectationsHashHelper
|
||||
|
||||
let(:version) { described_class.new(raw_version) }
|
||||
shared_examples "expectations hash" do |input_name, expectations|
|
||||
expectations.each do |input_value, expected_output|
|
||||
context "when #{input_name} is #{input_value.inspect}" do
|
||||
let(input_name.to_sym) { input_value }
|
||||
it { is_expected.to eq expected_output }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples "version equality" do
|
||||
let(:raw_version) { "1.2.3" }
|
||||
@ -36,6 +41,8 @@ describe Hbc::DSL::Version do
|
||||
end
|
||||
end
|
||||
|
||||
let(:version) { described_class.new(raw_version) }
|
||||
|
||||
describe "#==" do
|
||||
subject { version == other }
|
||||
include_examples "version equality"
|
||||
|
||||
@ -1,32 +1,13 @@
|
||||
require "rspec/its"
|
||||
require "rspec/wait"
|
||||
|
||||
if ENV["HOMEBREW_TESTS_COVERAGE"]
|
||||
require "simplecov"
|
||||
end
|
||||
|
||||
# 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/test/support/lib"))
|
||||
|
||||
require "global"
|
||||
require "test/spec_helper"
|
||||
|
||||
# add Homebrew-Cask to load path
|
||||
$LOAD_PATH.push(HOMEBREW_LIBRARY_PATH.join("cask", "lib").to_s)
|
||||
|
||||
require "test/support/helper/shutup"
|
||||
|
||||
Pathname.glob(HOMEBREW_LIBRARY_PATH.join("cask", "spec", "support", "**", "*.rb")).each(&method(:require))
|
||||
|
||||
require "hbc"
|
||||
|
||||
# create and override default directories
|
||||
Hbc.default_tap = Tap.fetch("caskroom", "spec").tap do |tap|
|
||||
# link test casks
|
||||
FileUtils.mkdir_p tap.path.dirname
|
||||
FileUtils.ln_s TEST_FIXTURE_DIR.join("cask"), tap.path
|
||||
end
|
||||
|
||||
HOMEBREW_CASK_DIRS = [
|
||||
:appdir,
|
||||
:caskroom,
|
||||
@ -38,26 +19,24 @@ HOMEBREW_CASK_DIRS = [
|
||||
].freeze
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.order = :random
|
||||
config.include(Test::Helper::Shutup)
|
||||
config.around(:each) do |example|
|
||||
begin
|
||||
@__dirs = HOMEBREW_CASK_DIRS.map { |dir|
|
||||
Pathname.new(TEST_TMPDIR).join(dir.to_s).tap { |path|
|
||||
dirs = HOMEBREW_CASK_DIRS.map { |dir|
|
||||
Pathname.new(TEST_TMPDIR).join("cask-#{dir}").tap { |path|
|
||||
path.mkpath
|
||||
Hbc.public_send("#{dir}=", path)
|
||||
}
|
||||
}
|
||||
|
||||
@__argv = ARGV.dup
|
||||
@__env = ENV.to_hash # dup doesn't work on ENV
|
||||
Hbc.default_tap = Tap.fetch("caskroom", "spec").tap do |tap|
|
||||
# link test casks
|
||||
FileUtils.mkdir_p tap.path.dirname
|
||||
FileUtils.ln_sf TEST_FIXTURE_DIR.join("cask"), tap.path
|
||||
end
|
||||
|
||||
example.run
|
||||
ensure
|
||||
ARGV.replace(@__argv)
|
||||
ENV.replace(@__env)
|
||||
|
||||
FileUtils.rm_rf @__dirs.map(&:children)
|
||||
FileUtils.rm_rf dirs
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,39 +0,0 @@
|
||||
module AuditMatchers
|
||||
extend RSpec::Matchers::DSL
|
||||
|
||||
matcher :pass do
|
||||
match do |audit|
|
||||
!audit.errors? && !audit.warnings?
|
||||
end
|
||||
end
|
||||
|
||||
matcher :fail do
|
||||
match(&:errors?)
|
||||
end
|
||||
|
||||
matcher :warn do
|
||||
match do |audit|
|
||||
audit.warnings? && !audit.errors?
|
||||
end
|
||||
end
|
||||
|
||||
matcher :fail_with do |error_msg|
|
||||
match do |audit|
|
||||
include_msg?(audit.errors, error_msg)
|
||||
end
|
||||
end
|
||||
|
||||
matcher :warn_with do |warning_msg|
|
||||
match do |audit|
|
||||
include_msg?(audit.warnings, warning_msg)
|
||||
end
|
||||
end
|
||||
|
||||
def include_msg?(messages, msg)
|
||||
if msg.is_a?(Regexp)
|
||||
Array(messages).any? { |m| m =~ msg }
|
||||
else
|
||||
Array(messages).include?(msg)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1,10 +0,0 @@
|
||||
module ExpectationsHashHelper
|
||||
shared_examples "expectations hash" do |input_name, expectations|
|
||||
expectations.each do |input_value, expected_output|
|
||||
context "when #{input_name} is #{input_value.inspect}" do
|
||||
let(input_name.to_sym) { input_value }
|
||||
it { is_expected.to eq expected_output }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user