aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMarkus Reiter2017-03-05 05:12:24 +0100
committerGitHub2017-03-05 05:12:24 +0100
commit8772b021a28074a70f84fc19d83af6d897c6fb51 (patch)
tree2e8d1ffd26404f953afc8dbf8dd154dc91181bee /Library
parent83188c625d7f179bb35839cf90b1b74956fb89af (diff)
parent551993a9c79912ed48c3d649414eb1e6d1b980b0 (diff)
downloadbrew-8772b021a28074a70f84fc19d83af6d897c6fb51.tar.bz2
Merge pull request #2258 from reitermarkus/cask-spec-helper
Update Cask `spec_helper`.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/cask/spec/cask/artifact/uninstall_spec.rb39
-rw-r--r--Library/Homebrew/cask/spec/cask/artifact/zap_spec.rb39
-rw-r--r--Library/Homebrew/cask/spec/cask/audit_spec.rb36
-rw-r--r--Library/Homebrew/cask/spec/cask/dsl/version_spec.rb13
-rw-r--r--Library/Homebrew/cask/spec/spec_helper.rb39
-rw-r--r--Library/Homebrew/cask/spec/support/audit_matchers.rb39
-rw-r--r--Library/Homebrew/cask/spec/support/expectations_hash_helper.rb10
7 files changed, 106 insertions, 109 deletions
diff --git a/Library/Homebrew/cask/spec/cask/artifact/uninstall_spec.rb b/Library/Homebrew/cask/spec/cask/artifact/uninstall_spec.rb
index e3595621d..4c09ea302 100644
--- a/Library/Homebrew/cask/spec/cask/artifact/uninstall_spec.rb
+++ b/Library/Homebrew/cask/spec/cask/artifact/uninstall_spec.rb
@@ -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") }
-
- 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)
+ 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") }
+
+ 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
diff --git a/Library/Homebrew/cask/spec/cask/artifact/zap_spec.rb b/Library/Homebrew/cask/spec/cask/artifact/zap_spec.rb
index c49cebbb8..47090c99a 100644
--- a/Library/Homebrew/cask/spec/cask/artifact/zap_spec.rb
+++ b/Library/Homebrew/cask/spec/cask/artifact/zap_spec.rb
@@ -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") }
-
- 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)
+ 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") }
+
+ 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
diff --git a/Library/Homebrew/cask/spec/cask/audit_spec.rb b/Library/Homebrew/cask/spec/cask/audit_spec.rb
index 9eb9f0136..222294bdc 100644
--- a/Library/Homebrew/cask/spec/cask/audit_spec.rb
+++ b/Library/Homebrew/cask/spec/cask/audit_spec.rb
@@ -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 }
diff --git a/Library/Homebrew/cask/spec/cask/dsl/version_spec.rb b/Library/Homebrew/cask/spec/cask/dsl/version_spec.rb
index 1dfbb4467..acf3db3ab 100644
--- a/Library/Homebrew/cask/spec/cask/dsl/version_spec.rb
+++ b/Library/Homebrew/cask/spec/cask/dsl/version_spec.rb
@@ -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"
diff --git a/Library/Homebrew/cask/spec/spec_helper.rb b/Library/Homebrew/cask/spec/spec_helper.rb
index 985a5335f..ca0b69d33 100644
--- a/Library/Homebrew/cask/spec/spec_helper.rb
+++ b/Library/Homebrew/cask/spec/spec_helper.rb
@@ -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
diff --git a/Library/Homebrew/cask/spec/support/audit_matchers.rb b/Library/Homebrew/cask/spec/support/audit_matchers.rb
deleted file mode 100644
index fc1e0e876..000000000
--- a/Library/Homebrew/cask/spec/support/audit_matchers.rb
+++ /dev/null
@@ -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
diff --git a/Library/Homebrew/cask/spec/support/expectations_hash_helper.rb b/Library/Homebrew/cask/spec/support/expectations_hash_helper.rb
deleted file mode 100644
index 726b1d053..000000000
--- a/Library/Homebrew/cask/spec/support/expectations_hash_helper.rb
+++ /dev/null
@@ -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