diff options
| author | Markus Reiter | 2016-10-20 09:07:03 +0200 |
|---|---|---|
| committer | GitHub | 2016-10-20 09:07:03 +0200 |
| commit | 2b049006fae516a30424a438f92e08acb88b6999 (patch) | |
| tree | 51218cfac7aa77106213aab16530b4ba35a69119 /Library | |
| parent | fcd2f6b2715340c3eb3aebfaaf9a4df623317a09 (diff) | |
| parent | 95c93263e61a756441fcf51516681fb8032d1662 (diff) | |
| download | brew-2b049006fae516a30424a438f92e08acb88b6999.tar.bz2 | |
Merge pull request #1330 from reitermarkus/spec-helper
Refactor `spec_helper`.
Diffstat (limited to 'Library')
21 files changed, 18 insertions, 74 deletions
diff --git a/Library/Homebrew/cask/.rspec b/Library/Homebrew/cask/.rspec deleted file mode 100644 index 83e16f804..000000000 --- a/Library/Homebrew/cask/.rspec +++ /dev/null @@ -1,2 +0,0 @@ ---color ---require spec_helper diff --git a/Library/Homebrew/cask/cmd/brew-cask-tests.rb b/Library/Homebrew/cask/cmd/brew-cask-tests.rb index ce62b5d84..4840ab451 100755 --- a/Library/Homebrew/cask/cmd/brew-cask-tests.rb +++ b/Library/Homebrew/cask/cmd/brew-cask-tests.rb @@ -25,6 +25,8 @@ repo_root.cd do if rspec run_tests "parallel_rspec", Dir["spec/**/*_spec.rb"], %w[ + --color + --require spec_helper --format progress --format ParallelTests::RSpec::RuntimeLogger --out tmp/parallel_runtime_rspec.log diff --git a/Library/Homebrew/cask/spec/cask/artifact/binary_spec.rb b/Library/Homebrew/cask/spec/cask/artifact/binary_spec.rb index 38b61a7e1..af6973777 100644 --- a/Library/Homebrew/cask/spec/cask/artifact/binary_spec.rb +++ b/Library/Homebrew/cask/spec/cask/artifact/binary_spec.rb @@ -1,5 +1,3 @@ -require "spec_helper" - describe Hbc::Artifact::Binary do let(:cask) { Hbc.load("with-binary").tap do |cask| diff --git a/Library/Homebrew/cask/spec/cask/audit_spec.rb b/Library/Homebrew/cask/spec/cask/audit_spec.rb index 7094ea3a8..c5433d0a2 100644 --- a/Library/Homebrew/cask/spec/cask/audit_spec.rb +++ b/Library/Homebrew/cask/spec/cask/audit_spec.rb @@ -1,5 +1,3 @@ -require "spec_helper" - describe Hbc::Audit do include AuditMatchers include Sha256Helper @@ -296,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}}) } @@ -305,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}}) } @@ -313,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}}) } @@ -324,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}) } diff --git a/Library/Homebrew/cask/spec/cask/cask_spec.rb b/Library/Homebrew/cask/spec/cask/cask_spec.rb index f31bee023..d470c6ec3 100644 --- a/Library/Homebrew/cask/spec/cask/cask_spec.rb +++ b/Library/Homebrew/cask/spec/cask/cask_spec.rb @@ -1,5 +1,3 @@ -require "spec_helper" - describe Hbc::Cask do let(:cask) { described_class.new("versioned-cask") } diff --git a/Library/Homebrew/cask/spec/cask/cli/cleanup_spec.rb b/Library/Homebrew/cask/spec/cask/cli/cleanup_spec.rb index fe8bb2d4d..58ce5b7a3 100644 --- a/Library/Homebrew/cask/spec/cask/cli/cleanup_spec.rb +++ b/Library/Homebrew/cask/spec/cask/cli/cleanup_spec.rb @@ -1,5 +1,3 @@ -require "spec_helper" - describe Hbc::CLI::Cleanup do let(:cache_location) { Pathname.new(Dir.mktmpdir).realpath } let(:cleanup_outdated) { false } diff --git a/Library/Homebrew/cask/spec/cask/cli/doctor_spec.rb b/Library/Homebrew/cask/spec/cask/cli/doctor_spec.rb index 3c9c66150..b452fdb19 100644 --- a/Library/Homebrew/cask/spec/cask/cli/doctor_spec.rb +++ b/Library/Homebrew/cask/spec/cask/cli/doctor_spec.rb @@ -1,4 +1,3 @@ -require "spec_helper" require "hbc/version" describe Hbc::CLI::Doctor do diff --git a/Library/Homebrew/cask/spec/cask/cli/style_spec.rb b/Library/Homebrew/cask/spec/cask/cli/style_spec.rb index dbd6970d5..b0d34576a 100644 --- a/Library/Homebrew/cask/spec/cask/cli/style_spec.rb +++ b/Library/Homebrew/cask/spec/cask/cli/style_spec.rb @@ -1,5 +1,4 @@ require "English" -require "spec_helper" describe Hbc::CLI::Style do let(:args) { [] } diff --git a/Library/Homebrew/cask/spec/cask/cli_spec.rb b/Library/Homebrew/cask/spec/cask/cli_spec.rb index 1bdc57b6e..9964275f1 100644 --- a/Library/Homebrew/cask/spec/cask/cli_spec.rb +++ b/Library/Homebrew/cask/spec/cask/cli_spec.rb @@ -1,5 +1,3 @@ -require "spec_helper" - describe Hbc::CLI do it "lists the taps for Casks that show up in two taps" do listing = Hbc::CLI.nice_listing(%w[ diff --git a/Library/Homebrew/cask/spec/cask/download_strategy_spec.rb b/Library/Homebrew/cask/spec/cask/download_strategy_spec.rb index 9b1c4d8e3..f867dc19f 100644 --- a/Library/Homebrew/cask/spec/cask/download_strategy_spec.rb +++ b/Library/Homebrew/cask/spec/cask/download_strategy_spec.rb @@ -1,5 +1,3 @@ -require "spec_helper" - describe "download strategies" do let(:url) { "http://example.com/cask.dmg" } let(:url_options) { Hash.new } diff --git a/Library/Homebrew/cask/spec/cask/dsl/version_spec.rb b/Library/Homebrew/cask/spec/cask/dsl/version_spec.rb index b0efa2f10..1dfbb4467 100644 --- a/Library/Homebrew/cask/spec/cask/dsl/version_spec.rb +++ b/Library/Homebrew/cask/spec/cask/dsl/version_spec.rb @@ -1,5 +1,3 @@ -require "spec_helper" - describe Hbc::DSL::Version do include ExpectationsHashHelper diff --git a/Library/Homebrew/cask/spec/cask/macos_spec.rb b/Library/Homebrew/cask/spec/cask/macos_spec.rb index 902c80d7a..a1ebb0a9e 100644 --- a/Library/Homebrew/cask/spec/cask/macos_spec.rb +++ b/Library/Homebrew/cask/spec/cask/macos_spec.rb @@ -1,5 +1,3 @@ -require "spec_helper" - describe MacOS do it "says '/' is undeletable" do expect(MacOS).to be_undeletable( diff --git a/Library/Homebrew/cask/spec/cask/scopes_spec.rb b/Library/Homebrew/cask/spec/cask/scopes_spec.rb index 0e592c990..12c1a697f 100644 --- a/Library/Homebrew/cask/spec/cask/scopes_spec.rb +++ b/Library/Homebrew/cask/spec/cask/scopes_spec.rb @@ -1,5 +1,3 @@ -require "spec_helper" - describe Hbc::Scopes do describe "installed" do let(:fake_caskroom) { Pathname(Dir.mktmpdir) } diff --git a/Library/Homebrew/cask/spec/cask/system_command_result_spec.rb b/Library/Homebrew/cask/spec/cask/system_command_result_spec.rb index 7eb4fb722..a6a51301a 100644 --- a/Library/Homebrew/cask/spec/cask/system_command_result_spec.rb +++ b/Library/Homebrew/cask/spec/cask/system_command_result_spec.rb @@ -1,5 +1,3 @@ -require "spec_helper" - describe Hbc::SystemCommand::Result do describe "::_parse_plist" do let(:command) { Hbc::SystemCommand.new("/usr/bin/true", {}) } diff --git a/Library/Homebrew/cask/spec/cask/system_command_spec.rb b/Library/Homebrew/cask/spec/cask/system_command_spec.rb index c29102305..2af095853 100644 --- a/Library/Homebrew/cask/spec/cask/system_command_spec.rb +++ b/Library/Homebrew/cask/spec/cask/system_command_spec.rb @@ -1,5 +1,3 @@ -require "spec_helper" - describe Hbc::SystemCommand do describe "when the exit code is 0" do describe "its result" do diff --git a/Library/Homebrew/cask/spec/cask/underscore_supporting_uri_spec.rb b/Library/Homebrew/cask/spec/cask/underscore_supporting_uri_spec.rb index a8756fde0..a8e2925db 100644 --- a/Library/Homebrew/cask/spec/cask/underscore_supporting_uri_spec.rb +++ b/Library/Homebrew/cask/spec/cask/underscore_supporting_uri_spec.rb @@ -1,5 +1,3 @@ -require "spec_helper" - describe Hbc::UnderscoreSupportingURI do describe "parse" do it "works like normal on normal URLs" do diff --git a/Library/Homebrew/cask/spec/cask/verify/checksum_spec.rb b/Library/Homebrew/cask/spec/cask/verify/checksum_spec.rb index a5772b21d..a379dafb9 100644 --- a/Library/Homebrew/cask/spec/cask/verify/checksum_spec.rb +++ b/Library/Homebrew/cask/spec/cask/verify/checksum_spec.rb @@ -1,5 +1,3 @@ -require "spec_helper" - describe Hbc::Verify::Checksum do include Sha256Helper diff --git a/Library/Homebrew/cask/spec/cask/verify_spec.rb b/Library/Homebrew/cask/spec/cask/verify_spec.rb index 5925119ed..fc62b749c 100644 --- a/Library/Homebrew/cask/spec/cask/verify_spec.rb +++ b/Library/Homebrew/cask/spec/cask/verify_spec.rb @@ -1,5 +1,3 @@ -require "spec_helper" - describe Hbc::Verify do let(:cask) { double("cask") } diff --git a/Library/Homebrew/cask/spec/formatter_spec.rb b/Library/Homebrew/cask/spec/formatter_spec.rb index 7e143d933..2c1de9b74 100644 --- a/Library/Homebrew/cask/spec/formatter_spec.rb +++ b/Library/Homebrew/cask/spec/formatter_spec.rb @@ -1,4 +1,3 @@ -require "spec_helper" require "utils/formatter" require "utils/tty" diff --git a/Library/Homebrew/cask/spec/locale_spec.rb b/Library/Homebrew/cask/spec/locale_spec.rb index 98a2de913..69914e23c 100644 --- a/Library/Homebrew/cask/spec/locale_spec.rb +++ b/Library/Homebrew/cask/spec/locale_spec.rb @@ -1,4 +1,3 @@ -require "spec_helper" require "locale" describe Locale do diff --git a/Library/Homebrew/cask/spec/spec_helper.rb b/Library/Homebrew/cask/spec/spec_helper.rb index ebd60124c..b71e1ecae 100644 --- a/Library/Homebrew/cask/spec/spec_helper.rb +++ b/Library/Homebrew/cask/spec/spec_helper.rb @@ -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 |
