File: call_spec.rb

package info (click to toggle)
ruby-tty-prompt 0.23.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,452 kB
  • sloc: ruby: 8,847; makefile: 4
file content (31 lines) | stat: -rw-r--r-- 924 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true

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