valvat 0.6.4 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,75 +3,75 @@ require 'spec_helper'
3
3
  describe Valvat::Utils do
4
4
  describe "#split" do
5
5
  it "returns country and rest on vat number as array" do
6
- Valvat::Utils.split("DE345889003").should eql(["DE", "345889003"])
7
- Valvat::Utils.split("ESX4588900X").should eql(["ES", "X4588900X"])
6
+ expect(Valvat::Utils.split("DE345889003")).to eql(["DE", "345889003"])
7
+ expect(Valvat::Utils.split("ESX4588900X")).to eql(["ES", "X4588900X"])
8
8
  end
9
9
 
10
10
  it "returns two nils on non-european iso codes as array" do
11
- Valvat::Utils.split("US345889003").should eql([nil, nil])
12
- Valvat::Utils.split("RUX4588900X").should eql([nil, nil])
11
+ expect(Valvat::Utils.split("US345889003")).to eql([nil, nil])
12
+ expect(Valvat::Utils.split("RUX4588900X")).to eql([nil, nil])
13
13
  end
14
14
 
15
15
  it "returns two nils on non-sense input as array" do
16
- Valvat::Utils.split("DE").should eql([nil, nil])
17
- Valvat::Utils.split("X345889003").should eql([nil, nil])
18
- Valvat::Utils.split("").should eql([nil, nil])
19
- Valvat::Utils.split("1234").should eql([nil, nil])
20
- Valvat::Utils.split(" ").should eql([nil, nil])
16
+ expect(Valvat::Utils.split("DE")).to eql([nil, nil])
17
+ expect(Valvat::Utils.split("X345889003")).to eql([nil, nil])
18
+ expect(Valvat::Utils.split("")).to eql([nil, nil])
19
+ expect(Valvat::Utils.split("1234")).to eql([nil, nil])
20
+ expect(Valvat::Utils.split(" ")).to eql([nil, nil])
21
21
  end
22
22
 
23
23
  it "returns EL (language iso code) on greek vat" do
24
- Valvat::Utils.split("EL999999999").should eql(["EL", "999999999"])
24
+ expect(Valvat::Utils.split("EL999999999")).to eql(["EL", "999999999"])
25
25
  end
26
26
  end
27
27
 
28
28
  describe "#normalize" do
29
29
  it "returns vat number with upcase chars" do
30
- Valvat::Utils.normalize("de345889003").should eql("DE345889003")
31
- Valvat::Utils.normalize("EsX4588900y").should eql("ESX4588900Y")
30
+ expect(Valvat::Utils.normalize("de345889003")).to eql("DE345889003")
31
+ expect(Valvat::Utils.normalize("EsX4588900y")).to eql("ESX4588900Y")
32
32
  end
33
33
 
34
34
  it "returns trimmed vat number" do
35
- Valvat::Utils.normalize(" DE345889003").should eql("DE345889003")
36
- Valvat::Utils.normalize(" DE345889003 ").should eql("DE345889003")
37
- Valvat::Utils.normalize("DE345889003 ").should eql("DE345889003")
35
+ expect(Valvat::Utils.normalize(" DE345889003")).to eql("DE345889003")
36
+ expect(Valvat::Utils.normalize(" DE345889003 ")).to eql("DE345889003")
37
+ expect(Valvat::Utils.normalize("DE345889003 ")).to eql("DE345889003")
38
38
  end
39
39
 
40
40
  it "does not change already normalized vat numbers" do
41
- Valvat::Utils.normalize("DE345889003").should eql("DE345889003")
42
- Valvat::Utils.normalize("ESX4588900X").should eql("ESX4588900X")
41
+ expect(Valvat::Utils.normalize("DE345889003")).to eql("DE345889003")
42
+ expect(Valvat::Utils.normalize("ESX4588900X")).to eql("ESX4588900X")
43
43
  end
44
44
 
45
45
  it "removes spaces" do
46
- Valvat::Utils.normalize("DE 345889003").should eql("DE345889003")
47
- Valvat::Utils.normalize("ESX 458 8900 X").should eql("ESX4588900X")
46
+ expect(Valvat::Utils.normalize("DE 345889003")).to eql("DE345889003")
47
+ expect(Valvat::Utils.normalize("ESX 458 8900 X")).to eql("ESX4588900X")
48
48
  end
49
49
 
50
50
  it "removes special chars" do
51
- Valvat::Utils.normalize("DE.345-889_00:3,;").should eql("DE345889003")
51
+ expect(Valvat::Utils.normalize("DE.345-889_00:3,;")).to eql("DE345889003")
52
52
  end
53
53
  end
54
54
 
55
55
  describe "#vat_country_to_iso_country" do
56
56
  it "returns iso country code on greek iso language 'EL'" do
57
- Valvat::Utils.vat_country_to_iso_country("EL").should eql("GR")
57
+ expect(Valvat::Utils.vat_country_to_iso_country("EL")).to eql("GR")
58
58
  end
59
59
 
60
60
  Valvat::Utils::EU_COUNTRIES.each do |iso|
61
61
  it "returns unchanged iso country code '#{iso}'" do
62
- Valvat::Utils.vat_country_to_iso_country(iso).should eql(iso)
62
+ expect(Valvat::Utils.vat_country_to_iso_country(iso)).to eql(iso)
63
63
  end
64
64
  end
65
65
  end
66
66
 
67
67
  describe "#iso_country_to_vat_country" do
68
68
  it "returns vat country on greek iso country code 'GR'" do
69
- Valvat::Utils.iso_country_to_vat_country("GR").should eql("EL")
69
+ expect(Valvat::Utils.iso_country_to_vat_country("GR")).to eql("EL")
70
70
  end
71
71
 
72
72
  Valvat::Utils::EU_COUNTRIES.reject{|c| c == "GR"}.each do |c|
73
73
  it "returns unchanged vat country code '#{c}'" do
74
- Valvat::Utils.iso_country_to_vat_country(c).should eql(c)
74
+ expect(Valvat::Utils.iso_country_to_vat_country(c)).to eql(c)
75
75
  end
76
76
  end
77
77
  end
data/spec/valvat_spec.rb CHANGED
@@ -5,26 +5,26 @@ require 'spec_helper'
5
5
  describe Valvat do
6
6
  describe "#new" do
7
7
  it "demands one and only one argument" do
8
- lambda{ Valvat.new }.should raise_error(ArgumentError)
9
- lambda{ Valvat.new("a", "b") }.should raise_error(ArgumentError)
10
- lambda{ Valvat.new("a") }.should_not raise_error
8
+ expect{ Valvat.new }.to raise_error(ArgumentError)
9
+ expect{ Valvat.new("a", "b") }.to raise_error(ArgumentError)
10
+ expect{ Valvat.new("a") }.not_to raise_error
11
11
  end
12
12
 
13
13
  it "normalizes input string" do
14
- Valvat.new("de25.9597,69 7").to_s.should eql("DE259597697")
15
- Valvat.new("de25.9597,69 7").iso_country_code.should eql("DE")
14
+ expect(Valvat.new("de25.9597,69 7").to_s).to eql("DE259597697")
15
+ expect(Valvat.new("de25.9597,69 7").iso_country_code).to eql("DE")
16
16
  end
17
17
  end
18
18
 
19
19
  context "Valvat()" do
20
20
  it "initializes new Valvat instance on string" do
21
- Valvat("abc").should be_kind_of(Valvat)
21
+ expect(Valvat("abc")).to be_kind_of(Valvat)
22
22
  end
23
23
 
24
24
  it "returns same Valvat instance on Valvat instance" do
25
25
  vat = Valvat.new("abc")
26
- Valvat(vat).should be_kind_of(Valvat)
27
- Valvat(vat).object_id.should eql(vat.object_id)
26
+ expect(Valvat(vat)).to be_kind_of(Valvat)
27
+ expect(Valvat(vat).object_id).to eql(vat.object_id)
28
28
  end
29
29
  end
30
30
 
@@ -32,15 +32,15 @@ describe Valvat do
32
32
  describe "#blank?" do
33
33
 
34
34
  it "returns true when when initialized with nil" do
35
- Valvat.new(nil).should be_blank
35
+ expect(Valvat.new(nil)).to be_blank
36
36
  end
37
37
 
38
38
  it "returns true when when initialized with an empty string" do
39
- Valvat.new(" ").should be_blank
39
+ expect(Valvat.new(" ")).to be_blank
40
40
  end
41
41
 
42
42
  it "returns false when initialized with a value" do
43
- Valvat.new("DE259597697").should_not be_blank
43
+ expect(Valvat.new("DE259597697")).not_to be_blank
44
44
  end
45
45
  end
46
46
 
@@ -52,111 +52,111 @@ describe Valvat do
52
52
 
53
53
  describe "#valid?" do
54
54
  it "returns true on valid numbers" do
55
- de_vat.should be_valid
56
- gr_vat.should be_valid
55
+ expect(de_vat).to be_valid
56
+ expect(gr_vat).to be_valid
57
57
  end
58
58
 
59
59
  it "returns false on invalid numbers" do
60
- at_vat.should_not be_valid
60
+ expect(at_vat).not_to be_valid
61
61
  end
62
62
  end
63
63
 
64
64
  describe "#valid_checksum?" do
65
65
  it "returns true on valid numbers" do
66
- de_vat.should be_valid_checksum
67
- gr_vat.should be_valid_checksum
66
+ expect(de_vat).to be_valid_checksum
67
+ expect(gr_vat).to be_valid_checksum
68
68
  end
69
69
 
70
70
  it "returns false on invalid numbers" do
71
- at_vat.should_not be_valid_checksum
72
- invalid_checksum.should_not be_valid_checksum
71
+ expect(at_vat).not_to be_valid_checksum
72
+ expect(invalid_checksum).not_to be_valid_checksum
73
73
  end
74
74
  end
75
75
 
76
76
  describe "#exist(s)?" do
77
77
  context "on existing vat numbers" do
78
78
  before do
79
- Valvat::Lookup.stub(:validate => true)
79
+ allow(Valvat::Lookup).to receive_messages(:validate => true)
80
80
  end
81
81
 
82
82
  it "returns true" do
83
- de_vat.exists?.should eql(true)
84
- gr_vat.exists?.should eql(true)
85
- de_vat.exist?.should eql(true)
86
- gr_vat.exist?.should eql(true)
83
+ expect(de_vat.exists?).to eql(true)
84
+ expect(gr_vat.exists?).to eql(true)
85
+ expect(de_vat.exist?).to eql(true)
86
+ expect(gr_vat.exist?).to eql(true)
87
87
  end
88
88
  end
89
89
 
90
90
  context "on not existing vat numbers" do
91
91
  before do
92
- Valvat::Lookup.stub(:validate => false)
92
+ allow(Valvat::Lookup).to receive_messages(:validate => false)
93
93
  end
94
94
 
95
95
  it "returns false" do
96
- at_vat.exists?.should eql(false)
97
- at_vat.exist?.should eql(false)
96
+ expect(at_vat.exists?).to eql(false)
97
+ expect(at_vat.exist?).to eql(false)
98
98
  end
99
99
  end
100
100
 
101
101
  context "with options" do
102
102
  it "calls Valvat::Lookup.validate with options" do
103
- Valvat::Lookup.should_receive(:validate).once.with(de_vat, :detail => true, :bla => 'blupp').and_return(true)
104
- de_vat.exists?(:detail => true, :bla => 'blupp').should eql(true)
103
+ expect(Valvat::Lookup).to receive(:validate).once.with(de_vat, :detail => true, :bla => 'blupp').and_return(true)
104
+ expect(de_vat.exists?(:detail => true, :bla => 'blupp')).to eql(true)
105
105
  end
106
106
  end
107
107
  end
108
108
 
109
109
  describe "#iso_country_code" do
110
110
  it "returns iso country code on iso_country_code" do
111
- de_vat.iso_country_code.should eql("DE")
112
- at_vat.iso_country_code.should eql("AT")
111
+ expect(de_vat.iso_country_code).to eql("DE")
112
+ expect(at_vat.iso_country_code).to eql("AT")
113
113
  end
114
114
 
115
115
  it "returns GR iso country code on greek vat number" do
116
- gr_vat.iso_country_code.should eql("GR")
116
+ expect(gr_vat.iso_country_code).to eql("GR")
117
117
  end
118
118
  end
119
119
 
120
120
  describe "#vat_country_code" do
121
121
  it "returns iso country code on iso_country_code" do
122
- de_vat.vat_country_code.should eql("DE")
123
- at_vat.vat_country_code.should eql("AT")
122
+ expect(de_vat.vat_country_code).to eql("DE")
123
+ expect(at_vat.vat_country_code).to eql("AT")
124
124
  end
125
125
 
126
126
  it "returns EL iso language code on greek vat number" do
127
- gr_vat.vat_country_code.should eql("EL")
127
+ expect(gr_vat.vat_country_code).to eql("EL")
128
128
  end
129
129
  end
130
130
 
131
131
  describe "#european?" do
132
132
  it "returns true" do
133
- de_vat.should be_european
134
- at_vat.should be_european
135
- gr_vat.should be_european
133
+ expect(de_vat).to be_european
134
+ expect(at_vat).to be_european
135
+ expect(gr_vat).to be_european
136
136
  end
137
137
  end
138
138
 
139
139
  describe "#to_s" do
140
140
  it "returns full vat number" do
141
- de_vat.to_s.should eql("DE259597697")
142
- at_vat.to_s.should eql("ATU458890031")
143
- gr_vat.to_s.should eql("EL999943280")
141
+ expect(de_vat.to_s).to eql("DE259597697")
142
+ expect(at_vat.to_s).to eql("ATU458890031")
143
+ expect(gr_vat.to_s).to eql("EL999943280")
144
144
  end
145
145
  end
146
146
 
147
147
  describe "#inspect" do
148
148
  it "returns vat number with iso country code" do
149
- de_vat.inspect.should eql("#<Valvat DE259597697 DE>")
150
- at_vat.inspect.should eql("#<Valvat ATU458890031 AT>")
151
- gr_vat.inspect.should eql("#<Valvat EL999943280 GR>")
149
+ expect(de_vat.inspect).to eql("#<Valvat DE259597697 DE>")
150
+ expect(at_vat.inspect).to eql("#<Valvat ATU458890031 AT>")
151
+ expect(gr_vat.inspect).to eql("#<Valvat EL999943280 GR>")
152
152
  end
153
153
  end
154
154
 
155
155
  describe "#to_a" do
156
156
  it "calls Valvat::Utils.split with raw vat number and returns result" do
157
157
  de_vat # initialize
158
- Valvat::Utils.should_receive(:split).once.with("DE259597697").and_return(["a", "b"])
159
- de_vat.to_a.should eql(["a", "b"])
158
+ expect(Valvat::Utils).to receive(:split).once.with("DE259597697").and_return(["a", "b"])
159
+ expect(de_vat.to_a).to eql(["a", "b"])
160
160
  end
161
161
  end
162
162
  end
@@ -167,8 +167,8 @@ describe Valvat do
167
167
 
168
168
  describe "#valid?" do
169
169
  it "returns false" do
170
- us_vat.should_not be_valid
171
- ch_vat.should_not be_valid
170
+ expect(us_vat).not_to be_valid
171
+ expect(ch_vat).not_to be_valid
172
172
  end
173
173
  end
174
174
 
@@ -176,43 +176,43 @@ describe Valvat do
176
176
  without_any_web_requests!
177
177
 
178
178
  it "returns false" do
179
- us_vat.should_not be_exist
180
- ch_vat.should_not be_exist
179
+ expect(us_vat).not_to be_exist
180
+ expect(ch_vat).not_to be_exist
181
181
  end
182
182
  end
183
183
 
184
184
  describe "#iso_country_code" do
185
185
  it "returns nil" do
186
- us_vat.iso_country_code.should eql(nil)
187
- ch_vat.iso_country_code.should eql(nil)
186
+ expect(us_vat.iso_country_code).to eql(nil)
187
+ expect(ch_vat.iso_country_code).to eql(nil)
188
188
  end
189
189
  end
190
190
 
191
191
  describe "#vat_country_code" do
192
192
  it "returns nil" do
193
- us_vat.vat_country_code.should eql(nil)
194
- ch_vat.vat_country_code.should eql(nil)
193
+ expect(us_vat.vat_country_code).to eql(nil)
194
+ expect(ch_vat.vat_country_code).to eql(nil)
195
195
  end
196
196
  end
197
197
 
198
198
  describe "#european?" do
199
199
  it "returns false" do
200
- us_vat.should_not be_european
201
- ch_vat.should_not be_european
200
+ expect(us_vat).not_to be_european
201
+ expect(ch_vat).not_to be_european
202
202
  end
203
203
  end
204
204
 
205
205
  describe "#to_s" do
206
206
  it "returns full given vat number" do
207
- us_vat.to_s.should eql("US345889003")
208
- ch_vat.to_s.should eql("CH445889003")
207
+ expect(us_vat.to_s).to eql("US345889003")
208
+ expect(ch_vat.to_s).to eql("CH445889003")
209
209
  end
210
210
  end
211
211
 
212
212
  describe "#inspect" do
213
213
  it "returns vat number without iso country code" do
214
- us_vat.inspect.should eql("#<Valvat US345889003>")
215
- ch_vat.inspect.should eql("#<Valvat CH445889003>")
214
+ expect(us_vat.inspect).to eql("#<Valvat US345889003>")
215
+ expect(ch_vat.inspect).to eql("#<Valvat CH445889003>")
216
216
  end
217
217
  end
218
218
 
@@ -226,10 +226,10 @@ describe Valvat do
226
226
 
227
227
  describe "#valid?" do
228
228
  it "returns false" do
229
- only_iso_vat.should_not be_valid
230
- num_vat.should_not be_valid
231
- empty_vat.should_not be_valid
232
- nil_vat.should_not be_valid
229
+ expect(only_iso_vat).not_to be_valid
230
+ expect(num_vat).not_to be_valid
231
+ expect(empty_vat).not_to be_valid
232
+ expect(nil_vat).not_to be_valid
233
233
  end
234
234
  end
235
235
 
@@ -237,55 +237,55 @@ describe Valvat do
237
237
  without_any_web_requests!
238
238
 
239
239
  it "returns false" do
240
- only_iso_vat.should_not be_exist
241
- num_vat.should_not be_exist
242
- empty_vat.should_not be_exist
243
- nil_vat.should_not be_exist
240
+ expect(only_iso_vat).not_to be_exist
241
+ expect(num_vat).not_to be_exist
242
+ expect(empty_vat).not_to be_exist
243
+ expect(nil_vat).not_to be_exist
244
244
  end
245
245
  end
246
246
 
247
247
  describe "#iso_country_code" do
248
248
  it "returns nil" do
249
- only_iso_vat.iso_country_code.should eql(nil)
250
- num_vat.iso_country_code.should eql(nil)
251
- empty_vat.iso_country_code.should eql(nil)
252
- nil_vat.iso_country_code.should eql(nil)
249
+ expect(only_iso_vat.iso_country_code).to eql(nil)
250
+ expect(num_vat.iso_country_code).to eql(nil)
251
+ expect(empty_vat.iso_country_code).to eql(nil)
252
+ expect(nil_vat.iso_country_code).to eql(nil)
253
253
  end
254
254
  end
255
255
 
256
256
  describe "#vat_country_code" do
257
257
  it "returns nil" do
258
- only_iso_vat.vat_country_code.should eql(nil)
259
- num_vat.vat_country_code.should eql(nil)
260
- empty_vat.vat_country_code.should eql(nil)
261
- nil_vat.vat_country_code.should eql(nil)
258
+ expect(only_iso_vat.vat_country_code).to eql(nil)
259
+ expect(num_vat.vat_country_code).to eql(nil)
260
+ expect(empty_vat.vat_country_code).to eql(nil)
261
+ expect(nil_vat.vat_country_code).to eql(nil)
262
262
  end
263
263
  end
264
264
 
265
265
  describe "#european?" do
266
266
  it "returns false" do
267
- only_iso_vat.should_not be_european
268
- num_vat.should_not be_european
269
- empty_vat.should_not be_european
270
- nil_vat.should_not be_european
267
+ expect(only_iso_vat).not_to be_european
268
+ expect(num_vat).not_to be_european
269
+ expect(empty_vat).not_to be_european
270
+ expect(nil_vat).not_to be_european
271
271
  end
272
272
  end
273
273
 
274
274
  describe "#to_s" do
275
275
  it "returns full given vat number" do
276
- only_iso_vat.to_s.should eql("DE")
277
- num_vat.to_s.should eql("12445889003")
278
- empty_vat.to_s.should eql("")
279
- nil_vat.to_s.should eql("")
276
+ expect(only_iso_vat.to_s).to eql("DE")
277
+ expect(num_vat.to_s).to eql("12445889003")
278
+ expect(empty_vat.to_s).to eql("")
279
+ expect(nil_vat.to_s).to eql("")
280
280
  end
281
281
  end
282
282
 
283
283
  describe "#inspect" do
284
284
  it "returns vat number without iso country code" do
285
- only_iso_vat.inspect.should eql("#<Valvat DE>")
286
- num_vat.inspect.should eql("#<Valvat 12445889003>")
287
- empty_vat.inspect.should eql("#<Valvat >")
288
- nil_vat.inspect.should eql("#<Valvat >")
285
+ expect(only_iso_vat.inspect).to eql("#<Valvat DE>")
286
+ expect(num_vat.inspect).to eql("#<Valvat 12445889003>")
287
+ expect(empty_vat.inspect).to eql("#<Valvat >")
288
+ expect(nil_vat.inspect).to eql("#<Valvat >")
289
289
  end
290
290
  end
291
291