mirror of
https://github.com/Homebrew/brew.git
synced 2026-08-12 22:29:27 +04:00
- Make every statically-poked method public and call it directly, keeping `public_send` only for dynamically-named public methods. - Read and write state through public `attr_*` accessors instead of instance variable reflection. - Enable `Homebrew/NoSendInTests` and `Homebrew/NoInstanceVariableAccessInTests` now the test suite is clean, so neither pattern creeps back in. - Keep rare justified disables, e.g. `Module#remove_const` is private core Ruby and raw memoisation state has no accessor.
65 lines
2.1 KiB
Ruby
65 lines
2.1 KiB
Ruby
# typed: true
|
|
# frozen_string_literal: true
|
|
|
|
require "cmd/search"
|
|
require "cmd/shared_examples/args_parse"
|
|
|
|
RSpec.describe Homebrew::Cmd::SearchCmd do
|
|
it_behaves_like "parseable arguments"
|
|
|
|
it "finds formula in search", :integration_test, :no_api do
|
|
setup_test_formula "testball"
|
|
|
|
expect { brew "search", "testball" }
|
|
.to output(/testball/).to_stdout
|
|
.and be_a_success
|
|
end
|
|
|
|
it "shows missing cask descriptions in description searches" do
|
|
expect(Homebrew::Search).to receive(:search_descriptions)
|
|
.with("testball", anything, show_missing: true)
|
|
|
|
described_class.new(["--desc", "testball"]).run
|
|
end
|
|
|
|
describe "::print_missing_formula_help" do
|
|
let(:search_cmd) { described_class.new([""]) }
|
|
|
|
context "when $stdout is not a TTY" do
|
|
before { allow_any_instance_of(StringIO).to receive(:tty?).and_return(false) }
|
|
|
|
it "skips" do
|
|
expect { search_cmd.print_missing_formula_help("formula", false) }
|
|
.not_to output.to_stdout
|
|
end
|
|
end
|
|
|
|
context "when $stdout is a TTY" do
|
|
before { allow_any_instance_of(StringIO).to receive(:tty?).and_return(true) }
|
|
|
|
it "skips a regex query" do
|
|
expect { search_cmd.print_missing_formula_help("/formula/", false) }
|
|
.not_to output.to_stdout
|
|
end
|
|
|
|
it "skips if there is not a reason" do
|
|
allow(Homebrew::MissingFormula).to receive(:reason).and_return(nil)
|
|
expect { search_cmd.print_missing_formula_help("formula", false) }
|
|
.not_to output.to_stdout
|
|
end
|
|
|
|
it "prints additional output if `found_matches` is true" do
|
|
allow(Homebrew::MissingFormula).to receive(:reason).and_return("Reason")
|
|
expect { search_cmd.print_missing_formula_help("formula", true) }
|
|
.to output("\nIf you meant \"formula\" specifically:\nReason\n").to_stdout
|
|
end
|
|
|
|
it "only prints reason if `found_matches` is false" do
|
|
allow(Homebrew::MissingFormula).to receive(:reason).and_return("Reason")
|
|
expect { search_cmd.print_missing_formula_help("formula", false) }
|
|
.to output("Reason\n").to_stdout
|
|
end
|
|
end
|
|
end
|
|
end
|