diff --git a/Library/Homebrew/test/cmd/search_remote_tap_spec.rb b/Library/Homebrew/test/cmd/search_remote_tap_spec.rb index c47b448bb3..41acc5a690 100644 --- a/Library/Homebrew/test/cmd/search_remote_tap_spec.rb +++ b/Library/Homebrew/test/cmd/search_remote_tap_spec.rb @@ -1,24 +1,45 @@ require "cmd/search" describe Homebrew do - specify "#search_taps" do - # Otherwise the tested method returns [], regardless of our stub - ENV.delete("HOMEBREW_NO_GITHUB_API") + describe "#search_taps" do + before do + ENV.delete("HOMEBREW_NO_GITHUB_API") + end - json_response = { - "items" => [ - { - "path" => "Formula/some-formula.rb", - "repository" => { - "full_name" => "Homebrew/homebrew-foo", + it "does not raise if `HOMEBREW_NO_GITHUB_API` is set" do + ENV["HOMEBREW_NO_GITHUB_API"] = "1" + expect(described_class.search_taps("some-formula")).to match([[], []]) + end + + it "does not raise if the network fails" do + allow(GitHub).to receive(:open_api).and_raise(GitHub::Error) + + expect(described_class.search_taps("some-formula")) + .to match([[], []]) + end + + it "returns Formulae and Casks separately" do + json_response = { + "items" => [ + { + "path" => "Formula/some-formula.rb", + "repository" => { + "full_name" => "Homebrew/homebrew-foo", + }, }, - }, - ], - } + { + "path" => "Casks/some-cask.rb", + "repository" => { + "full_name" => "Homebrew/homebrew-bar", + }, + }, + ], + } - allow(GitHub).to receive(:open_api).and_yield(json_response) + allow(GitHub).to receive(:open_api).and_yield(json_response) - expect(described_class.search_taps("some-formula")) - .to match([["homebrew/foo/some-formula"], []]) + expect(described_class.search_taps("some-formula")) + .to match([["homebrew/foo/some-formula"], ["homebrew/bar/some-cask"]]) + end end end diff --git a/Library/Homebrew/test/cmd/search_spec.rb b/Library/Homebrew/test/cmd/search_spec.rb index 1e1ef8e180..9e77fc6b61 100644 --- a/Library/Homebrew/test/cmd/search_spec.rb +++ b/Library/Homebrew/test/cmd/search_spec.rb @@ -1,3 +1,5 @@ +require "cmd/search" + describe "brew search", :integration_test do before do setup_test_formula "testball" @@ -63,4 +65,18 @@ describe "brew search", :integration_test do .and be_a_success end end + + describe "::query_regexp" do + it "correctly parses a regex query" do + expect(Homebrew.query_regexp("/^query$/")).to eq(/^query$/) + end + + it "correctly converts a query string to a regex" do + expect(Homebrew.query_regexp("query")).to eq(/.*query.*/i) + end + + it "raises an error if the query is an invalid regex" do + expect { Homebrew.query_regexp("/+/") }.to raise_error(/not a valid regex/) + end + end end