phony 2.18.3 → 2.20.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/README.textile +5 -1
  3. data/lib/phony/countries/argentina.rb +355 -0
  4. data/lib/phony/countries/austria.rb +2 -2
  5. data/lib/phony/countries/cambodia.rb +1 -5
  6. data/lib/phony/countries/china.rb +5 -2
  7. data/lib/phony/countries/germany.rb +1 -1
  8. data/lib/phony/countries/ireland.rb +6 -4
  9. data/lib/phony/countries/italy.rb +34 -17
  10. data/lib/phony/countries/japan.rb +58 -8
  11. data/lib/phony/countries/libya.rb +1 -1
  12. data/lib/phony/countries/serbia.rb +5 -1
  13. data/lib/phony/countries/taiwan.rb +1 -0
  14. data/lib/phony/countries/vietnam.rb +1 -0
  15. data/lib/phony/countries.rb +83 -53
  16. data/lib/phony/country.rb +8 -2
  17. data/lib/phony/country_codes.rb +15 -2
  18. data/lib/phony/dsl.rb +2 -2
  19. data/lib/phony/local_splitters/fixed.rb +2 -0
  20. data/lib/phony/national_code.rb +1 -1
  21. data/lib/phony/national_splitters/none.rb +1 -3
  22. data/lib/phony/trunk_code.rb +5 -5
  23. data/lib/phony.rb +1 -0
  24. data/spec/functional/config_spec.rb +5 -5
  25. data/spec/functional/plausibility_spec.rb +82 -16
  26. data/spec/lib/phony/countries_spec.rb +86 -23
  27. data/spec/lib/phony/country_codes_spec.rb +82 -58
  28. data/spec/lib/phony/country_spec.rb +29 -9
  29. data/spec/lib/phony/dsl_spec.rb +6 -2
  30. data/spec/lib/phony/local_splitters/regex_spec.rb +12 -15
  31. data/spec/lib/phony/national_code_spec.rb +15 -45
  32. data/spec/lib/phony/national_splitters/fixed_spec.rb +12 -16
  33. data/spec/lib/phony/national_splitters/none_spec.rb +3 -3
  34. data/spec/lib/phony/national_splitters/variable_spec.rb +9 -13
  35. data/spec/lib/phony/trunk_code_spec.rb +85 -0
  36. data/spec/lib/phony/vanity_spec.rb +4 -4
  37. metadata +21 -19
@@ -1,199 +1,223 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Phony::CountryCodes do
4
-
5
- before(:all) do
6
- @countries = Phony::CountryCodes.instance
4
+
5
+ let(:countries) { Phony::CountryCodes.instance }
6
+
7
+ describe '#plausible?' do
8
+ it 'raises an error on a too long ccc' do
9
+ expect do
10
+ countries.plausible?('+1 868 7620266', ccc: '1868123')
11
+ end.to raise_error(ArgumentError, %Q{The provided ccc option is too long and includes more than a cc ('1') and ndc ('868'). It also includes '123'.})
12
+ end
13
+ end
14
+
15
+ describe 'ccc handling' do
16
+ it 'splits a ccc correctly' do
17
+ cc, ndc, *local = countries.split('1868')
18
+
19
+ expect(cc).to eq '1'
20
+ expect(ndc).to eq '868'
21
+ end
22
+ it 'splits a ccc correctly' do
23
+ cc, ndc, *local = countries.split('1868')
24
+
25
+ expect(cc).to eq '1'
26
+ expect(ndc).to eq '868'
27
+ end
7
28
  end
8
29
 
9
30
  describe '#[]' do
10
31
  it 'returns a country' do
11
- @countries['41'].class.should eql Phony::Country
32
+ expect(countries['41'].class).to eq Phony::Country
12
33
  end
13
34
  end
14
35
 
15
36
  describe '#country_for' do
16
37
  it 'returns a country' do
17
- @countries.send(:country_for, '41').class.should eql Phony::Country
38
+ expect(countries.send(:country_for, '41').class).to eq Phony::Country
18
39
  end
19
40
  end
20
41
 
21
42
  describe '#countrify' do
22
43
  it 'returns a country' do
23
- @countries.send(:countrify, '441231212', '41').should eql '41441231212'
44
+ expect(countries.send(:countrify, '441231212', '41')).to eq '41441231212'
24
45
  end
25
46
  end
26
47
  describe '#countrify!' do
27
48
  it 'in-place replaces the number' do
28
49
  number = '441231212'
29
- @countries.send(:countrify!, number, '41').should eql number
50
+ expect(countries.send(:countrify!, number, '41')).to eq number
30
51
 
31
- number.should == '41441231212'
52
+ expect(number).to eq '41441231212'
32
53
  end
33
54
  end
34
55
 
35
56
  describe '#vanity?' do
36
57
  it 'returns true if so' do
37
- @countries.vanity?('1800HELLOES').should eql true
58
+ expect(countries.vanity?('1800HELLOES')).to eq true
38
59
  end
39
60
  it 'returns false if not' do
40
- @countries.vanity?('18001234567').should eql false
61
+ expect(countries.vanity?('18001234567')).to eq false
41
62
  end
42
63
  end
43
64
 
44
65
  describe 'normalize' do
45
66
  it 'normalizes correctly' do
46
- @countries.normalize('0041-44-364-35-32').should eql '41443643532'
67
+ expect(countries.normalize('0041-44-364-35-32')).to eq '41443643532'
47
68
  end
48
69
  it 'normalizes correctly with CC option' do
49
- @countries.normalize('044-364-35-32', cc: '41').should eql '41443643532'
70
+ expect(countries.normalize('044-364-35-32', cc: '41')).to eq '41443643532'
50
71
  end
51
72
 
52
73
  context 'specific countries' do
53
74
  it 'handles Congo correctly' do
54
- @countries.normalize('+242 0571 73992').should eql '242057173992'
55
- @countries.normalize('+242 2221 15932').should eql '242222115932'
75
+ expect(countries.normalize('+242 0571 73992')).to eq '242057173992'
76
+ expect(countries.normalize('+242 2221 15932')).to eq '242222115932'
56
77
  end
57
78
  end
58
79
  end
59
80
 
60
81
  describe 'formatted' do
61
82
  it 'formats correctly' do
62
- @countries.formatted('41443643532', :format => :international, :spaces => :-).should eql '+41-44-364-35-32'
83
+ expect(countries.formatted('41443643532', :format => :international, :spaces => :-)).to eq '+41-44-364-35-32'
63
84
  end
64
85
  it 'formats correctly' do
65
- @countries.formatted('41443643532', :format => :international_relative, :spaces => :-).should eql '0041-44-364-35-32'
86
+ expect(countries.formatted('41443643532', :format => :international_relative, :spaces => :-)).to eq '0041-44-364-35-32'
66
87
  end
67
88
  it 'formats correctly' do
68
- @countries.formatted('41443643532', :format => :national, :spaces => :-).should eql '044-364-35-32'
89
+ expect(countries.formatted('41443643532', :format => :national, :spaces => :-)).to eq '044-364-35-32'
69
90
  end
70
91
  context 'specific' do
71
92
  it 'formats Ireland correctly' do
72
- @countries.formatted("3533451234", :format => :national).should eql '0345 1234'
93
+ expect(countries.formatted("3533451234", :format => :national)).to eq '0345 1234'
73
94
  end
74
95
  it 'formats Ireland correctly' do
75
- @countries.formatted("353411231234", :format => :national).should eql '041 123 1234'
96
+ expect(countries.formatted("353411231234", :format => :national)).to eq '041 123 1234'
76
97
  end
77
98
  it 'formats Spain correctly' do
78
- @countries.formatted("34123456789", :format => :national).should eql '123 456 789'
99
+ expect(countries.formatted("34123456789", :format => :national)).to eq '123 456 789'
79
100
  end
80
101
  it 'formats Cambodia correctly' do
81
- @countries.formatted('85512239123', :format => :national).should eql '012 239 123'
102
+ expect(countries.formatted('85512239123', :format => :national)).to eq '012 239 123'
82
103
  end
83
104
  it 'formats the US correctly' do
84
- @countries.formatted('18005551212', :format => :national, :spaces => :-).should eql '(800)-555-1212'
105
+ expect(countries.formatted('18005551212', :format => :national, :spaces => :-)).to eq '(800)-555-1212'
85
106
  end
86
107
  it 'formats the US correctly' do
87
- @countries.formatted('18005551212', :format => :national, :spaces => :-).should eql '(800)-555-1212'
108
+ expect(countries.formatted('18005551212', :format => :national, :spaces => :-)).to eq '(800)-555-1212'
88
109
  end
89
110
  end
90
111
  context 'default' do
91
112
  it "should format swiss numbers" do
92
- @countries.formatted('41443643532').should eql '+41 44 364 35 32'
113
+ expect(countries.formatted('41443643532')).to eq '+41 44 364 35 32'
93
114
  end
94
115
  it "should format swiss service numbers" do
95
- @countries.formatted('41800112233').should eql '+41 800 112 233'
116
+ expect(countries.formatted('41800112233')).to eq '+41 800 112 233'
96
117
  end
97
118
  it "should format austrian numbers" do
98
- @countries.formatted('43198110').should eql '+43 1 98110'
119
+ expect(countries.formatted('43198110')).to eq '+43 1 98110'
99
120
  end
100
121
  it "should format american numbers" do
101
- @countries.formatted('18705551122').should eql '+1 (870) 555-1122'
122
+ expect(countries.formatted('18705551122')).to eq '+1 (870) 555-1122'
102
123
  end
103
124
  it "should format irish numbers" do
104
- @countries.formatted('35311234567').should eql '+353 1 123 4567'
125
+ expect(countries.formatted('35311234567')).to eq '+353 1 123 4567'
105
126
  end
106
127
  end
107
128
  describe "international" do
108
129
  it "should format north american numbers" do
109
- @countries.formatted('18091231234', :format => :international).should eql '+1 (809) 123-1234'
130
+ expect(countries.formatted('18091231234', :format => :international)).to eq '+1 (809) 123-1234'
110
131
  end
111
132
  it "should format austrian numbers" do
112
- @countries.formatted('43198110', :format => :international).should eql '+43 1 98110'
133
+ expect(countries.formatted('43198110', :format => :international)).to eq '+43 1 98110'
113
134
  end
114
135
  it "should format austrian numbers" do
115
- @countries.formatted('43198110', :format => :international_absolute).should eql '+43 1 98110'
136
+ expect(countries.formatted('43198110', :format => :international_absolute)).to eq '+43 1 98110'
116
137
  end
117
138
  it "should format french numbers" do
118
- @countries.formatted('33142278186', :format => :+).should eql '+33 1 42 27 81 86'
139
+ expect(countries.formatted('33142278186', :format => :+)).to eq '+33 1 42 27 81 86'
119
140
  end
120
141
  it "should format austrian numbers" do
121
- @countries.formatted('43198110', :format => :international_relative).should eql '0043 1 98110'
142
+ expect(countries.formatted('43198110', :format => :international_relative)).to eq '0043 1 98110'
122
143
  end
123
144
  it 'should format liechtensteiner numbers' do
124
- @countries.formatted('4233841148', :format => :international_relative).should eql '00423 384 11 48'
145
+ expect(countries.formatted('4233841148', :format => :international_relative)).to eq '00423 384 11 48'
125
146
  end
126
147
  it "should format irish numbers" do
127
- @countries.formatted('35311234567', :format => :international).should eql '+353 1 123 4567'
148
+ expect(countries.formatted('35311234567', :format => :international)).to eq '+353 1 123 4567'
128
149
  end
129
150
  it "should format luxembourgian numbers" do
130
- @countries.formatted('352222809', :format => :international).should eql '+352 22 28 09'
151
+ expect(countries.formatted('352222809', :format => :international)).to eq '+352 22 28 09'
131
152
  end
132
153
  it "should format luxembourgian 4-digit ndc numbers" do
133
- @countries.formatted('35226222809', :format => :international).should eql '+352 2622 28 09'
154
+ expect(countries.formatted('35226222809', :format => :international)).to eq '+352 2622 28 09'
134
155
  end
135
156
  it "should format luxembourgian mobile numbers" do
136
- @countries.formatted('352621123456', :format => :international).should eql '+352 621 123 456'
157
+ expect(countries.formatted('352621123456', :format => :international)).to eq '+352 621 123 456'
137
158
  end
138
159
  it "should format luxembourgian city numbers" do
139
- @countries.formatted('3524123456', :format => :international).should eql '+352 41 23 45 6'
160
+ expect(countries.formatted('3524123456', :format => :international)).to eq '+352 41 23 45 6'
140
161
  end
141
162
  it "should format luxembourgian machine to machine numbers" do
142
- @countries.formatted('352602112345678', :format => :international).should eql '+352 6021 12 34 56 78'
163
+ expect(countries.formatted('352602112345678', :format => :international)).to eq '+352 6021 12 34 56 78'
143
164
  end
144
165
  it "should format luxembourgian numbers" do
145
- @countries.formatted('352370431', :format => :international).should eql '+352 37 04 31'
166
+ expect(countries.formatted('352370431', :format => :international)).to eq '+352 37 04 31'
146
167
  end
147
168
  it "should format luxembourgian numbers" do
148
- @countries.formatted('35227855', :format => :international).should eql '+352 27 85 5'
169
+ expect(countries.formatted('35227855', :format => :international)).to eq '+352 27 85 5'
170
+ end
171
+ it "should format nigerian lagosian numbers" do
172
+ expect(countries.formatted('23414480000', :format => :international)).to eq '+234 1 448 0000'
149
173
  end
150
- it "should format nigerian numbers" do
151
- @countries.formatted('23414480000', :format => :international).should eql '+234 1 448 0000'
174
+ it "should format nigerian beninese numbers" do
175
+ expect(countries.formatted('23452123456', :format => :international)).to eq '+234 52 123 456'
152
176
  end
153
177
  it "should format nigerian mobile numbers" do
154
- @countries.formatted('2347061234567', :format => :international).should eql '+234 706 123 4567'
178
+ expect(countries.formatted('2347061234567', :format => :international)).to eq '+234 706 123 4567'
155
179
  end
156
180
  context 'with no spaces' do
157
181
  it "should format north american numbers" do
158
- Phony.formatted('18091231234', :format => :international, :spaces => '').should eql '+1(809)123-1234'
182
+ expect(Phony.formatted('18091231234', :format => :international, :spaces => '')).to eq '+1(809)123-1234'
159
183
  end
160
184
  it "should format austrian numbers" do
161
- Phony.formatted('43198110', :format => :international, :spaces => '').should eql '+43198110'
185
+ expect(Phony.formatted('43198110', :format => :international, :spaces => '')).to eq '+43198110'
162
186
  end
163
187
  it "should format austrian numbers" do
164
- Phony.formatted('43198110', :format => :international_absolute, :spaces => '').should eql '+43198110'
188
+ expect(Phony.formatted('43198110', :format => :international_absolute, :spaces => '')).to eq '+43198110'
165
189
  end
166
190
  it "should format french numbers" do
167
- Phony.formatted('33142278186', :format => :+, :spaces => '').should eql '+33142278186'
191
+ expect(Phony.formatted('33142278186', :format => :+, :spaces => '')).to eq '+33142278186'
168
192
  end
169
193
  it "should format austrian numbers" do
170
- Phony.formatted('43198110', :format => :international_relative, :spaces => '').should eql '0043198110'
194
+ expect(Phony.formatted('43198110', :format => :international_relative, :spaces => '')).to eq '0043198110'
171
195
  end
172
196
  it 'should format liechtensteiner numbers' do
173
- Phony.formatted('4233841148', :format => :international_relative, :spaces => '').should eql '004233841148'
197
+ expect(Phony.formatted('4233841148', :format => :international_relative, :spaces => '')).to eq '004233841148'
174
198
  end
175
199
  end
176
200
  context 'with special spaces' do
177
201
  it "should format swiss numbers" do
178
- Phony.formatted('41443643532', :format => :international).should eql '+41 44 364 35 32'
202
+ expect(Phony.formatted('41443643532', :format => :international)).to eq '+41 44 364 35 32'
179
203
  end
180
204
  it "should format north american numbers" do
181
- Phony.formatted('18091231234', :format => :international, :spaces => :-).should eql '+1-(809)-123-1234'
205
+ expect(Phony.formatted('18091231234', :format => :international, :spaces => :-)).to eq '+1-(809)-123-1234'
182
206
  end
183
207
  it "should format austrian numbers" do
184
- Phony.formatted('43198110', :format => :international, :spaces => :-).should eql '+43-1-98110'
208
+ expect(Phony.formatted('43198110', :format => :international, :spaces => :-)).to eq '+43-1-98110'
185
209
  end
186
210
  it "should format austrian numbers" do
187
- Phony.formatted('43198110', :format => :international_absolute, :spaces => :-).should eql '+43-1-98110'
211
+ expect(Phony.formatted('43198110', :format => :international_absolute, :spaces => :-)).to eq '+43-1-98110'
188
212
  end
189
213
  it "should format french numbers" do
190
- Phony.formatted('33142278186', :format => :+, :spaces => :-).should eql '+33-1-42-27-81-86'
214
+ expect(Phony.formatted('33142278186', :format => :+, :spaces => :-)).to eq '+33-1-42-27-81-86'
191
215
  end
192
216
  it "should format austrian numbers" do
193
- Phony.formatted('43198110', :format => :international_relative, :spaces => :-).should eql '0043-1-98110'
217
+ expect(Phony.formatted('43198110', :format => :international_relative, :spaces => :-)).to eq '0043-1-98110'
194
218
  end
195
219
  it 'should format liechtensteiner numbers' do
196
- Phony.formatted('4233841148', :format => :international_relative, :spaces => :-).should eql '00423-384-11-48'
220
+ expect(Phony.formatted('4233841148', :format => :international_relative, :spaces => :-)).to eq '00423-384-11-48'
197
221
  end
198
222
 
199
223
  end
@@ -12,18 +12,18 @@ describe Phony::Country do
12
12
  end
13
13
  describe '#clean' do
14
14
  it 'cleans the number' do
15
- country.clean('+41-44-123-12-12').should eql '41441231212'
15
+ expect(country.clean('+41-44-123-12-12')).to eq '41441231212'
16
16
  end
17
17
  end
18
18
  describe '#vanity_to_number' do
19
19
  it 'turns the vanity number into a number' do
20
- country.vanity_to_number('1-800-HELLO').should eql '1-800-43556'
20
+ expect(country.vanity_to_number('1-800-HELLO')).to eq '1-800-43556'
21
21
  end
22
22
  end
23
23
  end
24
24
 
25
25
  context 'regression' do
26
- describe 'iceland' do
26
+ describe 'Iceland' do
27
27
  let(:country) do
28
28
  national_splitter = Phony::NationalSplitters::None.instance_for
29
29
  local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 4]
@@ -32,7 +32,27 @@ describe Phony::Country do
32
32
  described_class.new national_code
33
33
  end
34
34
  it 'splits correctly' do
35
- country.split('112').should == [nil, false, '112']
35
+ expect(country.split('112')).to eq [nil, false, '112']
36
+ end
37
+ end
38
+ describe 'San Marino' do
39
+ it 'normalizes correctly' do
40
+ expect(Phony.normalize('+3780549903549')).to eq '3780549903549'
41
+ end
42
+ xit 'automatically adds the sole NC' do
43
+ expect(Phony.normalize('+378903549')).to eq '3780549903549'
44
+ end
45
+ end
46
+ describe 'Japan' do
47
+ it 'normalizes correctly' do
48
+ expect(Phony.normalize('+81-03-1234-5634')).to eq '81312345634'
49
+ expect(Phony.normalize('03-1234-5634', cc: '81')).to eq '81312345634'
50
+ end
51
+ it 'formats correctly' do
52
+ expect(Phony.format('81312345634')).to eq '+81-3-1234-5634'
53
+ end
54
+ it 'splits correctly' do
55
+ expect(Phony.split('81312345634')).to eq %w(81 3 1234 5634)
36
56
  end
37
57
  end
38
58
  end
@@ -48,12 +68,12 @@ describe Phony::Country do
48
68
 
49
69
  describe "split" do
50
70
  it "should handle ZH" do
51
- country.split('443643532').should == [nil, '44', '364', '35', '32']
71
+ expect(country.split('443643532')).to eq [nil, '44', '364', '35', '32']
52
72
  end
53
73
  end
54
74
  describe 'normalize' do
55
75
  it "should handle ZH" do
56
- country.normalize('0443643532').should == '443643532'
76
+ expect(country.normalize('0443643532')).to eq '443643532'
57
77
  end
58
78
  end
59
79
  end
@@ -73,12 +93,12 @@ describe Phony::Country do
73
93
 
74
94
  describe "split" do
75
95
  it "should handle ZH" do
76
- country.split('443643532').should == [nil, '44', '364', '35', '32']
96
+ expect(country.split('443643532')).to eq [nil, '44', '364', '35', '32']
77
97
  end
78
98
  it "should handle 800" do
79
- country.split('800333666').should == [nil, '800', '333', '666']
99
+ expect(country.split('800333666')).to eq [nil, '800', '333', '666']
80
100
  end
81
101
  end
82
102
  end
83
103
 
84
- end
104
+ end
@@ -7,9 +7,13 @@ describe Phony::DSL do
7
7
  let(:dsl) { described_class.new }
8
8
 
9
9
  it 'has a todo' do
10
+ result = nil
11
+
10
12
  Phony.define do
11
- todo.split("123456789012345").should == [nil, false, '123456789012345']
13
+ result = todo.split("123456789012345")
12
14
  end
15
+
16
+ expect(result).to eq [nil, false, '123456789012345']
13
17
  end
14
18
 
15
19
  describe 'match' do
@@ -17,7 +21,7 @@ describe Phony::DSL do
17
21
  expect { dsl.match(/123/) }.to raise_error("Regexp /123/ needs a group in it that defines which digits belong to the NDC.")
18
22
  end
19
23
  it 'should return a Phony::NationalSplitters::Regex' do
20
- dsl.match(/(123)/).class.name.should == Phony::NationalSplitters::Regex.name
24
+ expect(dsl.match(/(123)/).class.name).to eq Phony::NationalSplitters::Regex.name
21
25
  end
22
26
  end
23
27
 
@@ -16,40 +16,37 @@ describe Phony::LocalSplitters::Regex do
16
16
  end
17
17
 
18
18
  describe 'split' do
19
- before(:each) do
20
- # Norway as example.
21
- #
22
- @splitter = described_class.instance_for(/^[489].*$/ => [3,2,3], :fallback => [2,2,2,2])
23
- end
19
+ # Norway.
20
+ let(:splitter) { described_class.instance_for(/^[489].*$/ => [3,2,3], :fallback => [2,2,2,2]) }
24
21
  it 'splits a number correctly' do
25
- @splitter.split('21234567').should == ['21','23','45','67']
22
+ expect(splitter.split('21234567')).to eq ['21','23','45','67']
26
23
  end
27
24
  it 'splits a number correctly' do
28
- @splitter.split('31234567').should == ['31','23','45','67']
25
+ expect(splitter.split('31234567')).to eq ['31','23','45','67']
29
26
  end
30
27
  it 'splits a number correctly' do
31
- @splitter.split('41234567').should == ['412','34','567']
28
+ expect(splitter.split('41234567')).to eq ['412','34','567']
32
29
  end
33
30
  it 'splits a number correctly' do
34
- @splitter.split('51234567').should == ['51','23','45','67']
31
+ expect(splitter.split('51234567')).to eq ['51','23','45','67']
35
32
  end
36
33
  it 'splits a number correctly' do
37
- @splitter.split('61234567').should == ['61','23','45','67']
34
+ expect(splitter.split('61234567')).to eq ['61','23','45','67']
38
35
  end
39
36
  it 'splits a number correctly' do
40
- @splitter.split('71234567').should == ['71','23','45','67']
37
+ expect(splitter.split('71234567')).to eq ['71','23','45','67']
41
38
  end
42
39
  it 'splits a number correctly' do
43
- @splitter.split('81234567').should == ['812','34','567']
40
+ expect(splitter.split('81234567')).to eq ['812','34','567']
44
41
  end
45
42
  it 'splits a number correctly' do
46
- @splitter.split('91234567').should == ['912','34','567']
43
+ expect(splitter.split('91234567')).to eq ['912','34','567']
47
44
  end
48
45
  it 'splits it fast' do
49
- performance_of { @splitter.split('21234567').should == ['21','23','45','67'] }.should < 0.00005
46
+ expect(performance_of { splitter.split('21234567') }).to be < 0.00005
50
47
  end
51
48
  it 'splits it fast' do
52
- performance_of { @splitter.split('91234567').should == ['912','34','567'] }.should < 0.00004
49
+ expect(performance_of { splitter.split('91234567') }).to be < 0.00004
53
50
  end
54
51
  end
55
52
 
@@ -5,87 +5,57 @@ describe Phony::NationalCode do
5
5
  describe 'split' do
6
6
  context 'regression' do
7
7
  describe 'iceland' do
8
- before(:each) do
8
+ let(:national) do
9
9
  national_splitter = Phony::NationalSplitters::None.instance_for
10
10
  local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 4]
11
11
 
12
- @national = Phony::NationalCode.new national_splitter, local_splitter
12
+ Phony::NationalCode.new national_splitter, local_splitter
13
13
  end
14
14
  it 'splits correctly' do
15
- @national.split('112').should == [nil, false, '112']
15
+ expect(national.split('112')).to eq [nil, false, '112']
16
16
  end
17
17
  end
18
18
  end
19
19
  context 'with fixed ndc (Swiss)' do
20
- before(:each) do
20
+ let(:national) do
21
21
  national_splitter = Phony::NationalSplitters::Fixed.instance_for 2
22
22
  local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 2, 2]
23
23
 
24
- @national = Phony::NationalCode.new national_splitter, local_splitter
24
+ Phony::NationalCode.new national_splitter, local_splitter
25
25
  end
26
26
  it 'splits correctly' do
27
- @national.split('443643532').should == [nil, '44', '364', '35', '32']
27
+ expect(national.split('443643532')).to eq [nil, '44', '364', '35', '32']
28
28
  end
29
29
  it 'splits correctly' do
30
- @national.split('44364353').should == [nil, '44', '364', '35', '3']
30
+ expect(national.split('44364353')).to eq [nil, '44', '364', '35', '3']
31
31
  end
32
32
  it 'normalizes correctly' do
33
- @national.normalize('044364353').should == '44364353'
33
+ expect(national.normalize('044364353')).to eq '44364353'
34
34
  end
35
35
  it 'normalizes correctly' do
36
- @national.normalize('44364353').should == '44364353'
36
+ expect(national.normalize('44364353')).to eq '44364353'
37
37
  end
38
38
  end
39
39
  context 'with fixed ndc (French)' do
40
- before(:each) do
40
+ let(:national) do
41
41
  national_splitter = Phony::NationalSplitters::Fixed.instance_for 1
42
42
  local_splitter = Phony::LocalSplitters::Fixed.instance_for [2, 2, 2, 2]
43
43
 
44
- @national = Phony::NationalCode.new national_splitter, local_splitter
44
+ Phony::NationalCode.new national_splitter, local_splitter
45
45
  end
46
46
  it 'splits correctly' do
47
- @national.split('142278186').should == [nil, '1', '42', '27', '81', '86']
47
+ expect(national.split('142278186')).to eq [nil, '1', '42', '27', '81', '86']
48
48
  end
49
49
  it 'splits correctly' do
50
- @national.split('14227818').should == [nil, '1', '42', '27', '81', '8']
50
+ expect(national.split('14227818')).to eq [nil, '1', '42', '27', '81', '8']
51
51
  end
52
52
  it 'normalizes correctly' do
53
- @national.normalize('0142278186').should == '142278186'
53
+ expect(national.normalize('0142278186')).to eq '142278186'
54
54
  end
55
55
  it 'normalizes correctly' do
56
- @national.normalize('142278186').should == '142278186'
56
+ expect(national.normalize('142278186')).to eq '142278186'
57
57
  end
58
58
  end
59
- # context 'normalizing' do
60
- # context 'false' do
61
- # before(:each) do
62
- # @national = Phony::NationalCode.new nil, nil, false
63
- # end
64
- # it 'normalizes an italian case correctly' do
65
- # @national.normalize('0909709511').should == '0909709511'
66
- # end
67
- # end
68
- # context 'true' do
69
- # before(:each) do
70
- # national_splitter = Phony::NationalSplitters::Fixed.instance_for 2
71
- # local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 2, 2]
72
- # @national = Phony::NationalCode.new national_splitter, local_splitter, true
73
- # end
74
- # it 'normalizes a swiss case correctly' do
75
- # @national.normalize('044364353').should == '44364353'
76
- # end
77
- # end
78
- # context 'nil (true)' do
79
- # before(:each) do
80
- # national_splitter = Phony::NationalSplitters::Fixed.instance_for 2
81
- # local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 2, 2]
82
- # @national = Phony::NationalCode.new national_splitter, local_splitter, nil
83
- # end
84
- # it 'normalizes a swiss case correctly' do
85
- # @national.normalize('044364353').should == '44364353'
86
- # end
87
- # end
88
- # end
89
59
  end
90
60
 
91
61
  end
@@ -4,45 +4,41 @@ describe Phony::NationalSplitters::Fixed do
4
4
 
5
5
  describe 'instance_for' do
6
6
  it 'caches' do
7
- Phony::NationalSplitters::Fixed.instance_for(3).should equal(Phony::NationalSplitters::Fixed.instance_for(3))
7
+ expect(Phony::NationalSplitters::Fixed.instance_for(3)).to eq Phony::NationalSplitters::Fixed.instance_for(3)
8
8
  end
9
9
  it 'caches correctly' do
10
- Phony::NationalSplitters::Fixed.instance_for(1).should_not equal(Phony::NationalSplitters::Fixed.instance_for(2))
10
+ expect(Phony::NationalSplitters::Fixed.instance_for(1)).to_not eq Phony::NationalSplitters::Fixed.instance_for(2)
11
11
  end
12
12
  end
13
13
 
14
14
  describe 'split' do
15
- before(:each) do
16
- @splitter = Phony::NationalSplitters::Fixed.new 2
17
- end
15
+ let(:splitter) { Phony::NationalSplitters::Fixed.new(2) }
18
16
  it 'splits correctly' do
19
- @splitter.split('443643532').should == [nil, '44', '3643532']
17
+ expect(splitter.split('443643532')).to eq [nil, '44', '3643532']
20
18
  end
21
19
  it 'splits correctly even when the number is too long' do
22
- @splitter.split('44364353211').should == [nil, '44', '364353211']
20
+ expect(splitter.split('44364353211')).to eq [nil, '44', '364353211']
23
21
  end
24
22
  it 'splits correctly even when the number is too short' do
25
- @splitter.split('443').should == [nil, '44','3']
23
+ expect(splitter.split('443')).to eq [nil, '44','3']
26
24
  end
27
25
  it 'has a length of 2' do
28
- @splitter.length.should == 2
26
+ expect(splitter.length).to eq 2
29
27
  end
30
28
  end
31
29
  describe 'split' do
32
- before(:each) do
33
- @splitter = Phony::NationalSplitters::Fixed.new nil
34
- end
30
+ let(:splitter) { Phony::NationalSplitters::Fixed.new(nil) }
35
31
  it 'splits correctly' do
36
- @splitter.split('443643532').should == [nil, '443643532']
32
+ expect(splitter.split('443643532')).to eq [nil, '443643532']
37
33
  end
38
34
  it 'splits correctly even when the number is too long' do
39
- @splitter.split('44364353211').should == [nil, '44364353211']
35
+ expect(splitter.split('44364353211')).to eq [nil, '44364353211']
40
36
  end
41
37
  it 'splits correctly even when the number is too short' do
42
- @splitter.split('443').should == [nil, '443']
38
+ expect(splitter.split('443')).to eq [nil, '443']
43
39
  end
44
40
  it 'has a length of nil' do
45
- @splitter.length.should == nil
41
+ expect(splitter.length).to eq nil
46
42
  end
47
43
  end
48
44
 
@@ -4,7 +4,7 @@ describe Phony::NationalSplitters::None do
4
4
 
5
5
  describe 'instance_for' do
6
6
  it 'caches' do
7
- described_class.instance_for.should equal(described_class.instance_for)
7
+ expect(described_class.instance_for).to eq described_class.instance_for
8
8
  end
9
9
  end
10
10
 
@@ -13,13 +13,13 @@ describe Phony::NationalSplitters::None do
13
13
 
14
14
  describe 'split' do
15
15
  it 'splits correctly into ndc and rest' do
16
- splitter.split('123456789').should == [nil, false, '123456789']
16
+ expect(splitter.split('123456789')).to eq [nil, false, '123456789']
17
17
  end
18
18
  end
19
19
 
20
20
  describe 'length' do
21
21
  it 'is always 0' do
22
- splitter.length.should be_zero
22
+ expect(splitter.length).to be_zero
23
23
  end
24
24
  end
25
25