File: dry_run_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 (46 lines) | stat: -rw-r--r-- 1,217 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
# frozen_string_literal: true

RSpec.describe TTY::Command, "dry run" do
  let(:output) { StringIO.new }

  it "queries for dry mode" do
    command = TTY::Command.new(dry_run: false)
    expect(command.dry_run?).to eq(false)
  end

  it "runs command in dry run mode" do
    uuid = "xxxx"
    allow(SecureRandom).to receive(:uuid).and_return(uuid)
    command = TTY::Command.new(output: output, dry_run: true)

    command.run(:echo, "hello", "world")

    output.rewind
    expect(output.read).to eq(
      "[\e[32m#{uuid}\e[0m] \e[34m(dry run)\e[0m " \
      "\e[33;1mecho hello world\e[0m\n"
    )
  end

  it "allows to run command in dry mode" do
    uuid = "xxxx"
    allow(SecureRandom).to receive(:uuid).and_return(uuid)
    command = TTY::Command.new(output: output)

    command.run(:echo, "hello", "world", dry_run: true)

    output.rewind
    expect(output.read).to eq(
      "[\e[32m#{uuid}\e[0m] \e[34m(dry run)\e[0m " \
      "\e[33;1mecho hello world\e[0m\n"
    )
  end

  it "doesn't collect printout to stdin or stderr" do
    cmd = TTY::Command.new(output: output, dry_run: true)
    out, err = cmd.run(:echo, "hello", "world")

    expect(out).to be_empty
    expect(err).to be_empty
  end
end