Sha256: 29b4dd9a24d618fd1a10181b3291bc9edcde3e0e8ebdf98faca425b247bd7a39

Contents?: true

Size: 1.25 KB

Versions: 3

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true
require 'spec_helper'

describe ValidatesZipcode::Formatter, '#format' do
  context 'Canada' do
    it { check_format('CA', 'l3b3z6' => 'L3B 3Z6') }
    it { check_format('ca', 'V2r-1c8' => 'V2R 1C8') }
    it { check_format(:ca, 'g9a 5w1' => 'G9A 5W1') }
  end

  context 'Czech' do
    it { check_format('CZ', '12000' => '120 00') }
    it { check_format(:cz, '721 00' => '721 00') }
  end

  context 'Germany' do
    it { check_format('DE', 1309 => '01309') }
  end

  context 'Netherlands' do
    it { check_format('NL', '1000ap' => '1000 AP') }
    it { check_format('nl', '9104-BR' => '9104 BR') }
    it { check_format(:nl, '6832_AM' => '6832 AM') }
  end

  context 'UK' do
    it { check_format('UK', 'CB224RG' => 'CB22 4RG') }
    it { check_format('UK', 'Sw1A 2aA' => 'SW1A 2AA') }
    it { check_format('GB', 'id11qd' => 'ID1 1QD') }
  end

  context 'US' do
    it { check_format('US', '221	62	–	10	10' => '22162-1010') }
    it { check_format('US', '22162' => '22162') }
    it { check_format('US', '22162 1010' => '22162-1010') }
  end

  def check_format(country, formatting)
    from_zip, to_zip = formatting.first
    expect(::ValidatesZipcode::Formatter.new(zipcode: from_zip, country_alpha2: country).format).to eq(to_zip)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
validates_zipcode-0.5.2 spec/format_zipcode_spec.rb
validates_zipcode-0.5.1 spec/format_zipcode_spec.rb
validates_zipcode-0.5.0 spec/format_zipcode_spec.rb