Sha256: b64e02d1bd1f574566d88e8772120b1d5635cc528415726136ad1ceece51b6e4

Contents?: true

Size: 916 Bytes

Versions: 1

Compression:

Stored size: 916 Bytes

Contents

# encoding: utf-8

require 'spec_helper'

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

  it 'fails to read boolean' do
    input << 'invalid'
    input.rewind
    q = shell.ask("Do you read books?")
    expect { q.read_bool }.to raise_error(TTY::Conversion::TypeError)
  end

  it 'reads negative boolean' do
    input << 'No'
    input.rewind
    q = shell.ask("Do you read books?")
    answer = q.read_bool
    expect(answer).to eql false
  end

  it 'reads positive boolean' do
    input << 'Yes'
    input.rewind
    q = shell.ask("Do you read books?")
    answer = q.read_bool
    expect(answer).to eql true
  end

  it 'reads single positive boolean' do
    input << 'y'
    input.rewind
    q = shell.ask("Do you read books?")
    answer = q.read_bool
    expect(answer).to eql true
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tty-0.1.1 spec/tty/shell/response/read_bool_spec.rb