From d29cb450f729fc88ba045c68e3b70e86cdecfaec Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Thu, 6 Jul 2017 01:08:59 +0200 Subject: Output plain list when running `brew cask search` without a TTY. --- Library/Homebrew/test/cask/cli/search_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Library/Homebrew/test/cask/cli') diff --git a/Library/Homebrew/test/cask/cli/search_spec.rb b/Library/Homebrew/test/cask/cli/search_spec.rb index 00fcf7382..c382614a4 100644 --- a/Library/Homebrew/test/cask/cli/search_spec.rb +++ b/Library/Homebrew/test/cask/cli/search_spec.rb @@ -1,4 +1,8 @@ describe Hbc::CLI::Search, :cask do + before(:each) do + allow($stdout).to receive(:tty?).and_return(true) + end + it "lists the available Casks that match the search term" do expect { Hbc::CLI::Search.run("local") -- cgit v1.2.3 From dccdac55a835a22d46c36fe915e6e8cdf43a4adc Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 8 Jul 2017 00:57:08 +0200 Subject: Add helper for testing TTY output. --- Library/Homebrew/test/cask/cli/search_spec.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'Library/Homebrew/test/cask/cli') diff --git a/Library/Homebrew/test/cask/cli/search_spec.rb b/Library/Homebrew/test/cask/cli/search_spec.rb index c382614a4..4c779cae3 100644 --- a/Library/Homebrew/test/cask/cli/search_spec.rb +++ b/Library/Homebrew/test/cask/cli/search_spec.rb @@ -1,12 +1,12 @@ describe Hbc::CLI::Search, :cask do before(:each) do - allow($stdout).to receive(:tty?).and_return(true) + allow(Tty).to receive(:width).and_return(0) end it "lists the available Casks that match the search term" do expect { Hbc::CLI::Search.run("local") - }.to output(<<-EOS.undent).to_stdout + }.to output(<<-EOS.undent).to_stdout.as_tty ==> Partial Matches local-caffeine local-transmission @@ -16,49 +16,49 @@ describe Hbc::CLI::Search, :cask do 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 + }.to output("No Cask found for \"foo-bar-baz\".\n").to_stdout.as_tty end it "lists all available Casks with no search term" do expect { Hbc::CLI::Search.run - }.to output(/local-caffeine/).to_stdout + }.to output(/local-caffeine/).to_stdout.as_tty end it "ignores hyphens in search terms" do expect { Hbc::CLI::Search.run("lo-cal-caffeine") - }.to output(/local-caffeine/).to_stdout + }.to output(/local-caffeine/).to_stdout.as_tty end it "ignores hyphens in Cask tokens" do expect { Hbc::CLI::Search.run("localcaffeine") - }.to output(/local-caffeine/).to_stdout + }.to output(/local-caffeine/).to_stdout.as_tty end it "accepts multiple arguments" do expect { Hbc::CLI::Search.run("local caffeine") - }.to output(/local-caffeine/).to_stdout + }.to output(/local-caffeine/).to_stdout.as_tty end it "accepts a regexp argument" do expect { Hbc::CLI::Search.run("/^local-c[a-z]ffeine$/") - }.to output("==> Regexp Matches\nlocal-caffeine\n").to_stdout + }.to output("==> Regexp Matches\nlocal-caffeine\n").to_stdout.as_tty end it "Returns both exact and partial matches" do expect { Hbc::CLI::Search.run("test-opera") - }.to output(/^==> Exact Match\ntest-opera\n==> Partial Matches\ntest-opera-mail/).to_stdout + }.to output(/^==> Exact Match\ntest-opera\n==> Partial Matches\ntest-opera-mail/).to_stdout.as_tty 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 + }.to output(/^No Cask found for "caskroom"\.\n/).to_stdout.as_tty end it "doesn't highlight packages that aren't installed" do -- cgit v1.2.3 From 4e26fdfcf6922dca9a82b15697b4c76c6bf9212b Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 8 Jul 2017 18:26:46 +0200 Subject: Add test for non-TTY `brew cask search`. --- Library/Homebrew/test/cask/cli/search_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'Library/Homebrew/test/cask/cli') diff --git a/Library/Homebrew/test/cask/cli/search_spec.rb b/Library/Homebrew/test/cask/cli/search_spec.rb index 4c779cae3..f43610767 100644 --- a/Library/Homebrew/test/cask/cli/search_spec.rb +++ b/Library/Homebrew/test/cask/cli/search_spec.rb @@ -13,6 +13,15 @@ describe Hbc::CLI::Search, :cask do EOS end + it "outputs a plain list when stdout is not a TTY" do + expect { + Hbc::CLI::Search.run("local") + }.to output(<<-EOS.undent).to_stdout + local-caffeine + local-transmission + 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") -- cgit v1.2.3