File: suggest_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 (28 lines) | stat: -rw-r--r-- 934 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
# frozen_string_literal: true

RSpec.describe TTY::Prompt, "#suggest" do
  let(:possible) { %w[status stage stash commit branch blame] }

  subject(:prompt) { TTY::Prompt::Test.new }

  it "suggests few matches" do
    prompt.suggest("sta", possible)
    expect(prompt.output.string)
      .to eql("Did you mean one of these?\n        stage\n        stash\n")
  end

  it "suggests a single match for one character" do
    prompt.suggest("b", possible)
    expect(prompt.output.string).to eql("Did you mean this?\n        blame\n")
  end

  it "suggests a single match for two characters" do
    prompt.suggest("co", possible)
    expect(prompt.output.string).to eql("Did you mean this?\n        commit\n")
  end

  it "suggests with different text and indentation" do
    prompt.suggest("b", possible, indent: 4, single_text: "Perhaps you meant?")
    expect(prompt.output.string).to eql("Perhaps you meant?\n    blame\n")
  end
end