Sha256: 1b5aba8561a31dd9f05094812b3b8883ee103f2b3b54fea913275e5538fc6b1a

Contents?: true

Size: 1.19 KB

Versions: 6

Compression:

Stored size: 1.19 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 eq('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 eq('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 eq('club')
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

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