File: subscribe_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 (22 lines) | stat: -rw-r--r-- 603 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
# frozen_string_literal: true

RSpec.describe TTY::Prompt, "#subscribe" do
  it "subscribes to key events only for the current prompt" do
    prompt = TTY::Prompt::Test.new
    uuid = "14c3b412-e0c5-4ff5-9cd8-25ec3f18c702"
    prompt.input << "3\n#{uuid}\n"
    prompt.input.rewind
    keys = []

    prompt.on(:keypress) do |event|
      keys << :enter if event.key.name == :enter
    end

    letter = prompt.enum_select("Select something", ("A".."Z").to_a)
    id = prompt.ask("Request ID?")

    expect(letter).to eq("C")
    expect(id).to eq(uuid)
    expect(keys).to eq(%i[enter enter])
  end
end