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,10 +1,24 @@
require "cmd/search" require "cmd/search"
describe Homebrew do describe Homebrew do
specify "#search_taps" do describe "#search_taps" do
# Otherwise the tested method returns [], regardless of our stub before do
ENV.delete("HOMEBREW_NO_GITHUB_API") ENV.delete("HOMEBREW_NO_GITHUB_API")
end
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 = { json_response = {
"items" => [ "items" => [
{ {
@ -13,12 +27,19 @@ describe Homebrew do
"full_name" => "Homebrew/homebrew-foo", "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")) expect(described_class.search_taps("some-formula"))
.to match([["homebrew/foo/some-formula"], []]) .to match([["homebrew/foo/some-formula"], ["homebrew/bar/some-cask"]])
end
end end
end end

View File

@ -1,3 +1,5 @@
require "cmd/search"
describe "brew search", :integration_test do describe "brew search", :integration_test do
before do before do
setup_test_formula "testball" setup_test_formula "testball"
@ -63,4 +65,18 @@ describe "brew search", :integration_test do
.and be_a_success .and be_a_success
end end
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 end