Sha256: 4ee99808ac52524a100dbbdb7baa950f3e496c20af3a89a80a15da2b276224b1

Contents?: true

Size: 1.41 KB

Versions: 16

Compression:

Stored size: 1.41 KB

Contents

require 'spec_helper'

describe Ziptz do
  describe 'when inspected' do
    let(:ziptz) { Ziptz.new }

    it 'does not show internal instance variables' do
      expect(ziptz.inspect).to match /#<Ziptz:\d+>/
    end
  end

  describe '#time_zone_name' do
    let(:ziptz) { Ziptz.new }

    context 'when given a 5-digit zipcode' do
      it 'returns the time zone number' do
        expect(ziptz.time_zone_name('97034')).to eq 'Pacific'
      end
    end

    context 'when there is no matching zipcode' do
      it 'returns nil' do
        expect(ziptz.time_zone_name('xyz')).to be_nil
      end
    end
  end

  describe '#time_zone_offset' do
    let(:ziptz) { Ziptz.new }

    context 'when given a 5-digit zipcode' do
      it 'returns the time zone number' do
        expect(ziptz.time_zone_offset('97034')).to eq -8
      end
    end

    context 'when there is no matching zipcode' do
      it 'returns nil' do
        expect(ziptz.time_zone_offset('xyz')).to be_nil
      end
    end
  end

  describe '#zips' do
    context 'when given a time zone' do
      let(:ziptz) { Ziptz.new }

      it 'returns an array of zip codes' do
        expect(ziptz.zips('American Samoa')).to eq %w(96799)
      end

      it 'is case-insensitive' do
        expect(ziptz.zips('american samoa')).to eq %w(96799)
      end

      it 'returns nil for unknown time zones' do
        expect(ziptz.zips('Glark')).to be_nil
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ziptz-1.0.35 spec/ziptz_spec.rb
ziptz-1.0.34 spec/ziptz_spec.rb
ziptz-1.0.33 spec/ziptz_spec.rb
ziptz-1.0.32 spec/ziptz_spec.rb
ziptz-1.0.31 spec/ziptz_spec.rb
ziptz-1.0.30 spec/ziptz_spec.rb
ziptz-1.0.29 spec/ziptz_spec.rb
ziptz-1.0.28 spec/ziptz_spec.rb
ziptz-1.0.27 spec/ziptz_spec.rb
ziptz-1.0.26 spec/ziptz_spec.rb
ziptz-1.0.25 spec/ziptz_spec.rb
ziptz-1.0.24 spec/ziptz_spec.rb
ziptz-1.0.23 spec/ziptz_spec.rb
ziptz-1.0.22 spec/ziptz_spec.rb
ziptz-1.0.21 spec/ziptz_spec.rb
ziptz-1.0.20 spec/ziptz_spec.rb