Sha256: 04844a7eee0127322c23c8153877dbd307f8e626e48afca5c9f7d0ca69eb2c6a

Contents?: true

Size: 1.26 KB

Versions: 15

Compression:

Stored size: 1.26 KB

Contents

# encoding: utf-8

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

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

  it 'preserves answer for unkown modification' do
    prompt.input << 'piotr'
    prompt.input.rewind
    answer = prompt.ask("What is your name?") { |q| q.modify(:none) }
    expect(answer).to eq('piotr')
  end

  it 'converts to upper case' do
    prompt.input << 'piotr'
    prompt.input.rewind
    answer = prompt.ask("What is your name?") { |q| q.modify(:upcase) }
    expect(answer).to eq('PIOTR')
  end

  it 'trims whitespace' do
    prompt.input << " Some   white\t   space\t \there!   \n"
    prompt.input.rewind
    answer = prompt.ask('Enter some text: ') { |q| q.modify(:trim) }
    expect(answer).to eq("Some   white\t   space\t \there!")
  end

  it 'collapses whitespace' do
    prompt.input << " Some   white\t   space\t \there!   \n"
    prompt.input.rewind
    answer = prompt.ask('Enter some text: ') { |q| q.modify(:collapse) }
    expect(answer).to eq(' Some white space here! ')
  end

  it 'strips and collapses whitespace' do
    prompt.input << " Some   white\t   space\t \there!   \n"
    prompt.input.rewind
    answer = prompt.ask('Enter some text: ') { |q| q.modify(:strip, :collapse) }
    expect(answer).to eq('Some white space here!')
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
tty-prompt-0.17.2 spec/unit/question/modify_spec.rb
tty-prompt-0.17.1 spec/unit/question/modify_spec.rb
tty-prompt-0.17.0 spec/unit/question/modify_spec.rb
tty-prompt-0.12.0 spec/unit/question/modify_spec.rb
tty-prompt-0.11.0 spec/unit/question/modify_spec.rb
tty-prompt-0.10.1 spec/unit/question/modify_spec.rb
tty-prompt-0.10.0 spec/unit/question/modify_spec.rb
tty-prompt-0.9.0 spec/unit/question/modify_spec.rb
tty-prompt-0.8.0 spec/unit/question/modify_spec.rb
tty-prompt-0.7.1 spec/unit/question/modify_spec.rb
tty-prompt-0.7.0 spec/unit/question/modify_spec.rb
tty-prompt-0.6.0 spec/unit/question/modify_spec.rb
tty-prompt-0.5.0 spec/unit/question/modify_spec.rb
tty-prompt-0.4.0 spec/unit/question/modify_spec.rb
tty-prompt-0.3.0 spec/unit/question/modify_spec.rb