Sha256: 9f9270eacb2b9670e1e6d16c6a9239e6c288d615e102d1d92a071082a6eb5095

Contents?: true

Size: 799 Bytes

Versions: 15

Compression:

Stored size: 799 Bytes

Contents

# encoding: utf-8

RSpec.describe TTY::Prompt::Question::Validation, '#coerce' do
  let(:instance) { described_class.new }

  it "coerces lambda into proc" do
    pattern = lambda { "^[^\.]+\.[^\.]+" }
    validation = described_class.new(pattern)
    expect(validation.pattern).to be_a(Proc)
  end

  it "doesn't coerce symbols" do
    pattern = :email
    validation =described_class.new(pattern)
    expect(validation.pattern).to eq(:email)
  end

  it "coerces into regex" do
    pattern = /^[^\.]+\.[^\.]+/
    validation = described_class.new(pattern)
    expect(validation.pattern).to be_a(Regexp)
  end

  it "fails to coerce pattern into validation" do
    pattern = Object.new
    expect {
      described_class.new(pattern)
    }.to raise_error(TTY::Prompt::ValidationCoercion)
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

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