Add test for non-TTY brew cask search.
This commit is contained in:
parent
dccdac55a8
commit
4e26fdfcf6
@ -13,6 +13,15 @@ describe Hbc::CLI::Search, :cask do
|
|||||||
EOS
|
EOS
|
||||||
end
|
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
|
it "shows that there are no Casks matching a search term that did not result in anything" do
|
||||||
expect {
|
expect {
|
||||||
Hbc::CLI::Search.run("foo-bar-baz")
|
Hbc::CLI::Search.run("foo-bar-baz")
|
||||||
|
|||||||
@ -3,14 +3,6 @@ require "delegate"
|
|||||||
module Test
|
module Test
|
||||||
module Helper
|
module Helper
|
||||||
module OutputAsTTY
|
module OutputAsTTY
|
||||||
module TTYTrue
|
|
||||||
def tty?
|
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
alias isatty tty?
|
|
||||||
end
|
|
||||||
|
|
||||||
# This is a custom wrapper for the `output` matcher,
|
# This is a custom wrapper for the `output` matcher,
|
||||||
# used for testing output to a TTY:
|
# used for testing output to a TTY:
|
||||||
#
|
#
|
||||||
@ -26,41 +18,33 @@ module Test
|
|||||||
def matches?(block)
|
def matches?(block)
|
||||||
return super(block) unless @tty
|
return super(block) unless @tty
|
||||||
|
|
||||||
colored_tty_block = if @output == :stdout
|
colored_tty_block = lambda do
|
||||||
lambda do
|
instance_eval("$#{@output}").extend(Module.new do
|
||||||
$stdout.extend(TTYTrue)
|
def tty?
|
||||||
block.call
|
true
|
||||||
end
|
end
|
||||||
elsif @output == :stderr
|
|
||||||
lambda do
|
alias_method :isatty, :tty?
|
||||||
$stderr.extend(TTYTrue)
|
end)
|
||||||
block.call
|
block.call
|
||||||
end
|
end
|
||||||
else
|
|
||||||
raise "`as_tty` can only be chained to `stdout` or `stderr`."
|
|
||||||
end
|
|
||||||
|
|
||||||
return super(colored_tty_block) if @colors
|
return super(colored_tty_block) if @colors
|
||||||
|
|
||||||
uncolored_tty_block = lambda do
|
uncolored_tty_block = lambda do
|
||||||
|
instance_eval <<-EOS
|
||||||
begin
|
begin
|
||||||
out_stream = StringIO.new
|
captured_stream = StringIO.new
|
||||||
err_stream = StringIO.new
|
|
||||||
|
|
||||||
old_stdout = $stdout
|
original_stream = $#{@output}
|
||||||
old_stderr = $stderr
|
$#{@output} = captured_stream
|
||||||
|
|
||||||
$stdout = out_stream
|
|
||||||
$stderr = err_stream
|
|
||||||
|
|
||||||
colored_tty_block.call
|
colored_tty_block.call
|
||||||
ensure
|
ensure
|
||||||
$stdout = old_stdout
|
$#{@output} = original_stream
|
||||||
$stderr = old_stderr
|
$#{@output}.print Tty.strip_ansi(captured_stream.string)
|
||||||
|
|
||||||
$stdout.print Tty.strip_ansi(out_stream.string)
|
|
||||||
$stderr.print Tty.strip_ansi(err_stream.string)
|
|
||||||
end
|
end
|
||||||
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
super(uncolored_tty_block)
|
super(uncolored_tty_block)
|
||||||
@ -80,7 +64,8 @@ module Test
|
|||||||
|
|
||||||
def as_tty
|
def as_tty
|
||||||
@tty = true
|
@tty = true
|
||||||
self
|
return self if [:stdout, :stderr].include?(@output)
|
||||||
|
raise "`as_tty` can only be chained to `stdout` or `stderr`."
|
||||||
end
|
end
|
||||||
|
|
||||||
def with_color
|
def with_color
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user