test/carmen_test.rb in carmen-0.1.1 vs test/carmen_test.rb in carmen-0.2.0
- old
+ new
@@ -1,26 +1,65 @@
-require 'test/unit'
-require File.join(File.dirname(__FILE__), '../lib/carmen')
+require File.expand_path('test_helper', File.dirname(__FILE__))
class TestCarmen < Test::Unit::TestCase
+ def teardown
+ Carmen.default_locale = :en # restore default
+ end
+
+ def test_default_countries
+ assert_equal ['Aland Islands', 'AX'], Carmen.countries[1]
+ end
+
+ def test_localized_countries
+ Carmen.default_locale = :de
+ assert_equal ["Ascension (verwaltet von St. Helena)", 'AC'], Carmen.countries[0]
+ end
+
+ def test_single_localized_countries_call
+ # Check that we are working with the default
+ assert_equal ['Aland Islands', 'AX'], Carmen.countries[1]
+
+ # Switch to a different locale for one call
+ assert_equal ["Ascension (verwaltet von St. Helena)", 'AC'], Carmen.countries(:locale => 'de')[0]
+
+ # Make sure that we are back in the default locale
+ assert_equal ['Aland Islands', 'AX'], Carmen.countries[1]
+ end
+
def test_country_name
assert_equal 'United States', Carmen.country_name('US')
+ assert_equal 'United States', Carmen.country_name('us')
end
+ def test_localized_country_name
+ assert_equal 'Germany', Carmen.country_name('DE')
+ assert_equal 'Deutschland', Carmen.country_name('DE', :locale => :de)
+ Carmen.default_locale = :de
+ assert_equal 'Deutschland', Carmen.country_name('DE')
+ end
+
def test_country_code
assert_equal 'CA', Carmen.country_code('Canada')
+ assert_equal 'CA', Carmen.country_code('canada')
+ assert_equal 'IR', Carmen.country_code('Iran')
end
+ def test_localized_country_code
+ assert_equal 'DE', Carmen.country_code('Deutschland', :locale => :de)
+ Carmen.default_locale = :de
+ assert_equal 'DE', Carmen.country_code('Deutschland')
+ end
+
def test_country_codes
assert_equal 'AF', Carmen.country_codes.first
- assert_equal 243, Carmen.country_codes.length
+ assert_equal 245, Carmen.country_codes.length
end
def test_country_names
assert_equal 'Afghanistan', Carmen.country_names.first
- assert_equal 243, Carmen.country_names.length
+ assert_equal 245, Carmen.country_names.length
end
def test_state_name
assert_equal 'IL', Carmen.state_code('Illinois')
assert_equal 'MB', Carmen.state_code('Manitoba', 'CA')
@@ -67,7 +106,12 @@
assert_raises Carmen::StatesNotSupported do
Carmen::state_codes('ID')
end
end
+ def test_unsupported_locale
+ assert_raises Carmen::UnavailableLocale do
+ Carmen.countries(:locale => :latin)
+ end
+ end
-end
\ No newline at end of file
+end