cnab 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +18 -2
- data/lib/cnab.rb +6 -2
- data/lib/cnab/detalhe.rb +5 -0
- data/lib/cnab/detalhe/segmento_t.rb +31 -29
- data/lib/cnab/detalhe/segmento_t_u.rb +22 -0
- data/lib/cnab/detalhe/segmento_u.rb +26 -24
- data/lib/cnab/exceptions.rb +1 -0
- data/lib/cnab/exceptions/line_not_parseable.rb +9 -0
- data/lib/cnab/header_arquivo.rb +26 -24
- data/lib/cnab/header_lote/cobranca.rb +25 -23
- data/lib/cnab/helper.rb +13 -1
- data/lib/cnab/trailer_arquivo.rb +10 -8
- data/lib/cnab/trailer_lote/cobranca.rb +17 -15
- data/lib/cnab/version.rb +1 -1
- data/spec/cnab/detalhe/segmento_t_spec.rb +97 -89
- data/spec/cnab/detalhe/segmento_t_u_spec.rb +24 -0
- data/spec/cnab/detalhe/segmento_u_spec.rb +105 -97
- data/spec/cnab/detalhe_spec.rb +24 -3
- data/spec/cnab/header_arquivo_spec.rb +103 -95
- data/spec/cnab/header_lote/cobranca_spec.rb +79 -71
- data/spec/cnab/trailer_arquivo_spec.rb +34 -26
- data/spec/cnab_spec.rb +55 -31
- data/spec/spec_helper.rb +1 -1
- metadata +12 -2
data/spec/cnab/detalhe_spec.rb
CHANGED
@@ -3,21 +3,42 @@ require 'spec_helper'
|
|
3
3
|
describe Cnab::Detalhe do
|
4
4
|
describe "#parse" do
|
5
5
|
context "with a line of segmento U" do
|
6
|
+
before :each do
|
7
|
+
@line = LINE.clone
|
8
|
+
@line[13] = "U"
|
9
|
+
end
|
10
|
+
|
6
11
|
it "should return a instance of SegmentoU" do
|
7
|
-
Cnab::Detalhe.parse(
|
12
|
+
Cnab::Detalhe.parse(@line).should be_an_instance_of(Cnab::Detalhe::SegmentoU)
|
8
13
|
end
|
9
14
|
end
|
10
15
|
|
11
16
|
context "with a line of segmento T" do
|
17
|
+
before :each do
|
18
|
+
@line = LINE.clone
|
19
|
+
@line[13] = "T"
|
20
|
+
end
|
21
|
+
|
12
22
|
it "should return a instance of SegmentoT" do
|
13
|
-
Cnab::Detalhe.parse(
|
23
|
+
Cnab::Detalhe.parse(@line).should be_an_instance_of(Cnab::Detalhe::SegmentoT)
|
14
24
|
end
|
15
25
|
end
|
16
26
|
|
17
27
|
context "with a line of any other segmento" do
|
18
28
|
it "should raise an error" do
|
19
|
-
lambda { Cnab::Detalhe.parse(
|
29
|
+
lambda { Cnab::Detalhe.parse(LINE) }.should raise_error(Cnab::Exceptions::SegmentNotImplemented)
|
20
30
|
end
|
21
31
|
end
|
22
32
|
end
|
33
|
+
|
34
|
+
describe "#merge" do
|
35
|
+
before :each do
|
36
|
+
Cnab::Detalhe.stub(:parse).with("line1").and_return(Cnab::Detalhe::SegmentoT.new(LINE))
|
37
|
+
Cnab::Detalhe.stub(:parse).with("line2").and_return(Cnab::Detalhe::SegmentoU.new(LINE))
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should return a Cnab::Detalhe::SegmentoTU instance" do
|
41
|
+
Cnab::Detalhe.merge("line1", "line2").should be_an_instance_of(Cnab::Detalhe::SegmentoTU)
|
42
|
+
end
|
43
|
+
end
|
23
44
|
end
|
@@ -1,105 +1,113 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Cnab::HeaderArquivo do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should set #banco" do
|
10
|
-
@header_arquivo.banco.should == "012"
|
4
|
+
context "with a non valid line" do
|
5
|
+
it "should raise an error" do
|
6
|
+
lambda { Cnab::HeaderArquivo.new("12345") }.should raise_error(Cnab::Exceptions::LineNotParseable)
|
11
7
|
end
|
8
|
+
end
|
12
9
|
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
context "with a valid line" do
|
11
|
+
describe "#initialize" do
|
12
|
+
before :each do
|
13
|
+
@header_arquivo = Cnab::HeaderArquivo.new(LINE)
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
it "should set #banco" do
|
17
|
+
@header_arquivo.banco.should == "012"
|
18
|
+
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
20
|
+
it "should set #lote" do
|
21
|
+
@header_arquivo.lote.should == "3456"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should set #registro" do
|
25
|
+
@header_arquivo.registro.should == "7"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should set #res_cnab1" do
|
29
|
+
@header_arquivo.res_cnab1.should == "890123456"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should set #tipo_empresa" do
|
33
|
+
@header_arquivo.tipo_empresa.should == "7"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should set #num_empresa" do
|
37
|
+
@header_arquivo.num_empresa.should == "89012345678901"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should set #convenio" do
|
41
|
+
@header_arquivo.convenio.should == "23456789012345678901"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should set #agencia" do
|
45
|
+
@header_arquivo.agencia.should == "23456"
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should set #dv_agencia" do
|
49
|
+
@header_arquivo.dv_agencia.should == "7"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should set #conta_corrente" do
|
53
|
+
@header_arquivo.conta_corrente.should == "890123456789"
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should set #dv_conta" do
|
57
|
+
@header_arquivo.dv_conta.should == "0"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should set #dv_conta_agencia" do
|
61
|
+
@header_arquivo.dv_conta_agencia.should == "1"
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should set #nome_empresa" do
|
65
|
+
@header_arquivo.nome_empresa.should == "234567890123456789012345678901"
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should set #nome_banco" do
|
69
|
+
@header_arquivo.nome_banco.should == "234567890123456789012345678901"
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should set #res_cnab2" do
|
73
|
+
@header_arquivo.res_cnab2.should == "2345678901"
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should set #cod_retorno" do
|
77
|
+
@header_arquivo.cod_retorno.should == "2"
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should set #data_geracao_arq" do
|
81
|
+
@header_arquivo.data_geracao_arq.should == "34567890"
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should set #hora_geracao_arq" do
|
85
|
+
@header_arquivo.hora_geracao_arq.should == "123456"
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should set #sequencia" do
|
89
|
+
@header_arquivo.sequencia.should == "789012"
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should set #versao" do
|
93
|
+
@header_arquivo.versao.should == "345"
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should set #densidade" do
|
97
|
+
@header_arquivo.densidade.should == "67890"
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should set #res_banco" do
|
101
|
+
@header_arquivo.res_banco.should == "12345678901234567890"
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should set #res_empresa" do
|
105
|
+
@header_arquivo.res_empresa.should == "12345678901234567890"
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should set #res_cnab3" do
|
109
|
+
@header_arquivo.res_cnab3.should == "12345678901234567890123456789"
|
110
|
+
end
|
103
111
|
end
|
104
112
|
end
|
105
113
|
end
|
@@ -2,100 +2,108 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Cnab::HeaderLote::Cobranca do
|
4
4
|
describe "#initialize" do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
it "should set #banco" do
|
10
|
-
@cobranca.banco.should == "012"
|
5
|
+
context "with a non valid line" do
|
6
|
+
it "should raise an error" do
|
7
|
+
lambda { Cnab::HeaderLote::Cobranca.new("12345") }.should raise_error(Cnab::Exceptions::LineNotParseable)
|
8
|
+
end
|
11
9
|
end
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
context "with a valid line" do
|
12
|
+
before :each do
|
13
|
+
@cobranca = Cnab::HeaderLote::Cobranca.new(LINE)
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
it "should set #banco" do
|
17
|
+
@cobranca.banco.should == "012"
|
18
|
+
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
it "should set #lote" do
|
21
|
+
@cobranca.lote.should == "3456"
|
22
|
+
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
it "should set #registro" do
|
25
|
+
@cobranca.registro.should == "7"
|
26
|
+
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
it "should set #tipo_operacao" do
|
29
|
+
@cobranca.tipo_operacao.should == "8"
|
30
|
+
end
|
32
31
|
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
it "should set #tipo_servico" do
|
33
|
+
@cobranca.tipo_servico.should == "90"
|
34
|
+
end
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
it "should set #res_cnab1" do
|
37
|
+
@cobranca.res_cnab1.should == "12"
|
38
|
+
end
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
it "should set #layout_lote" do
|
41
|
+
@cobranca.layout_lote.should == "345"
|
42
|
+
end
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
|
44
|
+
it "should set #res_cnab2" do
|
45
|
+
@cobranca.res_cnab2.should == "6"
|
46
|
+
end
|
48
47
|
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
it "should set #tipo_empresa" do
|
49
|
+
@cobranca.tipo_empresa.should == "7"
|
50
|
+
end
|
52
51
|
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
it "should set #num_empresa" do
|
53
|
+
@cobranca.num_empresa.should == "890123456789012"
|
54
|
+
end
|
56
55
|
|
57
|
-
|
58
|
-
|
59
|
-
|
56
|
+
it "should set #convenio" do
|
57
|
+
@cobranca.convenio.should == "34567890123456789012"
|
58
|
+
end
|
60
59
|
|
61
|
-
|
62
|
-
|
63
|
-
|
60
|
+
it "should set #agencia" do
|
61
|
+
@cobranca.agencia.should == "34567"
|
62
|
+
end
|
64
63
|
|
65
|
-
|
66
|
-
|
67
|
-
|
64
|
+
it "should set #dv_agencia" do
|
65
|
+
@cobranca.dv_agencia.should == "8"
|
66
|
+
end
|
68
67
|
|
69
|
-
|
70
|
-
|
71
|
-
|
68
|
+
it "should set #conta_corrente" do
|
69
|
+
@cobranca.conta_corrente.should == "901234567890"
|
70
|
+
end
|
72
71
|
|
73
|
-
|
74
|
-
|
75
|
-
|
72
|
+
it "should set #dv_conta" do
|
73
|
+
@cobranca.dv_conta.should == "1"
|
74
|
+
end
|
76
75
|
|
77
|
-
|
78
|
-
|
79
|
-
|
76
|
+
it "should set #dv_conta_agencia" do
|
77
|
+
@cobranca.dv_conta_agencia.should == "2"
|
78
|
+
end
|
80
79
|
|
81
|
-
|
82
|
-
|
83
|
-
|
80
|
+
it "should set #nome_empresa" do
|
81
|
+
@cobranca.nome_empresa.should == "345678901234567890123456789012"
|
82
|
+
end
|
84
83
|
|
85
|
-
|
86
|
-
|
87
|
-
|
84
|
+
it "should set #informacao1" do
|
85
|
+
@cobranca.informacao1.should == "3456789012345678901234567890123456789012"
|
86
|
+
end
|
88
87
|
|
89
|
-
|
90
|
-
|
91
|
-
|
88
|
+
it "should set #informacao2" do
|
89
|
+
@cobranca.informacao2.should == "3456789012345678901234567890123456789012"
|
90
|
+
end
|
92
91
|
|
93
|
-
|
94
|
-
|
95
|
-
|
92
|
+
it "should set #numero_remessa" do
|
93
|
+
@cobranca.numero_remessa.should == "34567890"
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should set #data_gravacao" do
|
97
|
+
@cobranca.data_gravacao.should == "12345678"
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should set #data_credito" do
|
101
|
+
@cobranca.data_credito.should == "90123456"
|
102
|
+
end
|
96
103
|
|
97
|
-
|
98
|
-
|
104
|
+
it "should set #res_cnab3" do
|
105
|
+
@cobranca.res_cnab3.should == "789012345678901234567890123456789"
|
106
|
+
end
|
99
107
|
end
|
100
108
|
end
|
101
109
|
end
|
@@ -2,40 +2,48 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Cnab::TrailerArquivo do
|
4
4
|
describe "#initialize" do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
it "should set #banco" do
|
10
|
-
@trailer_arquivo.banco.should == "012"
|
5
|
+
context "with a non valid line" do
|
6
|
+
it "should raise an error" do
|
7
|
+
lambda { Cnab::TrailerArquivo.new("12345") }.should raise_error(Cnab::Exceptions::LineNotParseable)
|
8
|
+
end
|
11
9
|
end
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
context "with a valid line" do
|
12
|
+
before :each do
|
13
|
+
@trailer_arquivo = Cnab::TrailerArquivo.new(LINE)
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
it "should set #banco" do
|
17
|
+
@trailer_arquivo.banco.should == "012"
|
18
|
+
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
it "should set #lote" do
|
21
|
+
@trailer_arquivo.lote.should == "3456"
|
22
|
+
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
it "should set #registro" do
|
25
|
+
@trailer_arquivo.registro.should == "7"
|
26
|
+
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
it "should set #res_cnab1" do
|
29
|
+
@trailer_arquivo.res_cnab1.should == "890123456"
|
30
|
+
end
|
32
31
|
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
it "should set #qtd_lotes" do
|
33
|
+
@trailer_arquivo.qtd_lotes.should == "789012"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should set #qtd_registros" do
|
37
|
+
@trailer_arquivo.qtd_registros.should == "345678"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should set #qtd_contas" do
|
41
|
+
@trailer_arquivo.qtd_contas.should == "901234"
|
42
|
+
end
|
36
43
|
|
37
|
-
|
38
|
-
|
44
|
+
it "should set #res_cnab2" do
|
45
|
+
@trailer_arquivo.res_cnab2.should == "5678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
|
46
|
+
end
|
39
47
|
end
|
40
48
|
end
|
41
49
|
end
|