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
|
# frozen_string_literal: true
RSpec.describe TTY::Prompt::Question::Validation, "#coerce" do
let(:instance) { described_class.new }
it "coerces lambda into proc" do
pattern = -> { "^[^\.]+\.[^\.]+" }
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
|