Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creates tests for Address#zip_code #746

Merged
merged 1 commit into from
Dec 17, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions test/test_faker_zip_code.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
require File.dirname(__FILE__) + '/test_helper.rb'

class TestFakerZipCode < Test::Unit::TestCase
def setup
@zip_codes_without_state = ['50817', '48666', '55551', '14242', '99852']
@zip_codes_with_state = ['55555', '44444', '33333', '22222', '11111']

@old_locales = I18n.config.available_locales

locale_without_state = {
:faker => {
:address => {
:state_abbreviation => [''],
:postcode => @zip_codes_without_state
}
}
}

locale_with_state = {
:faker => {
:address => {
:postcode_by_state => {
:NY => @zip_codes_with_state
}
}
}
}

I18n.backend.store_translations(:xy, locale_without_state)
I18n.backend.store_translations(:xz, locale_with_state)
I18n.config.available_locales += [:xy, :xz]
@tester = Faker::Address
end

def teardown
I18n.config.available_locales = @old_locales
end

def test_default_zip_codes_without_states
I18n.with_locale(:xy) do
zip_codes = @zip_codes_without_state
100.times do
zip_code = @tester.zip_code
assert zip_codes.include?(zip_code), "Expected <#{zip_codes.join(' / ')}>, but got #{zip_code}"
end
end
end

def test_zip_codes_with_states
I18n.with_locale(:xz) do
zip_codes = @zip_codes_with_state
100.times do
zip_code = @tester.zip_code('NY')
assert zip_codes.include?(zip_code), "Expected <#{zip_codes.join(' / ')}>, but got #{zip_code}"
end
end
end

def test_zip_codes_with_states_with_inexisting_state
assert_raises I18n::MissingTranslationData do
I18n.with_locale(:xz) do
@tester.zip_code('MI')
end
end
end
end