rm unused OutputAsTTY helper
This commit is contained in:
parent
221fde4ad8
commit
c1a4a806e1
@ -44,7 +44,6 @@ require "test/support/helper/files"
|
||||
require "test/support/helper/fixtures"
|
||||
require "test/support/helper/formula"
|
||||
require "test/support/helper/mktmpdir"
|
||||
require "test/support/helper/output_as_tty"
|
||||
|
||||
require "test/support/helper/spec/shared_context/homebrew_cask" if OS.mac?
|
||||
require "test/support/helper/spec/shared_context/integration_test"
|
||||
@ -131,15 +130,12 @@ RSpec.configure do |config|
|
||||
|
||||
config.include(FileUtils)
|
||||
|
||||
config.include(Context)
|
||||
|
||||
config.include(RuboCop::RSpec::ExpectOffense)
|
||||
|
||||
config.include(Test::Helper::Cask)
|
||||
config.include(Test::Helper::Fixtures)
|
||||
config.include(Test::Helper::Formula)
|
||||
config.include(Test::Helper::MkTmpDir)
|
||||
config.include(Test::Helper::OutputAsTTY)
|
||||
|
||||
config.before(:each, :needs_linux) do
|
||||
skip "Not running on Linux." unless OS.linux?
|
||||
|
||||
@ -1,88 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "delegate"
|
||||
|
||||
module Test
|
||||
module Helper
|
||||
module OutputAsTTY
|
||||
# This is a custom wrapper for the `output` matcher,
|
||||
# used for testing output to a TTY:
|
||||
#
|
||||
# expect {
|
||||
# print "test" if $stdout.tty?
|
||||
# }.to output("test").to_stdout.as_tty
|
||||
#
|
||||
# expect {
|
||||
# # command
|
||||
# }.to output(...).to_stderr.as_tty.with_color
|
||||
#
|
||||
class Output < SimpleDelegator
|
||||
def matches?(block)
|
||||
return super(block) unless @tty
|
||||
|
||||
colored_tty_block = lambda do
|
||||
instance_eval("$#{@output} # $stdout", __FILE__, __LINE__).extend(Module.new do
|
||||
def tty?
|
||||
true
|
||||
end
|
||||
|
||||
alias_method :isatty, :tty?
|
||||
end)
|
||||
block.call
|
||||
end
|
||||
|
||||
return super(colored_tty_block) if @colors
|
||||
|
||||
uncolored_tty_block = lambda do
|
||||
instance_eval <<-EOS, __FILE__, __LINE__ + 1
|
||||
begin # begin
|
||||
captured_stream = StringIO.new # captured_stream = StringIO.new
|
||||
|
||||
original_stream = $#{@output} # original_stream = $stdout
|
||||
$#{@output} = captured_stream # $stdout = captured_stream
|
||||
|
||||
colored_tty_block.call # colored_tty_block.call
|
||||
ensure # ensure
|
||||
$#{@output} = original_stream # $stdout = original_stream
|
||||
$#{@output}.print Tty.strip_ansi(captured_stream.string) # $stdout.print Tty.strip_ansi(captured_stream.string)
|
||||
end # end
|
||||
EOS
|
||||
end
|
||||
|
||||
super(uncolored_tty_block)
|
||||
end
|
||||
|
||||
def to_stdout
|
||||
@output = :stdout
|
||||
super
|
||||
self
|
||||
end
|
||||
|
||||
def to_stderr
|
||||
@output = :stderr
|
||||
super
|
||||
self
|
||||
end
|
||||
|
||||
def as_tty
|
||||
@tty = true
|
||||
return self if [:stdout, :stderr].include?(@output)
|
||||
|
||||
raise "`as_tty` can only be chained to `stdout` or `stderr`."
|
||||
end
|
||||
|
||||
def with_color
|
||||
@colors = true
|
||||
return self if @tty
|
||||
|
||||
raise "`with_color` can only be chained to `as_tty`."
|
||||
end
|
||||
end
|
||||
|
||||
def output(*args)
|
||||
core_matcher = super(*args)
|
||||
Output.new(core_matcher)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -194,6 +194,8 @@ RSpec.describe SystemCommand do
|
||||
end
|
||||
|
||||
context "when `debug?` is true" do
|
||||
include Context
|
||||
|
||||
let(:options) do
|
||||
{ args: [
|
||||
"-c",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user