File: quiet_spec.rb

package info (click to toggle)
ruby-tty-command 0.10.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 452 kB
  • sloc: ruby: 1,990; makefile: 4; sh: 4
file content (71 lines) | stat: -rw-r--r-- 1,826 bytes parent folder | download
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# frozen_string_literal: true

RSpec.describe TTY::Command::Printers::Quiet do
  let(:output) { StringIO.new }

  it "doesn't print command start or exit" do
    printer = TTY::Command::Printers::Quiet.new(output)
    cmd = TTY::Command::Cmd.new("echo hello")

    printer.print_command_start(cmd)
    printer.print_command_exit(cmd, 0)
    output.rewind

    expect(output.string).to be_empty
  end

  it "prints command stdout data" do
    printer = TTY::Command::Printers::Quiet.new(output)
    cmd = TTY::Command::Cmd.new("echo hello")

    printer.print_command_out_data(cmd, "hello", "world")
    output.rewind

    expect(output.string).to eq("hello world")
  end

  it "prints command stderr data" do
    printer = TTY::Command::Printers::Quiet.new(output)
    cmd = TTY::Command::Cmd.new("echo hello")

    printer.print_command_err_data(cmd, "hello", "world")
    output.rewind

    expect(output.string).to eq("hello world")
  end

  it "doesn't print output on success when only_output_on_error is true" do
    zero_exit = fixtures_path("zero_exit")
    printer = TTY::Command::Printers::Quiet
    cmd = TTY::Command.new(output: output, printer: printer)

    cmd.run!(:ruby, zero_exit, only_output_on_error: true)
    cmd.run!(:ruby, zero_exit)

    output.rewind

    lines = output.readlines.map(&:chomp)

    expect(lines).to eq([
      "yess"
    ])
  end

  it "prints output on error when only_output_on_error is true" do
    non_zero_exit = fixtures_path("non_zero_exit")
    printer = TTY::Command::Printers::Quiet
    cmd = TTY::Command.new(output: output, printer: printer)

    cmd.run!(:ruby, non_zero_exit, only_output_on_error: true)
    cmd.run!(:ruby, non_zero_exit)

    output.rewind

    lines = output.readlines.map(&:chomp)

    expect(lines).to eq(%w[
      nooo
      nooo
    ])
  end
end