Sha256: bc45efbf0cbbd45c4680cd17f6744aefb359b5e6ebc201b6c94b0d3afcaddf2e

Contents?: true

Size: 914 Bytes

Versions: 15

Compression:

Stored size: 914 Bytes

Contents

# encoding: utf-8

RSpec.describe TTY::Prompt::Question::Validation, '#call' do
  let(:pattern) { /^[^\.]+\.[^\.]+/ }

  it "validates nil input" do
    validation = described_class.new(pattern)
    expect(validation.(nil)).to eq(false)
  end

  it "validates successfully when the value matches pattern" do
    validation = described_class.new(pattern)
    expect(validation.('piotr.murach')).to eq(true)
  end

  it "validates with a proc" do
    pat = proc { |input| !pattern.match(input).nil? }
    validation = described_class.new(pat)
    expect(validation.call('piotr.murach')).to eq(true)
  end

  it "validates with custom name" do
    validation = described_class.new(:email)
    expect(validation.call('piotr@example.com')).to eq(true)
  end

  it "fails validation when not maching pattern" do
    validation = described_class.new(pattern)
    expect(validation.('piotrmurach')).to eq(false)
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
tty-prompt-0.17.2 spec/unit/question/validation/call_spec.rb
tty-prompt-0.17.1 spec/unit/question/validation/call_spec.rb
tty-prompt-0.17.0 spec/unit/question/validation/call_spec.rb
tty-prompt-0.12.0 spec/unit/question/validation/call_spec.rb
tty-prompt-0.11.0 spec/unit/question/validation/call_spec.rb
tty-prompt-0.10.1 spec/unit/question/validation/call_spec.rb
tty-prompt-0.10.0 spec/unit/question/validation/call_spec.rb
tty-prompt-0.9.0 spec/unit/question/validation/call_spec.rb
tty-prompt-0.8.0 spec/unit/question/validation/call_spec.rb
tty-prompt-0.7.1 spec/unit/question/validation/call_spec.rb
tty-prompt-0.7.0 spec/unit/question/validation/call_spec.rb
tty-prompt-0.6.0 spec/unit/question/validation/call_spec.rb
tty-prompt-0.5.0 spec/unit/question/validation/call_spec.rb
tty-prompt-0.4.0 spec/unit/question/validation/call_spec.rb
tty-prompt-0.3.0 spec/unit/question/validation/call_spec.rb