boleto_bancario 0.0.1.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/.gitignore +18 -0
  2. data/.rspec +1 -0
  3. data/.rvmrc +1 -0
  4. data/Changelog.markdown +6 -0
  5. data/Gemfile +3 -0
  6. data/LICENSE +22 -0
  7. data/Planning.markdown +131 -0
  8. data/README.markdown +208 -0
  9. data/Rakefile +9 -0
  10. data/TODO.markdown +5 -0
  11. data/boleto_bancario.gemspec +25 -0
  12. data/documentacoes_dos_boletos/Bradesco/Manual_BRADESCO.PDF +0 -0
  13. data/lib/boleto_bancario/calculos/digitos.rb +35 -0
  14. data/lib/boleto_bancario/calculos/fator_vencimento.rb +87 -0
  15. data/lib/boleto_bancario/calculos/fatores_de_multiplicacao.rb +67 -0
  16. data/lib/boleto_bancario/calculos/linha_digitavel.rb +158 -0
  17. data/lib/boleto_bancario/calculos/modulo10.rb +83 -0
  18. data/lib/boleto_bancario/calculos/modulo11.rb +54 -0
  19. data/lib/boleto_bancario/calculos/modulo11_fator_de2a7.rb +97 -0
  20. data/lib/boleto_bancario/calculos/modulo11_fator_de2a9.rb +83 -0
  21. data/lib/boleto_bancario/calculos/modulo11_fator_de2a9_resto_zero.rb +29 -0
  22. data/lib/boleto_bancario/calculos/modulo11_fator_de9a2_resto_x.rb +101 -0
  23. data/lib/boleto_bancario/core/banco_brasil.rb +532 -0
  24. data/lib/boleto_bancario/core/boleto.rb +525 -0
  25. data/lib/boleto_bancario/core/bradesco.rb +285 -0
  26. data/lib/boleto_bancario/core/itau.rb +455 -0
  27. data/lib/boleto_bancario/core/santander.rb +274 -0
  28. data/lib/boleto_bancario/version.rb +4 -0
  29. data/lib/boleto_bancario.rb +83 -0
  30. data/spec/boleto_bancario/calculos/digitos_spec.rb +19 -0
  31. data/spec/boleto_bancario/calculos/fator_vencimento_spec.rb +59 -0
  32. data/spec/boleto_bancario/calculos/fatores_de_multiplicacao_spec.rb +69 -0
  33. data/spec/boleto_bancario/calculos/linha_digitavel_spec.rb +57 -0
  34. data/spec/boleto_bancario/calculos/modulo10_spec.rb +49 -0
  35. data/spec/boleto_bancario/calculos/modulo11_fator_de2a7_spec.rb +43 -0
  36. data/spec/boleto_bancario/calculos/modulo11_fator_de2a9_resto_zero_spec.rb +39 -0
  37. data/spec/boleto_bancario/calculos/modulo11_fator_de2a9_spec.rb +61 -0
  38. data/spec/boleto_bancario/calculos/modulo11_fator_de9a2_resto_x_spec.rb +37 -0
  39. data/spec/boleto_bancario/calculos/modulo11_spec.rb +19 -0
  40. data/spec/boleto_bancario/core/banco_brasil_spec.rb +383 -0
  41. data/spec/boleto_bancario/core/boleto_spec.rb +102 -0
  42. data/spec/boleto_bancario/core/bradesco_spec.rb +170 -0
  43. data/spec/boleto_bancario/core/itau_spec.rb +336 -0
  44. data/spec/boleto_bancario/core/santander_spec.rb +135 -0
  45. data/spec/shared_examples/boleto_bancario_shared_example.rb +164 -0
  46. data/spec/spec_helper.rb +14 -0
  47. metadata +221 -0
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ module BoletoBancario
4
+ module Calculos
5
+ describe Modulo11FatorDe2a9RestoZero do
6
+ describe "#calculate" do
7
+ context "with a one number digit" do
8
+ subject { Modulo11FatorDe2a9RestoZero.new(6) }
9
+
10
+ it { should eq '0' }
11
+ end
12
+
13
+ context "with a two number digit" do
14
+ subject { Modulo11FatorDe2a9RestoZero.new(100) }
15
+
16
+ it { should eq '7' }
17
+ end
18
+
19
+ context "with a three number digit" do
20
+ subject { Modulo11FatorDe2a9RestoZero.new(1004) }
21
+
22
+ it { should eq '9' }
23
+ end
24
+
25
+ context "with a three number digit that returns zero" do
26
+ subject { Modulo11FatorDe2a9RestoZero.new(1088) }
27
+
28
+ it { should eq '0' }
29
+ end
30
+
31
+ context "when mod division return '10'" do
32
+ subject { Modulo11FatorDe2a9RestoZero.new(1073) }
33
+
34
+ it { should eq '1' }
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ module BoletoBancario
4
+ module Calculos
5
+ describe Modulo11FatorDe2a9 do
6
+ context 'with Itau example' do
7
+ subject { Modulo11FatorDe2a9.new('3419166700000123451101234567880057123457000') }
8
+
9
+ it { should eq '6' }
10
+ end
11
+
12
+ context 'with Bradesco example' do
13
+ subject { Modulo11FatorDe2a9.new('9999101200000350007772130530150081897500000') }
14
+
15
+ it { should eq '1' }
16
+ end
17
+
18
+ context 'with Banco Brasil example' do
19
+ subject { Modulo11FatorDe2a9.new('0019373700000001000500940144816060680935031') }
20
+
21
+ it { should eq '3' }
22
+ end
23
+
24
+ context 'with Caixa example' do
25
+ subject { Modulo11FatorDe2a9.new('1049107400000160000001100128701000901200200') }
26
+
27
+ it { should eq '1' }
28
+ end
29
+
30
+ context 'when calculations returns 11' do
31
+ subject { Modulo11FatorDe2a9.new('1049107400000160000001100128701000901200298') }
32
+
33
+ it { should eq '1' }
34
+ end
35
+
36
+ context 'when calculations returns 1' do
37
+ subject { Modulo11FatorDe2a9.new('1049107400000160000001100128701000901244437') }
38
+
39
+ it { should eq '1' }
40
+ end
41
+
42
+ context 'with one digit' do
43
+ subject { Modulo11FatorDe2a9.new('1') }
44
+
45
+ it { should eq '9' }
46
+ end
47
+
48
+ context 'with two digits' do
49
+ subject { Modulo11FatorDe2a9.new('91') }
50
+
51
+ it { should eq '4' }
52
+ end
53
+
54
+ context 'with three digits' do
55
+ subject { Modulo11FatorDe2a9.new('189') }
56
+
57
+ it { should eq '9' }
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ module BoletoBancario
4
+ module Calculos
5
+ describe Modulo11FatorDe9a2RestoX do
6
+ context "when the mod result is 10 (ten)" do
7
+ subject { Modulo11FatorDe9a2RestoX.new('3973') }
8
+
9
+ it { should eq 'X' }
10
+ end
11
+
12
+ context "when the mod result is zero" do
13
+ subject { Modulo11FatorDe9a2RestoX.new('3995') }
14
+
15
+ it { should eq '0' }
16
+ end
17
+
18
+ context "using the 'Banco Brasil' documentation example" do
19
+ subject { Modulo11FatorDe9a2RestoX.new('01129004590') }
20
+
21
+ it { should eq '3' }
22
+ end
23
+
24
+ context "when the result is one" do
25
+ subject { Modulo11FatorDe9a2RestoX.new('5964') }
26
+
27
+ it { should eq '1' }
28
+ end
29
+
30
+ context "with a five digit number" do
31
+ subject { Modulo11FatorDe9a2RestoX.new('10949') }
32
+
33
+ it { should eq '5' }
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ module BoletoBancario
4
+ module Calculos
5
+ describe Modulo11 do
6
+ subject { Modulo11.new(1) }
7
+
8
+ describe "#fatores" do
9
+ before { Modulo11.any_instance.stub(:calculate).and_return(1) }
10
+
11
+ it { expect { subject.fatores }.to raise_error(NotImplementedError, "Not implemented #fatores in subclass.") }
12
+ end
13
+
14
+ describe "#calculate" do
15
+ it { expect { Modulo11.new(1) }.to raise_error(NotImplementedError, "Not implemented #calculate in subclass.") }
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,383 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ module BoletoBancario
5
+ module Core
6
+ describe BancoBrasil do
7
+ it_should_behave_like 'boleto bancario'
8
+
9
+ describe "on validations" do
10
+ context "#agencia" do
11
+ it { should have_valid(:agencia).when('123', '1234') }
12
+ it { should_not have_valid(:agencia).when('12345', '123456', nil, '') }
13
+ end
14
+
15
+ context "#digito_agencia" do
16
+ it { should have_valid(:digito_agencia).when('1', '3', 'X') }
17
+ it { should_not have_valid(:digito_agencia).when('12', nil, '') }
18
+ end
19
+
20
+ context "#conta_corrente" do
21
+ it { should have_valid(:conta_corrente).when('12345678', '12345', '1234') }
22
+ it { should_not have_valid(:conta_corrente).when('123456789', nil, '') }
23
+ end
24
+
25
+ context "#digito_conta_corrente" do
26
+ it { should have_valid(:digito_conta_corrente).when('1') }
27
+ it { should_not have_valid(:digito_conta_corrente).when('12', nil, '') }
28
+ end
29
+
30
+ context "#codigo_cedente" do
31
+ it { should have_valid(:codigo_cedente).when('1234', '123456', '1234567', '12345678') }
32
+ it { should_not have_valid(:codigo_cedente).when('123', '1', '12', nil, '') }
33
+ end
34
+
35
+ context "when 'carteira' is 16 and 'codigo_cedente' 6 digits" do
36
+ subject { BancoBrasil.new(carteira: 16, codigo_cedente: 123456) }
37
+
38
+ it { should have_valid(:numero_documento).when('1234', '12345', '12345', '12345678911234567') }
39
+ it { should_not have_valid(:numero_documento).when(nil, '', '123456', '123456789112345678') }
40
+ end
41
+
42
+ context "when 'carteira' is 18 and 'codigo_cedente' 6 digits" do
43
+ subject { BancoBrasil.new(carteira: 18, codigo_cedente: 123456) }
44
+
45
+ it { should have_valid(:numero_documento).when('1234', '12345', '12345678911234567') }
46
+ it { should_not have_valid(:numero_documento).when(nil, '', '123456', '1234567', '123456789112345678') }
47
+ end
48
+
49
+ context "when 'carteira' is 12 and 'codigo_cedente' 6 digits" do
50
+ subject { BancoBrasil.new(carteira: 12, codigo_cedente: 123456) }
51
+
52
+ it { should have_valid(:numero_documento).when('12345', '1234') }
53
+ it { should_not have_valid(:numero_documento).when(nil, '', '123456', '12345678911234567') }
54
+ end
55
+
56
+ context "when 'codigo_cedente' 4 digits" do
57
+ subject { BancoBrasil.new(codigo_cedente: 1234) }
58
+
59
+ it { should have_valid(:numero_documento).when('123', '1235', '1234567') }
60
+ it { should_not have_valid(:numero_documento).when(nil, '', '12345678', '12345678911234567') }
61
+ end
62
+
63
+ context "when 'codigo_cedente' 7 digits" do
64
+ subject { BancoBrasil.new(codigo_cedente: 1234567) }
65
+
66
+ it { should have_valid(:numero_documento).when('1234567890', '1235', '1234567') }
67
+ it { should_not have_valid(:numero_documento).when(nil, '', '12345678901', '12345678911234567') }
68
+ end
69
+
70
+ context "when 'codigo_cedente' 8 digits" do
71
+ subject { BancoBrasil.new(codigo_cedente: 12345678) }
72
+
73
+ it { should have_valid(:numero_documento).when('123456789', '1235', '1234567') }
74
+ it { should_not have_valid(:numero_documento).when(nil, '', '1234567890', '12345678911234567') }
75
+ end
76
+ end
77
+
78
+ describe "#agencia" do
79
+ context "when have a value" do
80
+ subject { BancoBrasil.new(:agencia => '001') }
81
+
82
+ its(:agencia) { should eq '0001' }
83
+ end
84
+
85
+ context "when is nil" do
86
+ subject { BancoBrasil.new(:agencia => nil) }
87
+
88
+ its(:agencia) { should be nil }
89
+ end
90
+ end
91
+
92
+ describe "#conta_corrente" do
93
+ context "when have a value" do
94
+ subject { BancoBrasil.new(:conta_corrente => 913) }
95
+
96
+ its(:conta_corrente) { should eq '00000913' }
97
+ end
98
+
99
+ context "when is nil" do
100
+ subject { BancoBrasil.new(:conta_corrente => nil) }
101
+
102
+ its(:conta_corrente) { should be nil }
103
+ end
104
+ end
105
+
106
+ describe "#numero_documento" do
107
+ context "when have 'codigo_cedente' 4 digits" do
108
+ subject { BancoBrasil.new(:numero_documento => 913, :codigo_cedente => 1234) }
109
+
110
+ its(:numero_documento) { should eq '0000913' }
111
+ end
112
+
113
+ context "when have 'codigo_cedente' 6 digits" do
114
+ subject { BancoBrasil.new(:numero_documento => 913, :codigo_cedente => 123456) }
115
+
116
+ its(:numero_documento) { should eq '00913' }
117
+ end
118
+
119
+ context "when have 'codigo_cedente' 7 digits" do
120
+ subject { BancoBrasil.new(:numero_documento => 913, :codigo_cedente => 1234567) }
121
+
122
+ its(:numero_documento) { should eq '0000000913' }
123
+ end
124
+
125
+ context "when have 'codigo_cedente' 8 digits" do
126
+ subject { BancoBrasil.new(:numero_documento => 913, :codigo_cedente => 12345678) }
127
+
128
+ its(:numero_documento) { should eq '000000913' }
129
+ end
130
+
131
+ context "when is nil" do
132
+ subject { BancoBrasil.new(:numero_documento => nil) }
133
+
134
+ its(:numero_documento) { should be nil }
135
+ end
136
+
137
+ context "when 'codigo_cedente' is nil" do
138
+ subject { BancoBrasil.new(:numero_documento => '12') }
139
+
140
+ its(:numero_documento) { should eq '12' }
141
+ end
142
+ end
143
+
144
+ describe "#codigo_banco" do
145
+ its(:codigo_banco) { should eq '001' }
146
+ end
147
+
148
+ describe "#digito_codigo_banco" do
149
+ its(:digito_codigo_banco) { should eq '9' }
150
+ end
151
+
152
+ describe "#agencia_codigo_cedente" do
153
+ subject { BancoBrasil.new(agencia: 9999, digito_agencia: 6, conta_corrente: 99999, digito_conta_corrente: 7) }
154
+
155
+ its(:agencia_codigo_cedente) { should eq '9999-6 / 00099999-7' }
156
+ end
157
+
158
+ describe "#nosso_numero" do
159
+ context "when 'codigo_cedente 4 digits" do
160
+ subject { BancoBrasil.new(codigo_cedente: 1234, numero_documento: 1984) }
161
+
162
+ its(:nosso_numero) { should eq '12340001984-7' }
163
+ end
164
+
165
+ context "when 'codigo_cedente 6 digits" do
166
+ subject { BancoBrasil.new(codigo_cedente: 123456, numero_documento: 1984) }
167
+
168
+ its(:nosso_numero) { should eq '12345601984-2' }
169
+ end
170
+
171
+ context "when 'codigo_cedente 7 digits" do
172
+ subject { BancoBrasil.new(codigo_cedente: 1234567, numero_documento: 1984) }
173
+
174
+ its(:nosso_numero) { should eq '12345670000001984' }
175
+ end
176
+
177
+ context "when 'codigo_cedente 8 digits" do
178
+ subject { BancoBrasil.new(codigo_cedente: 12345678, numero_documento: 1984) }
179
+
180
+ its(:nosso_numero) { should eq '12345678000001984' }
181
+ end
182
+ end
183
+
184
+ describe "#codigo_cedente_quatro_digitos?" do
185
+ context "when is true" do
186
+ subject { BancoBrasil.new(codigo_cedente: 1234) }
187
+
188
+ its(:codigo_cedente_quatro_digitos?) { should be true }
189
+ end
190
+
191
+ context "when is false" do
192
+ subject { BancoBrasil.new(codigo_cedente: 12345) }
193
+
194
+ its(:codigo_cedente_quatro_digitos?) { should be false }
195
+ end
196
+ end
197
+
198
+ describe "#codigo_cedente_seis_digitos?" do
199
+ context "when is true" do
200
+ subject { BancoBrasil.new(codigo_cedente: 123456) }
201
+
202
+ its(:codigo_cedente_seis_digitos?) { should be true }
203
+ end
204
+
205
+ context "when is false" do
206
+ subject { BancoBrasil.new(codigo_cedente: 1234567) }
207
+
208
+ its(:codigo_cedente_seis_digitos?) { should be false }
209
+ end
210
+ end
211
+
212
+ describe "#codigo_cedente_sete_digitos?" do
213
+ context "when is true" do
214
+ subject { BancoBrasil.new(codigo_cedente: 1234567) }
215
+
216
+ its(:codigo_cedente_sete_digitos?) { should be true }
217
+ end
218
+
219
+ context "when is false" do
220
+ subject { BancoBrasil.new(codigo_cedente: 12345678) }
221
+
222
+ its(:codigo_cedente_sete_digitos?) { should be false }
223
+ end
224
+ end
225
+
226
+ describe "#codigo_cedente_oito_digitos?" do
227
+ context "when is true" do
228
+ subject { BancoBrasil.new(codigo_cedente: 12345678) }
229
+
230
+ its(:codigo_cedente_oito_digitos?) { should be true }
231
+ end
232
+
233
+ context "when is false" do
234
+ subject { BancoBrasil.new(codigo_cedente: 123456789) }
235
+
236
+ its(:codigo_cedente_oito_digitos?) { should be false }
237
+ end
238
+ end
239
+
240
+ describe "#nosso_numero_dezessete_posicoes?" do
241
+ context "when 'carteira' 18, 'numero_documento' 17 digits and 'codigo_cedente' 6 digits" do
242
+ subject { BancoBrasil.new(numero_documento: 12345678911234567, carteira: 18, codigo_cedente: 123456) }
243
+
244
+ its(:nosso_numero_dezessete_posicoes?) { should be true }
245
+ end
246
+
247
+ context "when 'carteira' 16, 'numero_documento' 17 digits and 'codigo_cedente' 6 digits" do
248
+ subject { BancoBrasil.new(numero_documento: 12345678911234567, carteira: 16, codigo_cedente: 123456) }
249
+
250
+ its(:nosso_numero_dezessete_posicoes?) { should be true }
251
+ end
252
+
253
+ context "when is 'carteira' is not supported" do
254
+ subject { BancoBrasil.new(numero_documento: 123456789, carteira: 12, codigo_cedente: 123456) }
255
+
256
+ its(:nosso_numero_dezessete_posicoes?) { should be false }
257
+ end
258
+
259
+ context "when is 'codigo_cedente' is not supported" do
260
+ subject { BancoBrasil.new(numero_documento: 123456789, carteira: 16, codigo_cedente: 1234567) }
261
+
262
+ its(:nosso_numero_dezessete_posicoes?) { should be false }
263
+ end
264
+ end
265
+
266
+ describe "#codigo_de_barras" do
267
+ context "'codigo_cedente' with 4 digits" do
268
+ subject do
269
+ BancoBrasil.new do |banco_brasil|
270
+ banco_brasil.carteira = 18
271
+ banco_brasil.valor_documento = 2952.95
272
+ banco_brasil.numero_documento = 90801
273
+ banco_brasil.agencia = 7123
274
+ banco_brasil.digito_agencia = 6
275
+ banco_brasil.conta_corrente = 19345
276
+ banco_brasil.digito_conta_corrente = 7
277
+ banco_brasil.data_vencimento = Date.parse('2012-12-28')
278
+ banco_brasil.codigo_cedente = 4321
279
+ end
280
+ end
281
+
282
+ its(:codigo_de_barras) { should eq '00193556100002952954321009080171230001934518' }
283
+ its(:linha_digitavel) { should eq '00194.32103 09080.171235 00019.345180 3 55610000295295' }
284
+ end
285
+
286
+ context "'codigo_cedente' with 6 digits" do
287
+ subject do
288
+ BancoBrasil.new do |banco_brasil|
289
+ banco_brasil.carteira = 18
290
+ banco_brasil.valor_documento = 14001.99
291
+ banco_brasil.numero_documento = 12901
292
+ banco_brasil.agencia = 5030
293
+ banco_brasil.digito_agencia = 6
294
+ banco_brasil.conta_corrente = 14204195
295
+ banco_brasil.digito_conta_corrente = 7
296
+ banco_brasil.data_vencimento = Date.parse('2012-12-28')
297
+ banco_brasil.codigo_cedente = 555444
298
+ end
299
+ end
300
+
301
+ its(:codigo_de_barras) { should eq '00197556100014001995554441290150301420419518' }
302
+ its(:linha_digitavel) { should eq '00195.55440 41290.150303 14204.195185 7 55610001400199' }
303
+ end
304
+
305
+ context "'codigo_cedente' with 6 digits and 'nosso numero' with 17 digits" do
306
+ subject do
307
+ BancoBrasil.new do |banco_brasil|
308
+ banco_brasil.carteira = 12
309
+ banco_brasil.valor_documento = 14001.99
310
+ banco_brasil.numero_documento = 12345678911234567
311
+ banco_brasil.agencia = 5030
312
+ banco_brasil.digito_agencia = 6
313
+ banco_brasil.conta_corrente = 14204195
314
+ banco_brasil.digito_conta_corrente = 7
315
+ banco_brasil.data_vencimento = Date.parse('2012-12-28')
316
+ banco_brasil.codigo_cedente = 555444
317
+ end
318
+ end
319
+
320
+ its(:linha_digitavel) { should eq "" }
321
+ end
322
+
323
+
324
+ context "'codigo_cedente' with 6 digits and 'nosso numero' with 17 digits" do
325
+ subject do
326
+ BancoBrasil.new do |banco_brasil|
327
+ banco_brasil.carteira = 18
328
+ banco_brasil.valor_documento = 14001.99
329
+ banco_brasil.numero_documento = 12345678911234567
330
+ banco_brasil.agencia = 5030
331
+ banco_brasil.digito_agencia = 6
332
+ banco_brasil.conta_corrente = 14204195
333
+ banco_brasil.digito_conta_corrente = 7
334
+ banco_brasil.data_vencimento = Date.parse('2012-12-28')
335
+ banco_brasil.codigo_cedente = 555444
336
+ end
337
+ end
338
+
339
+ its(:codigo_de_barras) { should eq '00194556100014001995554441234567891123456721' }
340
+ its(:linha_digitavel) { should eq "00195.55440 41234.567893 11234.567219 4 55610001400199" }
341
+ end
342
+
343
+ context "'codigo_cedente' with 7 digits" do
344
+ subject do
345
+ BancoBrasil.new do |banco_brasil|
346
+ banco_brasil.carteira = 18
347
+ banco_brasil.valor_documento = 2952.95
348
+ banco_brasil.numero_documento = 87654
349
+ banco_brasil.agencia = 9999
350
+ banco_brasil.digito_agencia = 6
351
+ banco_brasil.conta_corrente = 99999
352
+ banco_brasil.digito_conta_corrente = 7
353
+ banco_brasil.data_vencimento = Date.parse('2012-12-28')
354
+ banco_brasil.codigo_cedente = 7777777
355
+ end
356
+ end
357
+
358
+ its(:codigo_de_barras) { should eq '00197556100002952950000007777777000008765418' }
359
+ its(:linha_digitavel) { should eq '00190.00009 07777.777009 00087.654182 7 55610000295295' }
360
+ end
361
+
362
+ context "'codigo_cedente' with 8 digits" do
363
+ subject do
364
+ BancoBrasil.new do |banco_brasil|
365
+ banco_brasil.carteira = 18
366
+ banco_brasil.valor_documento = 2952.95
367
+ banco_brasil.numero_documento = 87654
368
+ banco_brasil.agencia = 9999
369
+ banco_brasil.digito_agencia = 6
370
+ banco_brasil.conta_corrente = 99999
371
+ banco_brasil.digito_conta_corrente = 7
372
+ banco_brasil.data_vencimento = Date.parse('2012-12-28')
373
+ banco_brasil.codigo_cedente = 77777778
374
+ end
375
+ end
376
+
377
+ its(:codigo_de_barras) { should eq '00191556100002952950000007777777800008765418' }
378
+ its(:linha_digitavel) { should eq '00190.00009 07777.777801 00087.654182 1 55610000295295' }
379
+ end
380
+ end
381
+ end
382
+ end
383
+ end
@@ -0,0 +1,102 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ module BoletoBancario
5
+ module Core
6
+ describe Boleto do
7
+ describe '#initialize' do
8
+ context 'when passing a Hash' do
9
+ subject do
10
+ described_class.new(
11
+ :numero_documento => '191075',
12
+ :valor_documento => 101.99,
13
+ :data_vencimento => Date.new(2012, 10, 10),
14
+ :carteira => '175',
15
+ :agencia => '0098',
16
+ :digito_agencia => '1',
17
+ :conta_corrente => '98701',
18
+ :cedente => 'Nome da razao social',
19
+ :sacado => 'Teste',
20
+ :documento_sacado => '725.275.005-10',
21
+ :endereco_sacado => 'Rua teste, 23045'
22
+ )
23
+ end
24
+
25
+ its(:numero_documento) { should eq '191075' }
26
+ its(:valor_documento) { should eq 101.99 }
27
+ its(:data_vencimento) { should eq Date.new(2012, 10, 10) }
28
+ its(:carteira) { should eq '175' }
29
+ its(:agencia) { should eq '0098' }
30
+ its(:digito_agencia) { should eq '1' }
31
+ its(:conta_corrente) { should eq '98701' }
32
+ its(:codigo_moeda) { should eq '9' }
33
+ its(:cedente) { should eq 'Nome da razao social' }
34
+ its(:especie) { should eq 'R$' }
35
+ its(:especie_documento) { should eq 'DM' }
36
+ its(:data_documento) { should eq Date.today }
37
+ its(:sacado) { should eq 'Teste' }
38
+ its(:documento_sacado) { should eq '725.275.005-10' }
39
+ its(:endereco_sacado) { should eq 'Rua teste, 23045'}
40
+ its(:local_pagamento) { should eq 'PAGÁVEL EM QUALQUER BANCO ATÉ O VENCIMENTO' }
41
+ end
42
+
43
+ context 'when passing a block' do
44
+ subject do
45
+ described_class.new do |boleto|
46
+ boleto.numero_documento = '187390'
47
+ boleto.valor_documento = 1
48
+ boleto.data_vencimento = Date.new(2012, 10, 10)
49
+ boleto.carteira = '109'
50
+ boleto.agencia = '0914'
51
+ boleto.conta_corrente = '82369'
52
+ boleto.codigo_cedente = '90182'
53
+ boleto.endereco_cedente = 'Rua Itapaiuna, 2434'
54
+ boleto.cedente = 'Nome da razao social'
55
+ boleto.documento_cedente = '62.526.713/0001-40'
56
+ boleto.sacado = 'Teste'
57
+ end
58
+ end
59
+
60
+ its(:numero_documento) { should eq '187390' }
61
+ its(:valor_documento) { should eq 1 }
62
+ its(:carteira) { should eq '109' }
63
+ its(:agencia) { should eq '0914' }
64
+ its(:conta_corrente) { should eq '82369' }
65
+ its(:codigo_moeda) { should eq '9' }
66
+ its(:codigo_cedente) { should eq '90182' }
67
+ its(:endereco_cedente) { should eq 'Rua Itapaiuna, 2434' }
68
+ its(:cedente) { should eq 'Nome da razao social' }
69
+ its(:documento_cedente) { should eq '62.526.713/0001-40' }
70
+ its(:sacado) { should eq 'Teste' }
71
+ end
72
+ end
73
+
74
+ describe "#carteira_formatada" do
75
+ it "should return 'carteira' as default" do
76
+ subject.stub(:carteira).and_return('Foo')
77
+ subject.carteira_formatada.should eq 'Foo'
78
+ end
79
+ end
80
+
81
+ describe "#codigo_banco" do
82
+ it { expect { subject.codigo_banco }.to raise_error(NotImplementedError) }
83
+ end
84
+
85
+ describe "#digito_codigo_banco" do
86
+ it { expect { subject.digito_codigo_banco }.to raise_error(NotImplementedError) }
87
+ end
88
+
89
+ describe "#agencia_codigo_cedente" do
90
+ it { expect { subject.agencia_codigo_cedente }.to raise_error(NotImplementedError) }
91
+ end
92
+
93
+ describe "#nosso_numero" do
94
+ it { expect { subject.nosso_numero }.to raise_error(NotImplementedError) }
95
+ end
96
+
97
+ describe "#codigo_de_barras_do_banco" do
98
+ it { expect { subject.codigo_de_barras_do_banco }.to raise_error(NotImplementedError) }
99
+ end
100
+ end
101
+ end
102
+ end