Sha256: 12c21dda5bf1f4043f9b6c8a031fa2334a23d8c3e24e2d1cc88e2a70e19a6259

Contents?: true

Size: 731 Bytes

Versions: 4

Compression:

Stored size: 731 Bytes

Contents

require 'minitest_helper'

describe Rasti::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::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::Types::String[email_regexp].cast(value) }.must_raise Rasti::Types::CastError
      error.message.must_equal "Invalid cast: #{as_string(value)} -> Rasti::Types::String[#{as_string(email_regexp)}]"
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rasti-types-1.1.2 spec/string_formatted_spec.rb
rasti-types-1.1.1 spec/string_formatted_spec.rb
rasti-types-1.1.0 spec/string_formatted_spec.rb
rasti-types-1.0.0 spec/string_formatted_spec.rb