Sha256: 6bc27791f109b730f217ec4b1f1ffea79c8002bb80704b458112fdb257090a8b

Contents?: true

Size: 896 Bytes

Versions: 10

Compression:

Stored size: 896 Bytes

Contents

# encoding: utf-8

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

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

  it 'uses default value' do
    name = 'Anonymous'
    prompt.input << "\n"
    prompt.input.rewind
    answer = prompt.ask('What is your name?', default: name)
    expect(answer).to eq(name)
    expect(prompt.output.string).to eq([
      "What is your name? \e[90m(Anonymous)\e[0m ",
      "\e[1000D\e[K\e[1A",
      "\e[1000D\e[K",
      "What is your name? \e[32mAnonymous\e[0m\n"
    ].join)
  end

  it 'uses default value in block' do
    name = 'Anonymous'
    answer = prompt.ask('What is your name?') { |q| q.default(name) }
    expect(answer).to eq(name)
    expect(prompt.output.string).to eq([
      "What is your name? \e[90m(Anonymous)\e[0m ",
      "\e[1000D\e[K\e[1A",
      "\e[1000D\e[K",
      "What is your name? \e[32mAnonymous\e[0m\n"
    ].join)
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
tty-prompt-0.10.1 spec/unit/question/default_spec.rb
tty-prompt-0.10.0 spec/unit/question/default_spec.rb
tty-prompt-0.9.0 spec/unit/question/default_spec.rb
tty-prompt-0.8.0 spec/unit/question/default_spec.rb
tty-prompt-0.7.1 spec/unit/question/default_spec.rb
tty-prompt-0.7.0 spec/unit/question/default_spec.rb
tty-prompt-0.6.0 spec/unit/question/default_spec.rb
tty-prompt-0.5.0 spec/unit/question/default_spec.rb
tty-prompt-0.4.0 spec/unit/question/default_spec.rb
tty-prompt-0.3.0 spec/unit/question/default_spec.rb