1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
# frozen_string_literal: true
RSpec.describe "Custom Printer" do
let(:output) { StringIO.new }
before do
stub_const("CustomPrinter", Class.new(TTY::Command::Printers::Abstract) do
def write(message)
output << message
end
end)
end
it "prints command start" do
printer = CustomPrinter.new(output)
cmd = TTY::Command::Cmd.new(:echo, "'hello world'")
printer.print_command_start(cmd)
output.rewind
expect(output.string).to eq("echo \\'hello\\ world\\'")
end
it "prints command stdout data" do
printer = CustomPrinter.new(output)
cmd = TTY::Command::Cmd.new(:echo, "hello world")
printer.print_command_out_data(cmd, "data")
output.rewind
expect(output.string).to eq("data")
end
it "prints command exit" do
printer = CustomPrinter.new(output)
cmd = TTY::Command::Cmd.new(:echo, "hello world")
printer.print_command_exit(cmd)
output.rewind
expect(output.string).to be_empty
end
it "accepts options" do
printer = CustomPrinter.new(output, foo: :bar)
expect(printer.options[:foo]).to eq(:bar)
end
end
|