Sha256: 0266cb08d33ac3e1ffea146b54d8595f635ff8eea112db8b2fc502e7e15925f5

Contents?: true

Size: 754 Bytes

Versions: 3

Compression:

Stored size: 754 Bytes

Contents

require 'minitest_helper'

describe Rasti::Form::Types::String, 'Formatted' do

  email_regexp = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i

  ['user@mail.com'.to_sym, 'user.name-123@mail-test.com.ar'].each do |value|
    it "#{value.inspect} -> #{value.to_s}" do
      Rasti::Form::Types::String[email_regexp].cast(value).must_equal value.to_s
    end
  end

  [nil, 'text', :symbol, '999'.to_sym, [1,2], {a: 1, b: 2}, Object.new, 5].each do |value|
    it "#{value.inspect} -> CastError" do
      error = proc { Rasti::Form::Types::String[email_regexp].cast(value) }.must_raise Rasti::Form::CastError
      error.message.must_equal "Invalid cast: #{as_string(value)} -> Rasti::Form::Types::String[#{as_string(email_regexp)}]"
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rasti-form-3.1.2 spec/types/string_formatted_spec.rb
rasti-form-3.1.1 spec/types/string_formatted_spec.rb
rasti-form-3.1.0 spec/types/string_formatted_spec.rb