test/phonelib_test.rb in phonelib-0.1.3 vs test/phonelib_test.rb in phonelib-0.2.0

- old
+ new

@@ -15,10 +15,17 @@ should 'be possible but not valid phone number' do assert !@phone.valid? assert @phone.possible? end + + context 'with international formatting' do + setup { @phone = Phonelib.parse('+1 (972) 123-4567', 'US') } + should 'return exact original' do + assert_equal '+1 (972) 123-4567', @phone.original + end + end end context '.valid?' do context 'with malformed phone number' do should 'not be valid' do @@ -168,8 +175,27 @@ end should 'return sanitized national when number invalid but possible' do phone = Phonelib.parse('9721234567') assert_equal '1234567', phone.national + end + end + + context 'default_country' do + should 'be invalid with no default country set' do + phone = Phonelib.parse('541234567') + assert !phone.valid? + end + + should 'valid with default country set' do + Phonelib.default_country = :IL + phone = Phonelib.parse('541234567') + assert phone.valid? + end + + should 'valid with wrong default country set' do + Phonelib.default_country = :UA + phone = Phonelib.parse('972541234567') + assert phone.valid? end end end