Sha256: f4a0f739b1da4269f706701910ae70a9b7d6f4d0a844091dcc66c4f1deff6f9e

Contents?: true

Size: 860 Bytes

Versions: 5

Compression:

Stored size: 860 Bytes

Contents

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

require 'spec_helper'

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

  it 'fails to validate input' do
    input << 'piotrmurach'
    input.rewind
    q = shell.ask("What is your username?").validate(/^[^\.]+\.[^\.]+/)
    expect { q.read_string }.to raise_error(ArgumentError)
  end

  it 'validates input with regex' do
    input << 'piotr.murach'
    input.rewind
    q = shell.ask("What is your username?").validate(/^[^\.]+\.[^\.]+/)
    expect(q.read_string).to eql 'piotr.murach'
  end

  it 'validates input in block' do
    input << 'piotr.murach'
    input.rewind
    q = shell.ask("What is your username?").validate { |arg| arg =~ /^[^\.]+\.[^\.]+/ }
    expect(q.read_string).to eql 'piotr.murach'
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

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