Sha256: b8be2f955d06c96f49a1bdf90af0ae74d9a8834db30714cc0adfe98621a5c7ba

Contents?: true

Size: 808 Bytes

Versions: 7

Compression:

Stored size: 808 Bytes

Contents

# encoding: utf-8

RSpec.describe TTY::Prompt::Question, 'ask keypress' do
  it 'asks for a keypress with :read option' do
    prompt = TTY::TestPrompt.new
    prompt.input << "abcd"
    prompt.input.rewind
    answer = prompt.ask("Which one do you prefer a, b, c or d?", read: :keypress)
    expect(answer).to eq("a")
  end

  it 'asks for a keypress with method' do
    prompt = TTY::TestPrompt.new
    prompt.input << "abcd"
    prompt.input.rewind
    answer = prompt.keypress("Which one do you prefer a, b, c or d?")
    expect(answer).to eq("a")
  end

  it "interrupts input" do
    prompt = TTY::TestPrompt.new(interrupt: :exit)
    prompt.input << "\x03"
    prompt.input.rewind

    expect {
      prompt.keypress("Which one do you prefer a, b, c or d?")
    }.to raise_error(SystemExit)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
tty-prompt-0.11.0 spec/unit/keypress_spec.rb
tty-prompt-0.10.1 spec/unit/keypress_spec.rb
tty-prompt-0.10.0 spec/unit/keypress_spec.rb
tty-prompt-0.9.0 spec/unit/keypress_spec.rb
tty-prompt-0.8.0 spec/unit/keypress_spec.rb
tty-prompt-0.7.1 spec/unit/keypress_spec.rb
tty-prompt-0.7.0 spec/unit/keypress_spec.rb