Permalink
Browse files

+ 1.5.0, + cleanly raise on nil number in interface methods

  • Loading branch information...
1 parent 8b48990 commit c05b4765a51e7f203477321b717f425fa8dbbce0 @floere committed Oct 12, 2011
Showing with 22 additions and 1 deletion.
  1. +3 −0 lib/phony.rb
  2. +1 −1 phony.gemspec
  3. +18 −0 spec/lib/phony_spec.rb
View
@@ -45,6 +45,7 @@ class << self
# Useful before inserting the number into a database.
#
def normalize phone_number
+ raise ArgumentError, "Phone number cannot be nil. Use e.g. number && Phony.normalize(number)." unless phone_number
normalize! phone_number.dup
end
def normalize! phone_number
@@ -54,6 +55,7 @@ def normalize! phone_number
# Splits the phone number into pieces according to the country codes.
#
def split phone_number
+ raise ArgumentError, "Phone number cannot be nil. Use e.g. number && Phony.split(number)." unless phone_number
split! phone_number.dup
end
def split! phone_number
@@ -63,6 +65,7 @@ def split! phone_number
# Formats a E164 number according to local customs.
#
def format phone_number, options = {}
+ raise ArgumentError, "Phone number cannot be nil. Use e.g. number && Phony.format(number)." unless phone_number
formatted! phone_number.dup, options
end
def format! phone_number, options = {}
View
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'phony'
- s.version = '1.4.6'
+ s.version = '1.5.0'
s.authors = ['Florian Hanke']
s.email = 'florian.hanke+phony@gmail.com'
s.homepage = 'http://github.com/floere/phony'
View
@@ -4,6 +4,24 @@
describe Phony do
+ describe 'nil cases' do
+ it "should raise on normalize nil" do
+ expect {
+ Phony.normalize(nil)
+ }.to raise_error(ArgumentError, "Phone number cannot be nil. Use e.g. number && Phony.normalize(number).")
+ end
+ it "should raise on format nil" do
+ expect {
+ Phony.format(nil)
+ }.to raise_error(ArgumentError, "Phone number cannot be nil. Use e.g. number && Phony.format(number).")
+ end
+ it "should raise on split nil" do
+ expect {
+ Phony.split(nil)
+ }.to raise_error(ArgumentError, "Phone number cannot be nil. Use e.g. number && Phony.split(number).")
+ end
+ end
+
describe "normalize" do
describe "some examples" do
it "should normalize an already normalized number" do

0 comments on commit c05b476

Please sign in to comment.