2020-10-10 14:16:11 +02:00
|
|
|
# typed: false
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-06-02 20:49:14 +02:00
|
|
|
require "search"
|
|
|
|
|
|
|
|
describe Homebrew::Search do
|
|
|
|
subject(:mod) { Object.new }
|
|
|
|
|
|
|
|
before do
|
|
|
|
mod.extend(described_class)
|
|
|
|
end
|
2017-02-21 05:13:05 +01:00
|
|
|
|
2018-06-02 02:12:40 +02:00
|
|
|
describe "#search_taps" do
|
|
|
|
before do
|
|
|
|
ENV.delete("HOMEBREW_NO_GITHUB_API")
|
|
|
|
end
|
2017-08-31 22:29:36 -07:00
|
|
|
|
2018-06-02 02:12:40 +02:00
|
|
|
it "does not raise if `HOMEBREW_NO_GITHUB_API` is set" do
|
|
|
|
ENV["HOMEBREW_NO_GITHUB_API"] = "1"
|
2018-06-06 13:24:55 +02:00
|
|
|
expect(mod.search_taps("some-formula")).to match(formulae: [], casks: [])
|
2018-06-02 02:12:40 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does not raise if the network fails" do
|
|
|
|
allow(GitHub).to receive(:open_api).and_raise(GitHub::Error)
|
|
|
|
|
2018-06-02 20:49:14 +02:00
|
|
|
expect(mod.search_taps("some-formula"))
|
2018-06-06 13:24:55 +02:00
|
|
|
.to match(formulae: [], casks: [])
|
2018-06-02 02:12:40 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns Formulae and Casks separately" do
|
|
|
|
json_response = {
|
|
|
|
"items" => [
|
|
|
|
{
|
2018-11-02 17:18:07 +00:00
|
|
|
"path" => "Formula/some-formula.rb",
|
2018-06-02 02:12:40 +02:00
|
|
|
"repository" => {
|
|
|
|
"full_name" => "Homebrew/homebrew-foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2018-11-02 17:18:07 +00:00
|
|
|
"path" => "Casks/some-cask.rb",
|
2018-06-02 02:12:40 +02:00
|
|
|
"repository" => {
|
|
|
|
"full_name" => "Homebrew/homebrew-bar",
|
|
|
|
},
|
2017-04-24 14:11:04 +01:00
|
|
|
},
|
2018-06-02 02:12:40 +02:00
|
|
|
],
|
|
|
|
}
|
2017-02-21 05:13:05 +01:00
|
|
|
|
2018-06-02 02:12:40 +02:00
|
|
|
allow(GitHub).to receive(:open_api).and_yield(json_response)
|
2017-02-21 05:13:05 +01:00
|
|
|
|
2018-06-02 20:49:14 +02:00
|
|
|
expect(mod.search_taps("some-formula"))
|
2018-06-06 13:24:55 +02:00
|
|
|
.to match(formulae: ["homebrew/foo/some-formula"], casks: ["homebrew/bar/some-cask"])
|
2018-06-02 02:12:40 +02:00
|
|
|
end
|
2017-02-21 05:13:05 +01:00
|
|
|
end
|
2018-06-02 20:49:14 +02:00
|
|
|
|
2018-06-05 10:55:00 +02:00
|
|
|
describe "#query_regexp" do
|
|
|
|
it "correctly parses a regex query" do
|
|
|
|
expect(mod.query_regexp("/^query$/")).to eq(/^query$/)
|
2018-06-02 20:49:14 +02:00
|
|
|
end
|
2018-06-02 22:43:54 +02:00
|
|
|
|
2018-06-05 15:39:09 +02:00
|
|
|
it "returns the original string if it is not a regex query" do
|
|
|
|
expect(mod.query_regexp("query")).to eq("query")
|
2018-06-02 22:43:54 +02:00
|
|
|
end
|
|
|
|
|
2018-06-05 10:55:00 +02:00
|
|
|
it "raises an error if the query is an invalid regex" do
|
|
|
|
expect { mod.query_regexp("/+/") }.to raise_error(/not a valid regex/)
|
2018-06-02 22:43:54 +02:00
|
|
|
end
|
2018-06-02 20:49:14 +02:00
|
|
|
end
|
2017-02-21 05:13:05 +01:00
|
|
|
end
|