phony 1.4.6 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/phony.rb +3 -0
  2. data/spec/lib/phony_spec.rb +18 -0
  3. metadata +2 -2
data/lib/phony.rb CHANGED
@@ -45,6 +45,7 @@ module Phony
45
45
  # Useful before inserting the number into a database.
46
46
  #
47
47
  def normalize phone_number
48
+ raise ArgumentError, "Phone number cannot be nil. Use e.g. number && Phony.normalize(number)." unless phone_number
48
49
  normalize! phone_number.dup
49
50
  end
50
51
  def normalize! phone_number
@@ -54,6 +55,7 @@ module Phony
54
55
  # Splits the phone number into pieces according to the country codes.
55
56
  #
56
57
  def split phone_number
58
+ raise ArgumentError, "Phone number cannot be nil. Use e.g. number && Phony.split(number)." unless phone_number
57
59
  split! phone_number.dup
58
60
  end
59
61
  def split! phone_number
@@ -63,6 +65,7 @@ module Phony
63
65
  # Formats a E164 number according to local customs.
64
66
  #
65
67
  def format phone_number, options = {}
68
+ raise ArgumentError, "Phone number cannot be nil. Use e.g. number && Phony.format(number)." unless phone_number
66
69
  formatted! phone_number.dup, options
67
70
  end
68
71
  def format! phone_number, options = {}
@@ -4,6 +4,24 @@ require 'spec_helper'
4
4
 
5
5
  describe Phony do
6
6
 
7
+ describe 'nil cases' do
8
+ it "should raise on normalize nil" do
9
+ expect {
10
+ Phony.normalize(nil)
11
+ }.to raise_error(ArgumentError, "Phone number cannot be nil. Use e.g. number && Phony.normalize(number).")
12
+ end
13
+ it "should raise on format nil" do
14
+ expect {
15
+ Phony.format(nil)
16
+ }.to raise_error(ArgumentError, "Phone number cannot be nil. Use e.g. number && Phony.format(number).")
17
+ end
18
+ it "should raise on split nil" do
19
+ expect {
20
+ Phony.split(nil)
21
+ }.to raise_error(ArgumentError, "Phone number cannot be nil. Use e.g. number && Phony.split(number).")
22
+ end
23
+ end
24
+
7
25
  describe "normalize" do
8
26
  describe "some examples" do
9
27
  it "should normalize an already normalized number" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phony
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.6
4
+ version: 1.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-11 00:00:00.000000000 +02:00
12
+ date: 2011-10-12 00:00:00.000000000 +02:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
  description: ! 'Fast international phone number (E164 standard) normalizing, splitting