Sha256: 0982193b874f8fc0b297d2ef47ba045a7006182be75361c1f5fc1bad852e18b2

Contents?: true

Size: 1.23 KB

Versions: 6

Compression:

Stored size: 1.23 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe TTY::Shell::Question, '#modify' do
  let(:input)  { StringIO.new }
  let(:output) { StringIO.new }
  let(:shell)  { TTY::Shell.new(input, output) }

  it 'preserves answer for unkown modification' do
    input << 'piotr'
    input.rewind
    q = shell.ask("What is your name?").modify(:none)
    expect(q.read_string).to eql 'piotr'
  end

  it 'converts to upper case' do
    input << 'piotr'
    input.rewind
    q = shell.ask("What is your name?").modify(:upcase)
    expect(q.read_string).to eql 'PIOTR'
  end

  it 'trims whitespace' do
    input << " Some   white\t   space\t \there!   \n"
    input.rewind
    q = shell.ask("Enter some text: ").modify(:trim)
    expect(q.read_string).to eql "Some   white\t   space\t \there!"
  end

  it 'collapses whitespace' do
    input << " Some   white\t   space\t \there!   \n"
    input.rewind
    q = shell.ask("Enter some text: ").modify(:collapse)
    expect(q.read_string).to eql "Some white space here!"
  end

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
tty-0.2.1 spec/tty/shell/question/modify_spec.rb
tty-0.2.0 spec/tty/shell/question/modify_spec.rb
tty-0.1.3 spec/tty/shell/question/modify_spec.rb
tty-0.1.2 spec/tty/shell/question/modify_spec.rb
tty-0.1.1 spec/tty/shell/question/modify_spec.rb
tty-0.1.0 spec/tty/shell/question/modify_spec.rb