Refactor spec_helper.

This commit is contained in:
Markus Reiter 2016-10-19 23:01:52 +02:00
parent f04a1b59aa
commit 95c93263e6
2 changed files with 16 additions and 40 deletions

View File

@ -294,8 +294,8 @@ describe Hbc::Audit do
context "when download and verification succeed" do
before do
download.expects(:perform)
verify.expects(:all)
expect(download).to receive(:perform)
expect(verify).to receive(:all)
end
it { should_not fail_with(%r{#{error_msg}}) }
@ -303,7 +303,7 @@ describe Hbc::Audit do
context "when download fails" do
before do
download.expects(:perform).raises(StandardError.new(error_msg))
expect(download).to receive(:perform).and_raise(StandardError.new(error_msg))
end
it { is_expected.to fail_with(%r{#{error_msg}}) }
@ -311,8 +311,8 @@ describe Hbc::Audit do
context "when verification fails" do
before do
download.expects(:perform)
verify.expects(:all).raises(StandardError.new(error_msg))
expect(download).to receive(:perform)
expect(verify).to receive(:all).and_raise(StandardError.new(error_msg))
end
it { is_expected.to fail_with(%r{#{error_msg}}) }
@ -322,7 +322,7 @@ describe Hbc::Audit do
context "when an exception is raised" do
let(:cask) { instance_double(Hbc::Cask) }
before do
cask.expects(:version).raises(StandardError.new)
expect(cask).to receive(:version).and_raise(StandardError.new)
end
it { is_expected.to fail_with(%r{exception while auditing}) }

View File

@ -6,23 +6,19 @@ if ENV["HOMEBREW_TESTS_COVERAGE"]
require "simplecov"
end
project_root = Pathname.new(File.expand_path("../..", __FILE__))
# 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/lib"))
require "global"
# 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/shutup"
Dir["#{project_root}/spec/support/*.rb"].each(&method(:require))
# from Homebrew. Provides expects method.
require "mocha/api"
Pathname.glob(HOMEBREW_LIBRARY_PATH.join("cask", "spec", "support", "*.rb")).each(&method(:require))
require "hbc"
@ -30,35 +26,15 @@ module Hbc
class TestCask < Cask; end
end
TEST_TMPDIR = Dir.mktmpdir("homebrew_cask_tests")
at_exit do
FileUtils.remove_entry(TEST_TMPDIR)
end
# override Homebrew locations
Hbc.homebrew_prefix = Pathname.new(TEST_TMPDIR).join("prefix")
Hbc.homebrew_repository = Hbc.homebrew_prefix
Hbc.binarydir = Hbc.homebrew_prefix.join("binarydir", "bin")
Hbc.appdir = Pathname.new(TEST_TMPDIR).join("appdir")
# Override Tap::TAP_DIRECTORY to use our test Tap directory.
class Tap
send(:remove_const, :TAP_DIRECTORY)
TAP_DIRECTORY = Hbc.homebrew_repository.join("Library", "Taps")
end
Hbc.default_tap = Tap.fetch("caskroom", "speccasks")
Hbc.default_tap.path.dirname.mkpath
# also jack in some test Casks
FileUtils.ln_s project_root.join("spec", "support"), Tap::TAP_DIRECTORY.join("caskroom", "homebrew-speccasks")
# create cache directory
Hbc.homebrew_cache = Pathname.new(TEST_TMPDIR).join("cache")
# create and override default directories
Hbc.appdir = Pathname.new(TEST_TMPDIR).join("Applications").tap(&:mkpath)
Hbc.cache.mkpath
Hbc.caskroom.mkpath
Hbc.default_tap = Tap.fetch("caskroom", "spec").tap do |tap|
tap.path.dirname.mkpath
end
# our own testy caskroom
Hbc.caskroom = Hbc.homebrew_prefix.join("TestCaskroom")
FileUtils.ln_s Pathname.new(__FILE__).dirname.join("support"), Hbc.default_tap.path
RSpec.configure do |config|
config.order = :random