Fix stub orders, :env_var reference

This commit is contained in:
Ben Muschol 2019-02-25 14:54:31 -05:00
parent c7831a457d
commit 4c6ca1c5d9
2 changed files with 5 additions and 5 deletions

View File

@ -234,7 +234,7 @@ module Homebrew
next if violations.count < 2 next if violations.count < 2
env_var_options = violations.select do |option| env_var_options = violations.select do |option|
@switch_sources[option_to_name(option)] == :env_var @switch_sources[option_to_name(option)] == :env
end end
select_cli_arg = violations.count - env_var_options.count == 1 select_cli_arg = violations.count - env_var_options.count == 1

View File

@ -179,19 +179,19 @@ describe Homebrew::CLI::Parser do
end end
it "prioritizes cli arguments over env vars when they conflict" do it "prioritizes cli arguments over env vars when they conflict" do
allow(ENV).to receive(:[]).with("HOMEBREW_SWITCH_A").and_return("1")
allow(ENV).to receive(:[]).with("HOMEBREW_SWITCH_B").and_return("0")
allow(ENV).to receive(:[]) allow(ENV).to receive(:[])
allow(ENV).to receive(:[]).with("HOMEBREW_SWITCH_A").and_return("1")
allow(ENV).to receive(:[]).with("HOMEBREW_SWITCH_B").and_return(nil)
parser.parse(["--switch-b"]) parser.parse(["--switch-b"])
expect(Homebrew.args.switch_a).to be_falsy expect(Homebrew.args.switch_a).to be_falsy
expect(Homebrew.args).to be_switch_b expect(Homebrew.args).to be_switch_b
end end
it "raises an exception on constraint violation when both are env vars" do it "raises an exception on constraint violation when both are env vars" do
allow(ENV).to receive(:[])
allow(ENV).to receive(:[]).with("HOMEBREW_SWITCH_A").and_return("1") allow(ENV).to receive(:[]).with("HOMEBREW_SWITCH_A").and_return("1")
allow(ENV).to receive(:[]).with("HOMEBREW_SWITCH_B").and_return("1") allow(ENV).to receive(:[]).with("HOMEBREW_SWITCH_B").and_return("1")
allow(ENV).to receive(:[]) expect { parser.parse([]) }.to raise_error(Homebrew::CLI::OptionConflictError)
expect { parser.parse(["--switch-a", "--switch-b"]) }.to raise_error(Homebrew::CLI::OptionConflictError)
end end
end end