File: say_spec.rb

package info (click to toggle)
ruby-tty-prompt 0.23.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,452 kB
  • sloc: ruby: 8,847; makefile: 4
file content (66 lines) | stat: -rw-r--r-- 1,814 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
# frozen_string_literal: true

RSpec.describe TTY::Prompt, "#say" do
  subject(:prompt) { TTY::Prompt::Test.new }

  it "prints an empty message" do
    prompt.say("")
    expect(prompt.output.string).to eq("")
  end

  context "with new line" do
    it "prints a message with newline" do
      prompt.say("Hell yeah!\n")
      expect(prompt.output.string).to eq("Hell yeah!\n")
    end

    it "prints a message with implicit newline" do
      prompt.say("Hell yeah!\n")
      expect(prompt.output.string).to eq("Hell yeah!\n")
    end

    it "prints a message with newline within text" do
      prompt.say("Hell\n yeah!")
      expect(prompt.output.string).to eq("Hell\n yeah!\n")
    end

    it "prints a message with newline within text and blank space" do
      prompt.say("Hell\n yeah! ")
      expect(prompt.output.string).to eq("Hell\n yeah! ")
    end

    it "prints a message without newline" do
      prompt.say("Hell yeah!", newline: false)
      expect(prompt.output.string).to eq("Hell yeah!")
    end
  end

  context "with tab or space" do
    it "prints " do
      prompt.say("Hell yeah!\t")
      expect(prompt.output.string).to eq("Hell yeah!\t")
    end
  end

  context "with color" do
    it "prints message with ansi color" do
      prompt.say("Hell yeah!", color: :green)
      expect(prompt.output.string).to eq("\e[32mHell yeah!\e[0m\n")
    end

    it "prints message with ansi color without newline" do
      prompt.say("Hell yeah! ", color: :green)
      expect(prompt.output.string).to eq("\e[32mHell yeah! \e[0m")
    end
  end

  context "without color" do
    it "prints message without ansi" do
      prompt = TTY::Prompt::Test.new(enable_color: false)

      prompt.say("Hell yeah!", color: :green)

      expect(prompt.output.string).to eq("Hell yeah!\n")
    end
  end
end