Skip to content

Commit

Permalink
Merge pull request #1095 from Bo98/style-20220616
Browse files Browse the repository at this point in the history
bundle/brewfile: fix ENV style issues
  • Loading branch information
Bo98 authored Jun 16, 2022
2 parents c79b3ae + b0da929 commit 5e7826f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
4 changes: 2 additions & 2 deletions lib/bundle/brewfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ module Brewfile
module_function

def path(dash_writes_to_stdout: false, global: false, file: nil)
env_bundle_file = ENV["HOMEBREW_BUNDLE_FILE"]
env_bundle_file = ENV.fetch("HOMEBREW_BUNDLE_FILE", nil)

filename =
if global
raise "'HOMEBREW_BUNDLE_FILE' cannot be specified with '--global'" if env_bundle_file.present?

"#{ENV["HOME"]}/.Brewfile"
"#{Dir.home}/.Brewfile"
elsif file.present?
handle_file_value(file, dash_writes_to_stdout)
elsif env_bundle_file.present?
Expand Down
12 changes: 2 additions & 10 deletions spec/bundle/brewfile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,7 @@
let(:has_global) { false }

before do
original_method = ENV.method(:[])
allow(ENV).to receive(:[]) do |env_string|
case env_string
when "HOMEBREW_BUNDLE_FILE"
env_bundle_file_value
else
original_method.call(env_string)
end
end
allow(ENV).to receive(:fetch).with("HOMEBREW_BUNDLE_FILE", any_args).and_return(env_bundle_file_value)
end

context "when `file` is specified with a relative path" do
Expand Down Expand Up @@ -127,7 +119,7 @@

context "when `global` is true" do
let(:has_global) { true }
let(:expected_pathname) { Pathname.new("#{ENV["HOME"]}/.Brewfile") }
let(:expected_pathname) { Pathname.new("#{Dir.home}/.Brewfile") }

it "returns the expected path" do
expect(path).to eq(expected_pathname)
Expand Down

0 comments on commit 5e7826f

Please sign in to comment.