diff --git a/Library/Homebrew/test/search_spec.rb b/Library/Homebrew/test/search_spec.rb index dc67320fdebac..39b10cb7dc9ad 100644 --- a/Library/Homebrew/test/search_spec.rb +++ b/Library/Homebrew/test/search_spec.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true require "search" +require "descriptions" +require "cmd/desc" RSpec.describe Homebrew::Search do describe "#query_regexp" do @@ -57,4 +59,34 @@ end end end + + describe "#search_descriptions" do + let(:args) { Homebrew::Cmd::Desc.new(["min_arg_placeholder"]).args } + + context "with api" do + let(:api_formulae) do + { "testball" => { "desc" => "Some test" } } + end + + let(:api_casks) do + { "testball" => { "desc" => "Some test", "name" => ["Test Ball"] } } + end + + before do + allow(Homebrew::API::Formula).to receive(:all_formulae).and_return(api_formulae) + allow(Homebrew::API::Cask).to receive(:all_casks).and_return(api_casks) + end + + it "searches formula descriptions" do + expect { described_class.search_descriptions(described_class.query_regexp("some"), args) } + .to output(/testball: Some test/).to_stdout + end + + it "searches cask descriptions", :needs_macos do + expect { described_class.search_descriptions(described_class.query_regexp("ball"), args) } + .to output(/testball: \(Test Ball\) Some test/).to_stdout + .and not_to_output(/testball: Some test/).to_stdout + end + end + end end