|
5 | 5 | require "cmd/shared_examples/args_parse" |
6 | 6 |
|
7 | 7 | RSpec.describe Homebrew::Cmd::Prefix do |
| 8 | + let(:klass) { Homebrew::Cmd::Prefix } |
| 9 | + |
8 | 10 | it_behaves_like "parseable arguments" |
9 | 11 |
|
10 | 12 | it "prints Homebrew's prefix", :integration_test do |
|
14 | 16 | .and be_a_success |
15 | 17 | end |
16 | 18 |
|
17 | | - it "prints the prefix for a Formula", :integration_test, :needs_homebrew_core do |
18 | | - expect { brew_sh "--prefix", "wget" } |
19 | | - .to output("#{ENV.fetch("HOMEBREW_PREFIX")}/opt/wget\n").to_stdout |
| 19 | + it "prints the prefix for a Formula" do |
| 20 | + cmd = klass.new(["testball"]) |
| 21 | + allow(cmd.args.named).to receive(:to_resolved_formulae) |
| 22 | + .and_return([instance_double(Formula, opt_prefix: HOMEBREW_PREFIX/"opt/testball")]) |
| 23 | + |
| 24 | + expect { cmd.run } |
| 25 | + .to output("#{HOMEBREW_PREFIX}/opt/testball\n").to_stdout |
20 | 26 | .and not_to_output.to_stderr |
21 | | - .and be_a_success |
22 | 27 | end |
23 | 28 |
|
24 | | - it "errors if the given Formula doesn't exist", :integration_test do |
25 | | - expect { brew "--prefix", "nonexistent" } |
26 | | - .to output(/No available formula/).to_stderr |
27 | | - .and not_to_output.to_stdout |
28 | | - .and be_a_failure |
| 29 | + it "errors if the given Formula doesn't exist" do |
| 30 | + cmd = klass.new(["nonexistent"]) |
| 31 | + allow(cmd.args.named).to receive(:to_resolved_formulae) |
| 32 | + .and_raise(FormulaUnavailableError.new("nonexistent")) |
| 33 | + |
| 34 | + expect { cmd.run }.to raise_error(FormulaUnavailableError, /nonexistent/) |
29 | 35 | end |
30 | 36 |
|
31 | | - it "prints a warning when `--installed` is used and the given Formula is not installed", :integration_test do |
32 | | - expect { brew "--prefix", "--installed", testball } |
33 | | - .to not_to_output.to_stdout |
34 | | - .and output(/testball/).to_stderr |
35 | | - .and be_a_failure |
| 37 | + it "prints a warning when `--installed` is used and the given Formula is not installed" do |
| 38 | + cmd = klass.new(["--installed", "testball"]) |
| 39 | + allow(cmd.args.named).to receive(:to_resolved_formulae).and_return([ |
| 40 | + instance_double(Formula, name: "testball", opt_prefix: HOMEBREW_PREFIX/"opt/testball", optlinked?: false), |
| 41 | + ]) |
| 42 | + |
| 43 | + expect { cmd.run } |
| 44 | + .to raise_error(NotAKegError, /testball/) |
36 | 45 | end |
37 | 46 | end |
0 commit comments