Improve use of default_prefix? in tests.

This commit is contained in:
Mike McQuaid 2019-01-21 14:33:56 +00:00
parent 4ff0ecd443
commit 234e4aec96
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70
5 changed files with 13 additions and 9 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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