Extend search tests.

This commit is contained in:
Markus Reiter 2018-06-02 02:12:40 +02:00
parent 8b33fbef51
commit 3a361c139e
2 changed files with 52 additions and 15 deletions

View File

@ -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

View File

@ -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