Sha256: ed8fe1a68d618952d72dd1b320c024b1aed39b0e2e8183c233592f468775782e

Contents?: true

Size: 921 Bytes

Versions: 4

Compression:

Stored size: 921 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(Necromancer::ConversionTypeError)
  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

4 entries across 4 versions & 1 rubygems

Version Path
tty-0.2.1 spec/tty/shell/response/read_bool_spec.rb
tty-0.2.0 spec/tty/shell/response/read_bool_spec.rb
tty-0.1.3 spec/tty/shell/response/read_bool_spec.rb
tty-0.1.2 spec/tty/shell/response/read_bool_spec.rb