Sha256: 3b644cb900b851e412f029df96419b15a4355f9eb381da3302e1dffac176c682

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

# encoding: utf-8

RSpec.describe TTY::Prompt::Question, '#echo' do

  subject(:prompt) { TTY::TestPrompt.new }

  it 'asks with echo on' do
    prompt.input << "password"
    prompt.input.rewind
    answer = prompt.ask("What is your password?") { |q| q.echo(true) }
    expect(answer).to eql("password")
    expect(prompt.output.string).to eq([
      "What is your password? ",
      "\e[2K\e[1GWhat is your password? p",
      "\e[2K\e[1GWhat is your password? pa",
      "\e[2K\e[1GWhat is your password? pas",
      "\e[2K\e[1GWhat is your password? pass",
      "\e[2K\e[1GWhat is your password? passw",
      "\e[2K\e[1GWhat is your password? passwo",
      "\e[2K\e[1GWhat is your password? passwor",
      "\e[2K\e[1GWhat is your password? password",
      "\e[1A\e[2K\e[1G",
      "What is your password? \e[32mpassword\e[0m\n"
    ].join)
  end

  it 'asks with echo off' do
    prompt.input << "password"
    prompt.input.rewind
    answer = prompt.ask("What is your password?", echo: false)
    expect(answer).to eql("password")
    expect(prompt.output.string).to eq([
      "What is your password? ",
      "\e[2K\e[1G",
      "What is your password? \n"
    ].join)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tty-prompt-0.12.0 spec/unit/question/echo_spec.rb