Sha256: 6c7e5b05b91ece3b13d96de63405c97651c571036d36ee35a1de68e74f20f341

Contents?: true

Size: 1.2 KB

Versions: 5

Compression:

Stored size: 1.2 KB

Contents

# -*- encoding: utf-8 -*-

require 'spec_helper'

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

  let(:cards) { %w[ club diamond spade heart ] }

  it 'reads valid optios with helper' do
    input << 'club'
    input.rewind
    q = shell.ask("What is your card suit sir?").valid(cards)
    expect(q.read_choice).to eql 'club'
  end

  it 'reads valid options with option hash' do
    input << 'club'
    input.rewind
    q = shell.ask("What is your card suit sir?", :valid => cards)
    expect(q.read_choice).to eql 'club'
  end

  it 'reads invalid option' do
    input << 'clover'
    input.rewind
    q = shell.ask("What is your card suit sir?").valid(cards)
    expect { q.read_choice }.to raise_error(TTY::InvalidArgument)
  end

  it 'needs argument' do
    input << ''
    input.rewind
    q = shell.ask("What is your card suit sir?").valid(cards)
    expect { q.read_choice }.to raise_error(TTY::ArgumentRequired)
  end

  it 'reads with default' do
    input << ''
    input.rewind
    q = shell.ask("What is your card suit sir?").valid(cards).default('club')
    expect(q.read_choice).to eql 'club'
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
tty-0.0.11 spec/tty/shell/question/valid_spec.rb
tty-0.0.10 spec/tty/shell/question/valid_spec.rb
tty-0.0.9 spec/tty/shell/question/valid_spec.rb
tty-0.0.8 spec/tty/shell/question/valid_spec.rb
tty-0.0.7 spec/tty/shell/question/valid_spec.rb