File: decorate_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 (35 lines) | stat: -rw-r--r-- 1,184 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
# frozen_string_literal: true

RSpec.describe TTY::Prompt, "#decorate" do
  it "doesn't decorate empty string" do
    prompt = described_class.new(enable_color: true)
    expect(prompt.decorate(" \n ")).to eq(" \n ")
  end

  it "doesn't decorate when disabled" do
    prompt = described_class.new(enable_color: false)
    expect(prompt.decorate("string", :green)).to eq("string")
  end

  it "doesn't decorate without additional arguments" do
    prompt = described_class.new(enable_color: true)
    expect(prompt.decorate("string")).to eq("string")
  end

  it "decorates with a callable object" do
    prompt = described_class.new
    callable = Pastel.new(enabled: true).green.on_red.detach
    expect(prompt.decorate("string", callable)).to eq("\e[32;41mstring\e[0m")
  end

  it "decorates with a proc" do
    prompt = described_class.new
    proc_obj = ->(str) { Pastel.new(enabled: true).green(str) }
    expect(prompt.decorate("string", proc_obj)).to eq("\e[32mstring\e[0m")
  end

  it "decorates string with named colors" do
    prompt = described_class.new(enable_color: true)
    expect(prompt.decorate("string", :green, :on_red)).to eq("\e[32;41mstring\e[0m")
  end
end