diff --git a/Library/Homebrew/cli_parser.rb b/Library/Homebrew/cli_parser.rb index f35328a574..5ed6e4bd85 100644 --- a/Library/Homebrew/cli_parser.rb +++ b/Library/Homebrew/cli_parser.rb @@ -234,7 +234,7 @@ module Homebrew next if violations.count < 2 env_var_options = violations.select do |option| - @switch_sources[option_to_name(option)] == :env_var + @switch_sources[option_to_name(option)] == :env end select_cli_arg = violations.count - env_var_options.count == 1 diff --git a/Library/Homebrew/test/cli_parser_spec.rb b/Library/Homebrew/test/cli_parser_spec.rb index c5c1f25764..c4b1dfe033 100644 --- a/Library/Homebrew/test/cli_parser_spec.rb +++ b/Library/Homebrew/test/cli_parser_spec.rb @@ -179,19 +179,19 @@ describe Homebrew::CLI::Parser do end 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(:[]).with("HOMEBREW_SWITCH_A").and_return("1") + allow(ENV).to receive(:[]).with("HOMEBREW_SWITCH_B").and_return(nil) parser.parse(["--switch-b"]) expect(Homebrew.args.switch_a).to be_falsy expect(Homebrew.args).to be_switch_b end 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_B").and_return("1") - allow(ENV).to receive(:[]) - expect { parser.parse(["--switch-a", "--switch-b"]) }.to raise_error(Homebrew::CLI::OptionConflictError) + expect { parser.parse([]) }.to raise_error(Homebrew::CLI::OptionConflictError) end end