From e10e1f631964efaff619cec8a63434b9cde6f37b Mon Sep 17 00:00:00 2001 From: Ryan Rotter Date: Sun, 30 Jun 2024 21:09:30 -0400 Subject: [PATCH] test Search.search_descriptions --- Library/Homebrew/test/search_spec.rb | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Library/Homebrew/test/search_spec.rb b/Library/Homebrew/test/search_spec.rb index dc67320fdebac7..f34763ff16e5d5 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,32 @@ 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 "successfully searches descriptions" 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 + + expect { described_class.search_descriptions(described_class.query_regexp("some"), args) } + .to output(/testball: Some test/).to_stdout + end + end + end end