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