brcobranca 2.0.5 → 2.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +24 -0
- data/PostInstall.txt +4 -0
- data/README.rdoc +4 -4
- data/Rakefile +9 -6
- data/brcobranca.gemspec +9 -9
- data/lib/brcobranca/arquivos/logos/banespa.jpg +0 -0
- data/lib/brcobranca/boleto/banco_banespa.rb +85 -0
- data/lib/brcobranca/boleto/banco_bradesco.rb +14 -1
- data/lib/brcobranca/boleto/banco_brasil.rb +18 -9
- data/lib/brcobranca/boleto/banco_hsbc.rb +22 -8
- data/lib/brcobranca/boleto/banco_itau.rb +20 -10
- data/lib/brcobranca/boleto/banco_real.rb +16 -2
- data/lib/brcobranca/boleto/banco_unibanco.rb +19 -5
- data/lib/brcobranca/boleto/base.rb +21 -15
- data/lib/brcobranca/boleto/template/rghost.rb +18 -16
- data/lib/brcobranca/boleto/template/util.rb +2 -0
- data/lib/brcobranca/core_ext.rb +57 -47
- data/lib/brcobranca/currency.rb +7 -10
- data/lib/brcobranca.rb +10 -2
- data/spec/arquivos/CBR64310.RET +28 -0
- data/spec/brcobranca/banco_banespa_spec.rb +195 -0
- data/spec/brcobranca/banco_bradesco_spec.rb +179 -0
- data/spec/brcobranca/banco_brasil_spec.rb +353 -0
- data/spec/brcobranca/banco_hsbc_spec.rb +216 -0
- data/spec/brcobranca/banco_itau_spec.rb +202 -0
- data/spec/brcobranca/banco_real_spec.rb +145 -0
- data/spec/brcobranca/banco_unibanco_spec.rb +193 -0
- data/spec/brcobranca/base_spec.rb +240 -0
- data/spec/brcobranca/core_ext_spec.rb +275 -0
- data/spec/brcobranca/currency_spec.rb +81 -0
- data/spec/brcobranca/retorno_cbr643_spec.rb +69 -0
- data/spec/brcobranca/rghost_spec.rb +36 -0
- data/spec/brcobranca/template/rghost_spec.rb +65 -0
- data/spec/brcobranca/template/util_spec.rb +42 -0
- data/spec/brcobranca_spec.rb +8 -0
- data/spec/rcov.opts +2 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +10 -0
- data/tasks/rcov.rake +12 -0
- data/tasks/rspec.rake +21 -0
- metadata +32 -18
- data/test/test_banco_bradesco.rb +0 -87
- data/test/test_banco_brasil.rb +0 -276
- data/test/test_banco_hsbc.rb +0 -81
- data/test/test_banco_itau.rb +0 -103
- data/test/test_banco_real.rb +0 -112
- data/test/test_banco_unibanco.rb +0 -92
- data/test/test_base.rb +0 -162
- data/test/test_core_ext.rb +0 -227
- data/test/test_currency.rb +0 -51
- data/test/test_helper.rb +0 -5
- data/test/test_retorno_cbr643.rb +0 -66
- data/test/test_rghost.rb +0 -49
@@ -0,0 +1,275 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
+
|
3
|
+
module Brcobranca
|
4
|
+
describe Formatacao do
|
5
|
+
it "should format CPF" do
|
6
|
+
98789298790.to_br_cpf.should eql("987.892.987-90")
|
7
|
+
"98789298790".to_br_cpf.should eql("987.892.987-90")
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should format CEP" do
|
11
|
+
85253100.to_br_cep.should eql("85253-100")
|
12
|
+
"85253100".to_br_cep.should eql("85253-100")
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should format CNPJ" do
|
16
|
+
88394510000103.to_br_cnpj.should eql("88.394.510/0001-03")
|
17
|
+
"88394510000103".to_br_cnpj.should eql("88.394.510/0001-03")
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should format documents based in your lenght" do
|
21
|
+
98789298790.formata_documento.should eql("987.892.987-90")
|
22
|
+
"98789298790".formata_documento.should eql("987.892.987-90")
|
23
|
+
85253100.formata_documento.should eql("85253-100")
|
24
|
+
"85253100".formata_documento.should eql("85253-100")
|
25
|
+
88394510000103.formata_documento.should eql("88.394.510/0001-03")
|
26
|
+
"88394510000103".formata_documento.should eql("88.394.510/0001-03")
|
27
|
+
"8839".formata_documento.should eql("8839")
|
28
|
+
"8839451000010388394510000103".formata_documento.should eql("8839451000010388394510000103")
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should fill with zeros at left until lenght seted" do
|
32
|
+
"123".zeros_esquerda.should eql("123")
|
33
|
+
"123".zeros_esquerda(:tamanho => 0).should eql("123")
|
34
|
+
"123".zeros_esquerda(:tamanho => 1).should eql("123")
|
35
|
+
"123".zeros_esquerda(:tamanho => 2).should eql("123")
|
36
|
+
"123".zeros_esquerda(:tamanho => 3).should eql("123")
|
37
|
+
"123".zeros_esquerda(:tamanho => 4).should eql("0123")
|
38
|
+
"123".zeros_esquerda(:tamanho => 5).should eql("00123")
|
39
|
+
"123".zeros_esquerda(:tamanho => 10).should eql("0000000123")
|
40
|
+
"123".zeros_esquerda(:tamanho => 5).should be_a_kind_of(String)
|
41
|
+
|
42
|
+
123.zeros_esquerda.should eql("123")
|
43
|
+
123.zeros_esquerda(:tamanho => 0).should eql("123")
|
44
|
+
123.zeros_esquerda(:tamanho => 1).should eql("123")
|
45
|
+
123.zeros_esquerda(:tamanho => 2).should eql("123")
|
46
|
+
123.zeros_esquerda(:tamanho => 3).should eql("123")
|
47
|
+
123.zeros_esquerda(:tamanho => 4).should eql("0123")
|
48
|
+
123.zeros_esquerda(:tamanho => 5).should eql("00123")
|
49
|
+
123.zeros_esquerda(:tamanho => 10).should eql("0000000123")
|
50
|
+
123.zeros_esquerda(:tamanho => 5).should be_a_kind_of(String)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should mount linha digitavel" do
|
54
|
+
"00192376900000135000000001238798777770016818".linha_digitavel.should eql("00190.00009 01238.798779 77700.168188 2 37690000013500")
|
55
|
+
"00192376900000135000000001238798777770016818".linha_digitavel.should be_a_kind_of(String)
|
56
|
+
lambda { "".linha_digitavel }.should raise_error(ArgumentError)
|
57
|
+
lambda { "00193373700".linha_digitavel }.should raise_error(ArgumentError)
|
58
|
+
lambda { "0019337370000193373700".linha_digitavel }.should raise_error(ArgumentError)
|
59
|
+
lambda { "00b193373700bb00193373700".linha_digitavel }.should raise_error(ArgumentError)
|
60
|
+
lambda { "0019337370000193373700bbb".linha_digitavel }.should raise_error(ArgumentError)
|
61
|
+
lambda { "0019237690000c135000c0000123f7987e7773016813".linha_digitavel }.should raise_error(ArgumentError)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe Calculo do
|
66
|
+
it "should calculate mod10" do
|
67
|
+
lambda { "".modulo10 }.should raise_error(ArgumentError)
|
68
|
+
lambda { " ".modulo10 }.should raise_error(ArgumentError)
|
69
|
+
"001905009".modulo10.should eql(5)
|
70
|
+
"4014481606".modulo10.should eql(9)
|
71
|
+
"0680935031".modulo10.should eql(4)
|
72
|
+
"29004590".modulo10.should eql(5)
|
73
|
+
"341911012".modulo10.should eql(1)
|
74
|
+
"3456788005".modulo10.should eql(8)
|
75
|
+
"7123457000".modulo10.should eql(1)
|
76
|
+
"00571234511012345678".modulo10.should eql(8)
|
77
|
+
"001905009".modulo10.should be_a_kind_of(Fixnum)
|
78
|
+
0.modulo10.should eql(0)
|
79
|
+
1905009.modulo10.should eql(5)
|
80
|
+
4014481606.modulo10.should eql(9)
|
81
|
+
680935031.modulo10.should eql(4)
|
82
|
+
29004590.modulo10.should eql(5)
|
83
|
+
1905009.modulo10.should be_a_kind_of(Fixnum)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should calculate mo10_banespa" do
|
87
|
+
"4007469108".modulo_10_banespa.should eql(1)
|
88
|
+
4007469108.modulo_10_banespa.should eql(1)
|
89
|
+
"1237469108".modulo_10_banespa.should eql(3)
|
90
|
+
1237469108.modulo_10_banespa.should eql(3)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should test multiplicador" do
|
94
|
+
"85068014982".multiplicador([2,3,4,5,6,7,8,9]).should eql(255)
|
95
|
+
"05009401448".multiplicador([2,3,4,5,6,7,8,9]).should eql(164)
|
96
|
+
"12387987777700168".multiplicador([2,3,4,5,6,7,8,9]).should eql(460)
|
97
|
+
"34230".multiplicador([2,3,4,5,6,7,8,9]).should eql(55)
|
98
|
+
"258281".multiplicador([2,3,4,5,6,7,8,9]).should eql(118)
|
99
|
+
"5444".multiplicador([2,3,4,5,6,7,8,9]).should be_a_kind_of(Fixnum)
|
100
|
+
"000000005444".multiplicador([2,3,4,5,6,7,8,9]).should be_a_kind_of(Fixnum)
|
101
|
+
85068014982.multiplicador([2,3,4,5,6,7,8,9]).should eql(255)
|
102
|
+
5009401448.multiplicador([2,3,4,5,6,7,8,9]).should eql(164)
|
103
|
+
5444.multiplicador([2,3,4,5,6,7,8,9]).should eql(61)
|
104
|
+
1129004590.multiplicador([2,3,4,5,6,7,8,9]).should eql(162)
|
105
|
+
5444.multiplicador([2,3,4,5,6,7,8,9]).should be_a_kind_of(Fixnum)
|
106
|
+
lambda { "2582fd81".multiplicador([2,3,4,5,6,7,8,9]) }.should raise_error(ArgumentError)
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should calculate mo11 - 9to2" do
|
110
|
+
"85068014982".modulo11_9to2.should eql(9)
|
111
|
+
"05009401448".modulo11_9to2.should eql(1)
|
112
|
+
"12387987777700168".modulo11_9to2.should eql(2)
|
113
|
+
"4042".modulo11_9to2.should eql(8)
|
114
|
+
"61900".modulo11_9to2.should eql(0)
|
115
|
+
"0719".modulo11_9to2.should eql(6)
|
116
|
+
"000000005444".modulo11_9to2.should eql(5)
|
117
|
+
"5444".modulo11_9to2.should eql(5)
|
118
|
+
"01129004590".modulo11_9to2.should eql(3)
|
119
|
+
"15735".modulo11_9to2.should eql(10)
|
120
|
+
"777700168".modulo11_9to2.should eql(0)
|
121
|
+
"77700168".modulo11_9to2.should eql(3)
|
122
|
+
"00015448".modulo11_9to2.should eql(2)
|
123
|
+
"15448".modulo11_9to2.should eql(2)
|
124
|
+
"12345678".modulo11_9to2.should eql(9)
|
125
|
+
"34230".modulo11_9to2.should eql(0)
|
126
|
+
"258281".modulo11_9to2.should eql(3)
|
127
|
+
"5444".modulo11_9to2.should be_a_kind_of(Fixnum)
|
128
|
+
"000000005444".modulo11_9to2.should be_a_kind_of(Fixnum)
|
129
|
+
85068014982.modulo11_9to2.should eql(9)
|
130
|
+
5009401448.modulo11_9to2.should eql(1)
|
131
|
+
12387987777700168.modulo11_9to2.should eql(2)
|
132
|
+
4042.modulo11_9to2.should eql(8)
|
133
|
+
61900.modulo11_9to2.should eql(0)
|
134
|
+
719.modulo11_9to2.should eql(6)
|
135
|
+
5444.modulo11_9to2.should eql(5)
|
136
|
+
1129004590.modulo11_9to2.should eql(3)
|
137
|
+
5444.modulo11_9to2.should be_a_kind_of(Fixnum)
|
138
|
+
lambda { "2582fd81".modulo11_9to2 }.should raise_error(ArgumentError)
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should calculate mod11 - 9to2, X instead of 10" do
|
142
|
+
"85068014982".modulo11_9to2_10_como_x.should eql(9)
|
143
|
+
"05009401448".modulo11_9to2_10_como_x.should eql(1)
|
144
|
+
"12387987777700168".modulo11_9to2_10_como_x.should eql(2)
|
145
|
+
"4042".modulo11_9to2_10_como_x.should eql(8)
|
146
|
+
"61900".modulo11_9to2_10_como_x.should eql(0)
|
147
|
+
"0719".modulo11_9to2_10_como_x.should eql(6)
|
148
|
+
"000000005444".modulo11_9to2_10_como_x.should eql(5)
|
149
|
+
"5444".modulo11_9to2_10_como_x.should eql(5)
|
150
|
+
"01129004590".modulo11_9to2_10_como_x.should eql(3)
|
151
|
+
"15735".modulo11_9to2_10_como_x.should eql("X")
|
152
|
+
"15735".modulo11_9to2_10_como_x.should be_a_kind_of(String)
|
153
|
+
"5444".modulo11_9to2_10_como_x.should be_a_kind_of(Fixnum)
|
154
|
+
"000000005444".modulo11_9to2_10_como_x.should be_a_kind_of(Fixnum)
|
155
|
+
lambda { "2582fd81".modulo11_9to2_10_como_x }.should raise_error(ArgumentError)
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should calculate mod11 - 2to9" do
|
159
|
+
"0019373700000001000500940144816060680935031".modulo11_2to9.should eql(3)
|
160
|
+
"0019373700000001000500940144816060680935031".modulo11_2to9.should be_a_kind_of(Fixnum)
|
161
|
+
"3419166700000123451101234567880057123457000".modulo11_2to9.should eql(6)
|
162
|
+
19373700000001000500940144816060680935031.modulo11_2to9.should eql(3)
|
163
|
+
19373700000001000500940144816060680935031.modulo11_2to9.should be_a_kind_of(Fixnum)
|
164
|
+
lambda { "2582fd81".modulo11_2to9 }.should raise_error(ArgumentError)
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should calculate digit's sum side by side" do
|
168
|
+
111.soma_digitos.should eql(3)
|
169
|
+
8.soma_digitos.should eql(8)
|
170
|
+
"111".soma_digitos.should eql(3)
|
171
|
+
"8".soma_digitos.should eql(8)
|
172
|
+
111.soma_digitos.should be_a_kind_of(Fixnum)
|
173
|
+
"111".soma_digitos.should be_a_kind_of(Fixnum)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
describe Validacao do
|
178
|
+
it "should return true when value is a currency" do
|
179
|
+
1234.03.to_s.moeda?.should be_true
|
180
|
+
+1234.03.to_s.moeda?.should be_true
|
181
|
+
-1234.03.to_s.moeda?.should be_true
|
182
|
+
1234.03.moeda?.should be_true
|
183
|
+
+1234.03.moeda?.should be_true
|
184
|
+
-1234.03.moeda?.should be_true
|
185
|
+
"1234.03".moeda?.should be_true
|
186
|
+
"1234,03".moeda?.should be_true
|
187
|
+
"1,234.03".moeda?.should be_true
|
188
|
+
"1.234.03".moeda?.should be_true
|
189
|
+
"1,234,03".moeda?.should be_true
|
190
|
+
"12.340,03".moeda?.should be_true
|
191
|
+
"+1234.03".moeda?.should be_true
|
192
|
+
"+1234,03".moeda?.should be_true
|
193
|
+
"+1,234.03".moeda?.should be_true
|
194
|
+
"+1.234.03".moeda?.should be_true
|
195
|
+
"+1,234,03".moeda?.should be_true
|
196
|
+
"+12.340,03".moeda?.should be_true
|
197
|
+
"-1234.03".moeda?.should be_true
|
198
|
+
"-1234,03".moeda?.should be_true
|
199
|
+
"-1,234.03".moeda?.should be_true
|
200
|
+
"-1.234.03".moeda?.should be_true
|
201
|
+
"-1,234,03".moeda?.should be_true
|
202
|
+
"-12.340,03".moeda?.should be_true
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should return false when value is NOT a currency" do
|
206
|
+
123403.to_s.moeda?.should be_false
|
207
|
+
-123403.to_s.moeda?.should be_false
|
208
|
+
+123403.to_s.moeda?.should be_false
|
209
|
+
123403.moeda?.should be_false
|
210
|
+
-123403.moeda?.should be_false
|
211
|
+
+123403.moeda?.should be_false
|
212
|
+
"1234ab".moeda?.should be_false
|
213
|
+
"ab1213".moeda?.should be_false
|
214
|
+
"ffab".moeda?.should be_false
|
215
|
+
"1234".moeda?.should be_false
|
216
|
+
"23[;)]ddf".moeda?.should be_false
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
describe Limpeza do
|
221
|
+
it "should return just numbers when value is a currency" do
|
222
|
+
1234.03.limpa_valor_moeda.should == "123403"
|
223
|
+
+1234.03.limpa_valor_moeda.limpa_valor_moeda.should == "123403"
|
224
|
+
-1234.03.limpa_valor_moeda.limpa_valor_moeda.should == "123403"
|
225
|
+
"1234.03".limpa_valor_moeda.limpa_valor_moeda.should == "123403"
|
226
|
+
"1234,03".limpa_valor_moeda.limpa_valor_moeda.should == "123403"
|
227
|
+
"1,234.03".limpa_valor_moeda.limpa_valor_moeda.should == "123403"
|
228
|
+
"1.234.03".limpa_valor_moeda.limpa_valor_moeda.should == "123403"
|
229
|
+
"1,234,03".limpa_valor_moeda.limpa_valor_moeda.should == "123403"
|
230
|
+
"12.340,03".limpa_valor_moeda.limpa_valor_moeda.should == "1234003"
|
231
|
+
"+1234.03".limpa_valor_moeda.limpa_valor_moeda.should == "123403"
|
232
|
+
"+1234,03".limpa_valor_moeda.limpa_valor_moeda.should == "123403"
|
233
|
+
"+1,234.03".limpa_valor_moeda.limpa_valor_moeda.should == "123403"
|
234
|
+
"+1.234.03".limpa_valor_moeda.limpa_valor_moeda.should == "123403"
|
235
|
+
"+1,234,03".limpa_valor_moeda.limpa_valor_moeda.should == "123403"
|
236
|
+
"+12.340,03".limpa_valor_moeda.limpa_valor_moeda.should == "1234003"
|
237
|
+
"-1234.03".limpa_valor_moeda.limpa_valor_moeda.should == "123403"
|
238
|
+
"-1234,03".limpa_valor_moeda.limpa_valor_moeda.should == "123403"
|
239
|
+
"-1,234.03".limpa_valor_moeda.limpa_valor_moeda.should == "123403"
|
240
|
+
"-1.234.03".limpa_valor_moeda.limpa_valor_moeda.should == "123403"
|
241
|
+
"-1,234,03".limpa_valor_moeda.limpa_valor_moeda.should == "123403"
|
242
|
+
"-12.340,03".limpa_valor_moeda.limpa_valor_moeda.should == "1234003"
|
243
|
+
end
|
244
|
+
|
245
|
+
it "should NOT modify value when it is NOT a currency" do
|
246
|
+
"1234ab".limpa_valor_moeda.limpa_valor_moeda.should == "1234ab"
|
247
|
+
"ab1213".limpa_valor_moeda.limpa_valor_moeda.should == "ab1213"
|
248
|
+
"ffab".limpa_valor_moeda.limpa_valor_moeda.should == "ffab"
|
249
|
+
"1234".limpa_valor_moeda.limpa_valor_moeda.should == "1234"
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
describe CalculoData do
|
254
|
+
it "should return number of days between Date and 1997-10-07" do
|
255
|
+
(Date.parse "2008-02-01").fator_vencimento.should == 3769
|
256
|
+
(Date.parse "2008-02-02").fator_vencimento.should == 3770
|
257
|
+
(Date.parse "2008-02-06").fator_vencimento.should == 3774
|
258
|
+
end
|
259
|
+
|
260
|
+
it "should format Date to Brazillian format" do
|
261
|
+
(Date.parse "2008-02-01").to_s_br.should == "01/02/2008"
|
262
|
+
(Date.parse "2008-02-02").to_s_br.should == "02/02/2008"
|
263
|
+
(Date.parse "2008-02-06").to_s_br.should == "06/02/2008"
|
264
|
+
end
|
265
|
+
|
266
|
+
it "should calculate julian date from a Date" do
|
267
|
+
(Date.parse "2009-02-11").to_juliano.should eql("0429")
|
268
|
+
(Date.parse "2008-02-11").to_juliano.should eql("0428")
|
269
|
+
(Date.parse "2009-04-08").to_juliano.should eql("0989")
|
270
|
+
# Ano 2008 eh bisexto
|
271
|
+
(Date.parse "2008-04-08").to_juliano.should eql("0998")
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
+
|
3
|
+
module Brcobranca #:nodoc:[all]
|
4
|
+
module Currency #:nodoc:[all]
|
5
|
+
describe String do
|
6
|
+
it "should return true if value seted is a valid ruby number" do
|
7
|
+
"1234".numeric?.should be_true
|
8
|
+
"123.4".numeric?.should be_true
|
9
|
+
"123,4".numeric?.should be_true
|
10
|
+
"1234.03".numeric?.should be_true
|
11
|
+
"1234,03".numeric?.should be_true
|
12
|
+
"-1234".numeric?.should be_true
|
13
|
+
"-123.4".numeric?.should be_true
|
14
|
+
"-123,4".numeric?.should be_true
|
15
|
+
"-1234.03".numeric?.should be_true
|
16
|
+
"-1234,03".numeric?.should be_true
|
17
|
+
"+1234".numeric?.should be_true
|
18
|
+
"+123.4".numeric?.should be_true
|
19
|
+
"+123,4".numeric?.should be_true
|
20
|
+
"+1234.03".numeric?.should be_true
|
21
|
+
"+1234,03".numeric?.should be_true
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should return false if value seted is NOT a valid ruby number" do
|
25
|
+
"1234,".numeric?.should be_false
|
26
|
+
"1234.".numeric?.should be_false
|
27
|
+
"1,234.03".numeric?.should be_false
|
28
|
+
"1.234.03".numeric?.should be_false
|
29
|
+
"1,234,03".numeric?.should be_false
|
30
|
+
"12.340,03".numeric?.should be_false
|
31
|
+
"1234ab".numeric?.should be_false
|
32
|
+
"ab1213".numeric?.should be_false
|
33
|
+
"ffab".numeric?.should be_false
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should convert value seted to valid ruby number" do
|
37
|
+
"1234".to_number.should eql(1234.0)
|
38
|
+
"123.4".to_number.should eql(123.4)
|
39
|
+
"123,4".to_number.should eql(123.4)
|
40
|
+
"1234.03".to_number.should eql(1234.03)
|
41
|
+
"1234,03".to_number.should eql(1234.03)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should return nil when is not possible convert value seted" do
|
45
|
+
"1234,".to_number.should be_nil
|
46
|
+
"1234.".to_number.should be_nil
|
47
|
+
"1,234.03".to_number.should be_nil
|
48
|
+
"1.234.03".to_number.should be_nil
|
49
|
+
"1,234,03".to_number.should be_nil
|
50
|
+
"12.340,03".to_number.should be_nil
|
51
|
+
"1234ab".to_number.should be_nil
|
52
|
+
"ab1213".to_number.should be_nil
|
53
|
+
"ffab".to_number.should be_nil
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe Number do
|
58
|
+
it "should convert value seted to currency value" do
|
59
|
+
1234.to_currency.should eql("1.234,00")
|
60
|
+
123.4.to_currency.should eql("123,40")
|
61
|
+
1234.03.to_currency.should eql("1.234,03")
|
62
|
+
1234.03.to_currency(options = {:unit => "R$ "}).should eql("R$ 1.234,03")
|
63
|
+
1234.03.to_currency(options = {:unit => "R$ ",:separator => "."}).should eql("R$ 1.234.03")
|
64
|
+
1234.03.to_currency(options = {:unit => "R$ ",:separator => ".",:delimiter => ','}).should eql("R$ 1,234.03")
|
65
|
+
1234.03.to_currency(options = {:unit => "R$ ", :precision => 3}).should eql("R$ 1.234,030")
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should convert value seted using delimiter and separator" do
|
69
|
+
1234.with_delimiter.should eql("1,234")
|
70
|
+
123.4.with_delimiter.should eql("123.4")
|
71
|
+
1234.03.with_delimiter.should eql("1,234.03")
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should convert value seted using precision " do
|
75
|
+
1234.with_precision.should eql("1234.000")
|
76
|
+
123.4.with_precision.should eql("123.400")
|
77
|
+
1234.03.with_precision.should eql("1234.030")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe RetornoCbr643 do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@arquivo = File.join(File.dirname(__FILE__),'..','arquivos','CBR64310.RET')
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should read correctly values from file" do
|
10
|
+
pagamentos = RetornoCbr643.load_lines(@arquivo)
|
11
|
+
pagamentos.first.sequencial.should eql("000001")
|
12
|
+
pagamentos.first.agencia_com_dv.should eql("CA")
|
13
|
+
pagamentos.first.cedente_com_dv.should eql("33251")
|
14
|
+
pagamentos.first.convenio.should eql("0002893")
|
15
|
+
pagamentos.first.data_liquidacao.should eql("")
|
16
|
+
pagamentos.first.data_credito.should eql("")
|
17
|
+
pagamentos.first.valor_recebido.should eql("")
|
18
|
+
pagamentos.first.nosso_numero.should eql("OSSENSE DO AL001B")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should read correctly values from file with option :except in number" do
|
22
|
+
pagamentos = RetornoCbr643.load_lines(@arquivo,{:except => [1]})
|
23
|
+
pagamentos.first.sequencial.should eql("000002")
|
24
|
+
pagamentos.first.agencia_com_dv.should eql("33251")
|
25
|
+
pagamentos.first.cedente_com_dv.should eql("000289353")
|
26
|
+
pagamentos.first.convenio.should eql("1622420")
|
27
|
+
pagamentos.first.data_liquidacao.should eql("200109")
|
28
|
+
pagamentos.first.data_credito.should eql("220109")
|
29
|
+
pagamentos.first.valor_recebido.should eql("0000000009064")
|
30
|
+
pagamentos.first.nosso_numero.should eql("16224200000000003")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should read correctly values from file with option :except in number and :length" do
|
34
|
+
pagamentos = RetornoCbr643.load_lines(@arquivo,{:except => [1], :length => 400})
|
35
|
+
pagamentos.first.sequencial.should eql("000002")
|
36
|
+
pagamentos.first.agencia_com_dv.should eql("33251")
|
37
|
+
pagamentos.first.cedente_com_dv.should eql("000289353")
|
38
|
+
pagamentos.first.convenio.should eql("1622420")
|
39
|
+
pagamentos.first.data_liquidacao.should eql("200109")
|
40
|
+
pagamentos.first.data_credito.should eql("220109")
|
41
|
+
pagamentos.first.valor_recebido.should eql("0000000009064")
|
42
|
+
pagamentos.first.nosso_numero.should eql("16224200000000003")
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should read correctly values from file with option :except in regex" do
|
46
|
+
pagamentos = RetornoCbr643.load_lines(@arquivo,{:except => /^[^7]/})
|
47
|
+
pagamentos.first.sequencial.should eql("000002")
|
48
|
+
pagamentos.first.agencia_com_dv.should eql("33251")
|
49
|
+
pagamentos.first.cedente_com_dv.should eql("000289353")
|
50
|
+
pagamentos.first.convenio.should eql("1622420")
|
51
|
+
pagamentos.first.data_liquidacao.should eql("200109")
|
52
|
+
pagamentos.first.data_credito.should eql("220109")
|
53
|
+
pagamentos.first.valor_recebido.should eql("0000000009064")
|
54
|
+
pagamentos.first.nosso_numero.should eql("16224200000000003")
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should read correctly values from file with option :except in regex and :length" do
|
58
|
+
pagamentos = RetornoCbr643.load_lines(@arquivo,{:except => /^[^7]/, :length => 400})
|
59
|
+
pagamentos.first.sequencial.should eql("000002")
|
60
|
+
pagamentos.first.agencia_com_dv.should eql("33251")
|
61
|
+
pagamentos.first.cedente_com_dv.should eql("000289353")
|
62
|
+
pagamentos.first.convenio.should eql("1622420")
|
63
|
+
pagamentos.first.data_liquidacao.should eql("200109")
|
64
|
+
pagamentos.first.data_credito.should eql("220109")
|
65
|
+
pagamentos.first.valor_recebido.should eql("0000000009064")
|
66
|
+
pagamentos.first.nosso_numero.should eql("16224200000000003")
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
describe "RGhost test" do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@valid_attributes = {
|
8
|
+
:especie_documento => "DM",
|
9
|
+
:moeda => "9",
|
10
|
+
:banco => "001",
|
11
|
+
:data_documento => Date.today,
|
12
|
+
:dias_vencimento => 1,
|
13
|
+
:aceite => "S",
|
14
|
+
:quantidade => 1,
|
15
|
+
:valor => 0.0,
|
16
|
+
:local_pagamento => "QUALQUER BANCO ATÉ O VENCIMENTO",
|
17
|
+
:cedente => "Kivanio Barbosa",
|
18
|
+
:documento_cedente => "12345678912",
|
19
|
+
:sacado => "Claudio Pozzebom",
|
20
|
+
:sacado_documento => "12345678900",
|
21
|
+
:agencia => "4042",
|
22
|
+
:conta_corrente => "61900",
|
23
|
+
:convenio => 12387989,
|
24
|
+
:numero_documento => "777700168"
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should test gs presence" do
|
29
|
+
RGhost::Config.config_platform
|
30
|
+
File.exist?(RGhost::Config::GS[:path]).should be_true
|
31
|
+
File.executable?(RGhost::Config::GS[:path]).should be_true
|
32
|
+
s=`#{RGhost::Config::GS[:path]} -v`
|
33
|
+
s.should =~ /^GPL Ghostscript 8\.[6-9]/
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
module Brcobranca
|
4
|
+
module Boleto
|
5
|
+
module Template
|
6
|
+
describe Rghost do
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
@valid_attributes = {
|
10
|
+
:especie_documento => "DM",
|
11
|
+
:moeda => "9",
|
12
|
+
:banco => "001",
|
13
|
+
:data_documento => Date.today,
|
14
|
+
:dias_vencimento => 1,
|
15
|
+
:aceite => "S",
|
16
|
+
:quantidade => 1,
|
17
|
+
:valor => 0.0,
|
18
|
+
:local_pagamento => "QUALQUER BANCO ATÉ O VENCIMENTO",
|
19
|
+
:cedente => "Kivanio Barbosa",
|
20
|
+
:documento_cedente => "12345678912",
|
21
|
+
:sacado => "Claudio Pozzebom",
|
22
|
+
:sacado_documento => "12345678900",
|
23
|
+
:agencia => "4042",
|
24
|
+
:conta_corrente => "61900",
|
25
|
+
:convenio => 12387989,
|
26
|
+
:numero_documento => "777700168"
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should genarate a banck invoice" do
|
31
|
+
@valid_attributes[:valor] = 135.00
|
32
|
+
@valid_attributes[:data_documento] = Date.parse("2008-02-01")
|
33
|
+
@valid_attributes[:dias_vencimento] = 2
|
34
|
+
@valid_attributes[:convenio] = 1238798
|
35
|
+
@valid_attributes[:numero_documento] = "7777700168"
|
36
|
+
boleto_novo = BancoBrasil.new(@valid_attributes)
|
37
|
+
boleto_novo.should be_instance_of(BancoBrasil)
|
38
|
+
boleto_novo.monta_codigo_43_digitos.should eql("0019377100000135000000001238798777770016818")
|
39
|
+
boleto_novo.codigo_barras.should eql("00193377100000135000000001238798777770016818")
|
40
|
+
boleto_novo.codigo_barras.linha_digitavel.should eql("00190.00009 01238.798779 77700.168188 3 37710000013500")
|
41
|
+
boleto_novo.conta_corrente_dv.should eql(0)
|
42
|
+
#
|
43
|
+
# %w| pdf jpg tif png ps |.each do |format|
|
44
|
+
# file_body=boleto_novo.to(format.to_sym)
|
45
|
+
# tmp_file=Tempfile.new("foobar." << format)
|
46
|
+
# tmp_file.puts file_body
|
47
|
+
# tmp_file.close
|
48
|
+
# File.exist?(tmp_file.path).should be_true
|
49
|
+
# File.stat(tmp_file.path).zero?.should be_false
|
50
|
+
# File.delete(tmp_file.path).should eql(1)
|
51
|
+
# File.exist?(tmp_file.path).should be_false
|
52
|
+
# end
|
53
|
+
# file_body=boleto_novo.to
|
54
|
+
# tmp_file=Tempfile.new("foobar.")
|
55
|
+
# tmp_file.puts file_body
|
56
|
+
# tmp_file.close
|
57
|
+
# File.exist?(tmp_file.path).should be_true
|
58
|
+
# File.stat(tmp_file.path).zero?.should be_false
|
59
|
+
# File.delete(tmp_file.path).should eql(1)
|
60
|
+
# File.exist?(tmp_file.path).should be_false
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
module Brcobranca
|
4
|
+
module Boleto
|
5
|
+
module Template
|
6
|
+
describe Util do
|
7
|
+
it "should get correct file" do
|
8
|
+
boleto_novo = BancoBanespa.new
|
9
|
+
File.exist?(boleto_novo.monta_logo).should be_true
|
10
|
+
File.stat(boleto_novo.monta_logo).zero?.should be_false
|
11
|
+
|
12
|
+
boleto_novo = BancoBradesco.new
|
13
|
+
File.exist?(boleto_novo.monta_logo).should be_true
|
14
|
+
File.stat(boleto_novo.monta_logo).zero?.should be_false
|
15
|
+
|
16
|
+
boleto_novo = BancoBrasil.new
|
17
|
+
File.exist?(boleto_novo.monta_logo).should be_true
|
18
|
+
File.stat(boleto_novo.monta_logo).zero?.should be_false
|
19
|
+
|
20
|
+
boleto_novo = BancoHsbc.new
|
21
|
+
File.exist?(boleto_novo.monta_logo).should be_true
|
22
|
+
File.stat(boleto_novo.monta_logo).zero?.should be_false
|
23
|
+
|
24
|
+
boleto_novo = BancoItau.new
|
25
|
+
File.exist?(boleto_novo.monta_logo).should be_true
|
26
|
+
File.stat(boleto_novo.monta_logo).zero?.should be_false
|
27
|
+
|
28
|
+
boleto_novo = BancoReal.new
|
29
|
+
File.exist?(boleto_novo.monta_logo).should be_true
|
30
|
+
File.stat(boleto_novo.monta_logo).zero?.should be_false
|
31
|
+
|
32
|
+
boleto_novo = BancoUnibanco.new
|
33
|
+
File.exist?(boleto_novo.monta_logo).should be_true
|
34
|
+
File.stat(boleto_novo.monta_logo).zero?.should be_false
|
35
|
+
|
36
|
+
boleto_novo = Brcobranca::Boleto::Base.new
|
37
|
+
boleto_novo.monta_logo.should be_false
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/spec/rcov.opts
ADDED
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
data/tasks/rcov.rake
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec/rake/spectask'
|
2
|
+
|
3
|
+
namespace :rcov do
|
4
|
+
Spec::Rake::SpecTask.new(:rspec) do |t|
|
5
|
+
t.spec_opts = ['--options', "spec/spec.opts"]
|
6
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
7
|
+
t.rcov = true
|
8
|
+
t.rcov_opts = lambda do
|
9
|
+
IO.readlines("spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/tasks/rspec.rake
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
begin
|
2
|
+
require 'spec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
5
|
+
require 'spec'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'spec/rake/spectask'
|
9
|
+
rescue LoadError
|
10
|
+
puts <<-EOS
|
11
|
+
To use rspec for testing you must install rspec gem:
|
12
|
+
gem install rspec
|
13
|
+
EOS
|
14
|
+
exit(0)
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Run the specs under spec/models"
|
18
|
+
Spec::Rake::SpecTask.new do |t|
|
19
|
+
t.spec_opts = ['--options', "spec/spec.opts"]
|
20
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
21
|
+
end
|