From 234e4aec96297145e1760bc3d8ff6cc9f6f64713 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Mon, 21 Jan 2019 14:33:56 +0000 Subject: [PATCH] Improve use of default_prefix? in tests. --- Library/Homebrew/os/linux/global.rb | 2 +- Library/Homebrew/test/diagnostic_checks_spec.rb | 2 +- Library/Homebrew/test/support/lib/config.rb | 5 +++++ Library/Homebrew/test/utils/analytics_spec.rb | 11 +++++------ Library/Homebrew/utils/analytics.rb | 2 +- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/os/linux/global.rb b/Library/Homebrew/os/linux/global.rb index 67d80e4560..39114fab57 100644 --- a/Library/Homebrew/os/linux/global.rb +++ b/Library/Homebrew/os/linux/global.rb @@ -1,5 +1,5 @@ module Homebrew - DEFAULT_PREFIX = if ENV["HOMEBREW_FORCE_HOMEBREW_ON_LINUX"] + DEFAULT_PREFIX ||= if ENV["HOMEBREW_FORCE_HOMEBREW_ON_LINUX"] "/usr/local".freeze else "/home/linuxbrew/.linuxbrew".freeze diff --git a/Library/Homebrew/test/diagnostic_checks_spec.rb b/Library/Homebrew/test/diagnostic_checks_spec.rb index 74f0b57ab0..06be59c5c4 100644 --- a/Library/Homebrew/test/diagnostic_checks_spec.rb +++ b/Library/Homebrew/test/diagnostic_checks_spec.rb @@ -164,7 +164,7 @@ describe Homebrew::Diagnostic::Checks do end specify "#check_homebrew_prefix" do - # the integration tests are run in a special prefix + allow(Homebrew).to receive(:default_prefix?).and_return(false) expect(subject.check_homebrew_prefix) .to match("Your Homebrew's prefix is not #{Homebrew::DEFAULT_PREFIX}") end diff --git a/Library/Homebrew/test/support/lib/config.rb b/Library/Homebrew/test/support/lib/config.rb index a5ad271801..6d6de3368e 100644 --- a/Library/Homebrew/test/support/lib/config.rb +++ b/Library/Homebrew/test/support/lib/config.rb @@ -41,3 +41,8 @@ PATCH_B_SHA256 = "57958271bb802a59452d0816e0670d16c8b70bdf6530bcf6f78726489ad89b TEST_SHA1 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef".freeze TEST_SHA256 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef".freeze + +# For testing's sake always assume the default prefix +module Homebrew + DEFAULT_PREFIX = HOMEBREW_PREFIX.to_s.freeze +end diff --git a/Library/Homebrew/test/utils/analytics_spec.rb b/Library/Homebrew/test/utils/analytics_spec.rb index 3ec68224b4..29bdd04387 100644 --- a/Library/Homebrew/test/utils/analytics_spec.rb +++ b/Library/Homebrew/test/utils/analytics_spec.rb @@ -9,19 +9,18 @@ describe Utils::Analytics do end it "returns OS_VERSION and prefix when HOMEBREW_PREFIX is a custom prefix" do - stub_const("HOMEBREW_PREFIX", "blah") + allow(Homebrew).to receive(:default_prefix?).and_return(false) expect(described_class.os_prefix_ci).to include("#{OS_VERSION}, #{described_class.custom_prefix_label}") end + it "does not include prefix when HOMEBREW_PREFIX is the default prefix" do + expect(described_class.os_prefix_ci).not_to include(described_class.custom_prefix_label) + end + it "includes CI when ENV['CI'] is set" do ENV["CI"] = "true" expect(described_class.os_prefix_ci).to include("CI") end - - it "does not include prefix when HOMEBREW_PREFIX is the default prefix" do - stub_const("HOMEBREW_PREFIX", Homebrew::DEFAULT_PREFIX) - expect(described_class.os_prefix_ci).not_to include(described_class.custom_prefix_label) - end end end diff --git a/Library/Homebrew/utils/analytics.rb b/Library/Homebrew/utils/analytics.rb index 7283b5aece..31174451e1 100644 --- a/Library/Homebrew/utils/analytics.rb +++ b/Library/Homebrew/utils/analytics.rb @@ -16,7 +16,7 @@ module Utils def os_prefix_ci @os_prefix_ci ||= begin os = OS_VERSION - prefix = ", #{custom_prefix_label}" if Homebrew.default_prefix? + prefix = ", #{custom_prefix_label}" unless Homebrew.default_prefix? ci = ", CI" if ENV["CI"] "#{os}#{prefix}#{ci}" end