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
@@ -2,124 +2,132 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Cnab::Detalhe::SegmentoT do
|
4
4
|
describe "#initialize" do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
it "should set #banco" do
|
10
|
-
@segmento_t.banco.should == "012"
|
5
|
+
context "with a non valid line" do
|
6
|
+
it "should raise an error" do
|
7
|
+
lambda { Cnab::Detalhe::SegmentoT.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
|
+
@segmento_t = Cnab::Detalhe::SegmentoT.new(LINE)
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
it "should set #banco" do
|
17
|
+
@segmento_t.banco.should == "012"
|
18
|
+
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
it "should set #lote" do
|
21
|
+
@segmento_t.lote.should == "3456"
|
22
|
+
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
it "should set #tipo_registro" do
|
25
|
+
@segmento_t.tipo_registro.should == "7"
|
26
|
+
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
it "should set #num_registro" do
|
29
|
+
@segmento_t.num_registro.should == "89012"
|
30
|
+
end
|
32
31
|
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
it "should set #segmento" do
|
33
|
+
@segmento_t.segmento.should == "3"
|
34
|
+
end
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
it "should set #res_cnab1" do
|
37
|
+
@segmento_t.res_cnab1.should == "4"
|
38
|
+
end
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
it "should set #cod_movimentacao" do
|
41
|
+
@segmento_t.cod_movimentacao.should == "56"
|
42
|
+
end
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
|
44
|
+
it "should set #agencia" do
|
45
|
+
@segmento_t.agencia.should == "78901"
|
46
|
+
end
|
48
47
|
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
it "should set #dv_agencia" do
|
49
|
+
@segmento_t.dv_agencia.should == "2"
|
50
|
+
end
|
52
51
|
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
it "should set #conta_corrente" do
|
53
|
+
@segmento_t.conta_corrente.should == "345678901234"
|
54
|
+
end
|
56
55
|
|
57
|
-
|
58
|
-
|
59
|
-
|
56
|
+
it "should set #dv_conta" do
|
57
|
+
@segmento_t.dv_conta.should == "5"
|
58
|
+
end
|
60
59
|
|
61
|
-
|
62
|
-
|
63
|
-
|
60
|
+
it "should set #dv_conta_agencia" do
|
61
|
+
@segmento_t.dv_conta_agencia.should == "6"
|
62
|
+
end
|
64
63
|
|
65
|
-
|
66
|
-
|
67
|
-
|
64
|
+
it "should set #id_titulo" do
|
65
|
+
@segmento_t.id_titulo.should == "78901234567890123456"
|
66
|
+
end
|
68
67
|
|
69
|
-
|
70
|
-
|
71
|
-
|
68
|
+
it "should set #carteira" do
|
69
|
+
@segmento_t.carteira.should == "7"
|
70
|
+
end
|
72
71
|
|
73
|
-
|
74
|
-
|
75
|
-
|
72
|
+
it "should set #doc_cobranca" do
|
73
|
+
@segmento_t.doc_cobranca.should == "890123456789012"
|
74
|
+
end
|
76
75
|
|
77
|
-
|
78
|
-
|
79
|
-
|
76
|
+
it "should set #vencimento" do
|
77
|
+
@segmento_t.vencimento.should == "34567890"
|
78
|
+
end
|
80
79
|
|
81
|
-
|
82
|
-
|
83
|
-
|
80
|
+
it "should set #valor_titulo" do
|
81
|
+
@segmento_t.valor_titulo.should == "123456789012345"
|
82
|
+
end
|
84
83
|
|
85
|
-
|
86
|
-
|
87
|
-
|
84
|
+
it "should set #banco_recebimento" do
|
85
|
+
@segmento_t.banco_recebimento.should == "678"
|
86
|
+
end
|
88
87
|
|
89
|
-
|
90
|
-
|
91
|
-
|
88
|
+
it "should set #ag_recebimento" do
|
89
|
+
@segmento_t.ag_recebimento.should == "90123"
|
90
|
+
end
|
92
91
|
|
93
|
-
|
94
|
-
|
95
|
-
|
92
|
+
it "should set #dv_ag_recebimento" do
|
93
|
+
@segmento_t.dv_ag_recebimento.should == "4"
|
94
|
+
end
|
96
95
|
|
97
|
-
|
98
|
-
|
99
|
-
|
96
|
+
it "should set #id_titulo_empresa" do
|
97
|
+
@segmento_t.id_titulo_empresa.should == "5678901234567890123456789"
|
98
|
+
end
|
100
99
|
|
101
|
-
|
102
|
-
|
103
|
-
|
100
|
+
it "should set #cod_moeda" do
|
101
|
+
@segmento_t.cod_moeda.should == "01"
|
102
|
+
end
|
104
103
|
|
105
|
-
|
106
|
-
|
107
|
-
|
104
|
+
it "should set #tipo_inscricao" do
|
105
|
+
@segmento_t.tipo_inscricao.should == "2"
|
106
|
+
end
|
108
107
|
|
109
|
-
|
110
|
-
|
111
|
-
|
108
|
+
it "should set #num_inscricao" do
|
109
|
+
@segmento_t.num_inscricao.should == "345678901234567"
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should set #nome" do
|
113
|
+
@segmento_t.nome.should == "8901234567890123456789012345678901234567"
|
114
|
+
end
|
112
115
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
+
it "should set #num_contrato" do
|
117
|
+
@segmento_t.num_contrato.should == "8901234567"
|
118
|
+
end
|
116
119
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
+
it "should set #tarifa" do
|
121
|
+
@segmento_t.tarifa.should == "890123456789012"
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should set #motivo" do
|
125
|
+
@segmento_t.motivo.should == "3456789012"
|
126
|
+
end
|
120
127
|
|
121
|
-
|
122
|
-
|
128
|
+
it "should set #res_cnab2" do
|
129
|
+
@segmento_t.res_cnab2.should == "34567890123456789"
|
130
|
+
end
|
123
131
|
end
|
124
132
|
end
|
125
133
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cnab::Detalhe::SegmentoTU do
|
4
|
+
let(:segmento_t) { Cnab::Detalhe::SegmentoT.new(LINE) }
|
5
|
+
let(:segmento_u) { Cnab::Detalhe::SegmentoU.new(LINE) }
|
6
|
+
|
7
|
+
describe "#method_missing" do
|
8
|
+
before :each do
|
9
|
+
@segmento_t_u = Cnab::Detalhe::SegmentoTU.new(segmento_t, segmento_u)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should call attributes on segmento_t object when it exists" do
|
13
|
+
@segmento_t_u.should respond_to(:ag_recebimento)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should call attributes on segmento_u object when it exists" do
|
17
|
+
@segmento_t_u.should respond_to(:valor_iof)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should raise an error if no segmento has the attribute" do
|
21
|
+
lambda { @segmento_t_u.valor_total }.should raise_error(NoMethodError)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -2,104 +2,112 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Cnab::Detalhe::SegmentoU do
|
4
4
|
describe "#initialize" do
|
5
|
-
|
6
|
-
|
5
|
+
context "with a non valid line" do
|
6
|
+
it "should raise an error" do
|
7
|
+
lambda { Cnab::Detalhe::SegmentoU.new("12345") }.should raise_error(Cnab::Exceptions::LineNotParseable)
|
8
|
+
end
|
7
9
|
end
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
10
|
+
|
11
|
+
context "with a valid line" do
|
12
|
+
before :each do
|
13
|
+
@segmento_u = Cnab::Detalhe::SegmentoU.new(LINE)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should set #banco" do
|
17
|
+
@segmento_u.banco.should == "012"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should set #lote" do
|
21
|
+
@segmento_u.lote.should == "3456"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should set #tipo_registro" do
|
25
|
+
@segmento_u.tipo_registro.should == "7"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should set #num_registro" do
|
29
|
+
@segmento_u.num_registro.should == "89012"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should set #segmento" do
|
33
|
+
@segmento_u.segmento.should == "3"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should set #res_cnab1" do
|
37
|
+
@segmento_u.res_cnab1.should == "4"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should set #cod_movimentacao" do
|
41
|
+
@segmento_u.cod_movimentacao.should == "56"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should set #acrescimos" do
|
45
|
+
@segmento_u.acrescimos.should == "789012345678901"
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should set #valor_desconto" do
|
49
|
+
@segmento_u.valor_desconto.should == "234567890123456"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should set #valor_abatimento" do
|
53
|
+
@segmento_u.valor_abatimento.should == "789012345678901"
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should set #valor_iof" do
|
57
|
+
@segmento_u.valor_iof.should == "234567890123456"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should set #valor_pago" do
|
61
|
+
@segmento_u.valor_pago.should == "789012345678901"
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should set #valor_liquido" do
|
65
|
+
@segmento_u.valor_liquido.should == "234567890123456"
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should set #outras_despesas" do
|
69
|
+
@segmento_u.outras_despesas.should == "7890123456789012"
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should set #outros_creditos" do
|
73
|
+
@segmento_u.outros_creditos.should == "34567890123456"
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should set #data_ocorrencia" do
|
77
|
+
@segmento_u.data_ocorrencia.should == "78901234"
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should set #data_credito" do
|
81
|
+
@segmento_u.data_credito.should == "56789012"
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should set #cod_ocorrencia_sacado" do
|
85
|
+
@segmento_u.cod_ocorrencia_sacado.should == "3456"
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should set #data_ocorrencia_sacado" do
|
89
|
+
@segmento_u.data_ocorrencia_sacado.should == "78901234"
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should set #valor_ocorrencia_sacado" do
|
93
|
+
@segmento_u.valor_ocorrencia_sacado.should == "567890123456789"
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should set #compl_ocorrencia_sacado" do
|
97
|
+
@segmento_u.compl_ocorrencia_sacado.should == "012345678901234567890123456789"
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should set #banco_compensacao" do
|
101
|
+
@segmento_u.banco_compensacao.should == "012"
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should set #banco_enviado" do
|
105
|
+
@segmento_u.banco_enviado.should == "34567890123456789012"
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should set #res_cnab2" do
|
109
|
+
@segmento_u.res_cnab2.should == "3456789"
|
110
|
+
end
|
103
111
|
end
|
104
112
|
end
|
105
113
|
end
|