2017-03-05 19:26:56 +01:00
|
|
|
describe Hbc::CLI::Search, :cask do
|
2017-07-06 01:08:59 +02:00
|
|
|
before(:each) do
|
|
|
|
allow($stdout).to receive(:tty?).and_return(true)
|
|
|
|
end
|
|
|
|
|
2017-02-08 13:34:26 +01:00
|
|
|
it "lists the available Casks that match the search term" do
|
|
|
|
expect {
|
2017-03-04 21:42:09 +01:00
|
|
|
Hbc::CLI::Search.run("local")
|
2017-02-08 13:34:26 +01:00
|
|
|
}.to output(<<-EOS.undent).to_stdout
|
2017-04-24 19:31:36 +02:00
|
|
|
==> Partial Matches
|
2017-03-04 21:42:09 +01:00
|
|
|
local-caffeine
|
|
|
|
local-transmission
|
2017-02-08 13:34:26 +01:00
|
|
|
EOS
|
|
|
|
end
|
|
|
|
|
|
|
|
it "shows that there are no Casks matching a search term that did not result in anything" do
|
|
|
|
expect {
|
|
|
|
Hbc::CLI::Search.run("foo-bar-baz")
|
|
|
|
}.to output("No Cask found for \"foo-bar-baz\".\n").to_stdout
|
|
|
|
end
|
|
|
|
|
|
|
|
it "lists all available Casks with no search term" do
|
|
|
|
expect {
|
|
|
|
Hbc::CLI::Search.run
|
2017-03-04 21:42:09 +01:00
|
|
|
}.to output(/local-caffeine/).to_stdout
|
2017-02-08 13:34:26 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "ignores hyphens in search terms" do
|
|
|
|
expect {
|
2017-03-04 21:42:09 +01:00
|
|
|
Hbc::CLI::Search.run("lo-cal-caffeine")
|
|
|
|
}.to output(/local-caffeine/).to_stdout
|
2017-02-08 13:34:26 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "ignores hyphens in Cask tokens" do
|
|
|
|
expect {
|
2017-03-04 21:42:09 +01:00
|
|
|
Hbc::CLI::Search.run("localcaffeine")
|
|
|
|
}.to output(/local-caffeine/).to_stdout
|
2017-02-08 13:34:26 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "accepts multiple arguments" do
|
|
|
|
expect {
|
2017-03-04 21:42:09 +01:00
|
|
|
Hbc::CLI::Search.run("local caffeine")
|
|
|
|
}.to output(/local-caffeine/).to_stdout
|
2017-02-08 13:34:26 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "accepts a regexp argument" do
|
|
|
|
expect {
|
2017-03-04 21:42:09 +01:00
|
|
|
Hbc::CLI::Search.run("/^local-c[a-z]ffeine$/")
|
2017-04-24 19:31:36 +02:00
|
|
|
}.to output("==> Regexp Matches\nlocal-caffeine\n").to_stdout
|
2017-02-08 13:34:26 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "Returns both exact and partial matches" do
|
|
|
|
expect {
|
2017-03-04 21:42:09 +01:00
|
|
|
Hbc::CLI::Search.run("test-opera")
|
2017-04-24 19:31:36 +02:00
|
|
|
}.to output(/^==> Exact Match\ntest-opera\n==> Partial Matches\ntest-opera-mail/).to_stdout
|
2017-02-08 13:34:26 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does not search the Tap name" do
|
|
|
|
expect {
|
|
|
|
Hbc::CLI::Search.run("caskroom")
|
|
|
|
}.to output(/^No Cask found for "caskroom"\.\n/).to_stdout
|
|
|
|
end
|
2017-03-13 17:52:32 -05:00
|
|
|
|
2017-03-13 19:43:08 -05:00
|
|
|
it "doesn't highlight packages that aren't installed" do
|
2017-03-13 19:15:41 -05:00
|
|
|
expect(Hbc::CLI::Search.highlight_installed("local-caffeine")).to eq("local-caffeine")
|
2017-03-13 17:52:32 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "highlights installed packages" do
|
|
|
|
shutup do
|
2017-03-13 19:15:41 -05:00
|
|
|
Hbc::CLI::Install.run("local-caffeine")
|
2017-03-13 17:52:32 -05:00
|
|
|
end
|
|
|
|
|
2017-03-13 19:15:41 -05:00
|
|
|
expect(Hbc::CLI::Search.highlight_installed("local-caffeine")).to eq(pretty_installed("local-caffeine"))
|
2017-03-13 17:52:32 -05:00
|
|
|
end
|
2017-02-08 13:34:26 +01:00
|
|
|
end
|