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.
@@ -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("1234567890123U").should be_an_instance_of(Cnab::Detalhe::SegmentoU)
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("1234567890123T").should be_an_instance_of(Cnab::Detalhe::SegmentoT)
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("1234567890123V") }.should raise_error(Cnab::Exceptions::SegmentNotImplemented)
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
- describe "#initialize" do
5
- before :each do
6
- @header_arquivo = Cnab::HeaderArquivo.new(LINE)
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
- it "should set #lote" do
14
- @header_arquivo.lote.should == "3456"
15
- end
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
- it "should set #registro" do
18
- @header_arquivo.registro.should == "7"
19
- end
16
+ it "should set #banco" do
17
+ @header_arquivo.banco.should == "012"
18
+ end
20
19
 
21
- it "should set #res_cnab1" do
22
- @header_arquivo.res_cnab1.should == "890123456"
23
- end
24
-
25
- it "should set #tipo_empresa" do
26
- @header_arquivo.tipo_empresa.should == "7"
27
- end
28
-
29
- it "should set #num_empresa" do
30
- @header_arquivo.num_empresa.should == "89012345678901"
31
- end
32
-
33
- it "should set #convenio" do
34
- @header_arquivo.convenio.should == "23456789012345678901"
35
- end
36
-
37
- it "should set #agencia" do
38
- @header_arquivo.agencia.should == "23456"
39
- end
40
-
41
- it "should set #dv_agencia" do
42
- @header_arquivo.dv_agencia.should == "7"
43
- end
44
-
45
- it "should set #conta_corrente" do
46
- @header_arquivo.conta_corrente.should == "890123456789"
47
- end
48
-
49
- it "should set #dv_conta" do
50
- @header_arquivo.dv_conta.should == "0"
51
- end
52
-
53
- it "should set #dv_conta_agencia" do
54
- @header_arquivo.dv_conta_agencia.should == "1"
55
- end
56
-
57
- it "should set #nome_empresa" do
58
- @header_arquivo.nome_empresa.should == "234567890123456789012345678901"
59
- end
60
-
61
- it "should set #nome_banco" do
62
- @header_arquivo.nome_banco.should == "234567890123456789012345678901"
63
- end
64
-
65
- it "should set #res_cnab2" do
66
- @header_arquivo.res_cnab2.should == "2345678901"
67
- end
68
-
69
- it "should set #cod_retorno" do
70
- @header_arquivo.cod_retorno.should == "2"
71
- end
72
-
73
- it "should set #data_geracao_arq" do
74
- @header_arquivo.data_geracao_arq.should == "34567890"
75
- end
76
-
77
- it "should set #hora_geracao_arq" do
78
- @header_arquivo.hora_geracao_arq.should == "123456"
79
- end
80
-
81
- it "should set #sequencia" do
82
- @header_arquivo.sequencia.should == "789012"
83
- end
84
-
85
- it "should set #versao" do
86
- @header_arquivo.versao.should == "345"
87
- end
88
-
89
- it "should set #densidade" do
90
- @header_arquivo.densidade.should == "67890"
91
- end
92
-
93
- it "should set #res_banco" do
94
- @header_arquivo.res_banco.should == "12345678901234567890"
95
- end
96
-
97
- it "should set #res_empresa" do
98
- @header_arquivo.res_empresa.should == "12345678901234567890"
99
- end
100
-
101
- it "should set #res_cnab3" do
102
- @header_arquivo.res_cnab3.should == "12345678901234567890123456789"
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
- before :each do
6
- @cobranca = Cnab::HeaderLote::Cobranca.new(LINE)
7
- end
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
- it "should set #lote" do
14
- @cobranca.lote.should == "3456"
15
- end
11
+ context "with a valid line" do
12
+ before :each do
13
+ @cobranca = Cnab::HeaderLote::Cobranca.new(LINE)
14
+ end
16
15
 
17
- it "should set #registro" do
18
- @cobranca.registro.should == "7"
19
- end
16
+ it "should set #banco" do
17
+ @cobranca.banco.should == "012"
18
+ end
20
19
 
21
- it "should set #tipo_operacao" do
22
- @cobranca.tipo_operacao.should == "8"
23
- end
20
+ it "should set #lote" do
21
+ @cobranca.lote.should == "3456"
22
+ end
24
23
 
25
- it "should set #tipo_servico" do
26
- @cobranca.tipo_servico.should == "90"
27
- end
24
+ it "should set #registro" do
25
+ @cobranca.registro.should == "7"
26
+ end
28
27
 
29
- it "should set #res_cnab1" do
30
- @cobranca.res_cnab1.should == "12"
31
- end
28
+ it "should set #tipo_operacao" do
29
+ @cobranca.tipo_operacao.should == "8"
30
+ end
32
31
 
33
- it "should set #layout_lote" do
34
- @cobranca.layout_lote.should == "345"
35
- end
32
+ it "should set #tipo_servico" do
33
+ @cobranca.tipo_servico.should == "90"
34
+ end
36
35
 
37
- it "should set #res_cnab2" do
38
- @cobranca.res_cnab2.should == "6"
39
- end
36
+ it "should set #res_cnab1" do
37
+ @cobranca.res_cnab1.should == "12"
38
+ end
40
39
 
41
- it "should set #tipo_empresa" do
42
- @cobranca.tipo_empresa.should == "7"
43
- end
40
+ it "should set #layout_lote" do
41
+ @cobranca.layout_lote.should == "345"
42
+ end
44
43
 
45
- it "should set #num_empresa" do
46
- @cobranca.num_empresa.should == "890123456789012"
47
- end
44
+ it "should set #res_cnab2" do
45
+ @cobranca.res_cnab2.should == "6"
46
+ end
48
47
 
49
- it "should set #convenio" do
50
- @cobranca.convenio.should == "34567890123456789012"
51
- end
48
+ it "should set #tipo_empresa" do
49
+ @cobranca.tipo_empresa.should == "7"
50
+ end
52
51
 
53
- it "should set #agencia" do
54
- @cobranca.agencia.should == "34567"
55
- end
52
+ it "should set #num_empresa" do
53
+ @cobranca.num_empresa.should == "890123456789012"
54
+ end
56
55
 
57
- it "should set #dv_agencia" do
58
- @cobranca.dv_agencia.should == "8"
59
- end
56
+ it "should set #convenio" do
57
+ @cobranca.convenio.should == "34567890123456789012"
58
+ end
60
59
 
61
- it "should set #conta_corrente" do
62
- @cobranca.conta_corrente.should == "901234567890"
63
- end
60
+ it "should set #agencia" do
61
+ @cobranca.agencia.should == "34567"
62
+ end
64
63
 
65
- it "should set #dv_conta" do
66
- @cobranca.dv_conta.should == "1"
67
- end
64
+ it "should set #dv_agencia" do
65
+ @cobranca.dv_agencia.should == "8"
66
+ end
68
67
 
69
- it "should set #dv_conta_agencia" do
70
- @cobranca.dv_conta_agencia.should == "2"
71
- end
68
+ it "should set #conta_corrente" do
69
+ @cobranca.conta_corrente.should == "901234567890"
70
+ end
72
71
 
73
- it "should set #nome_empresa" do
74
- @cobranca.nome_empresa.should == "345678901234567890123456789012"
75
- end
72
+ it "should set #dv_conta" do
73
+ @cobranca.dv_conta.should == "1"
74
+ end
76
75
 
77
- it "should set #informacao1" do
78
- @cobranca.informacao1.should == "3456789012345678901234567890123456789012"
79
- end
76
+ it "should set #dv_conta_agencia" do
77
+ @cobranca.dv_conta_agencia.should == "2"
78
+ end
80
79
 
81
- it "should set #informacao2" do
82
- @cobranca.informacao2.should == "3456789012345678901234567890123456789012"
83
- end
80
+ it "should set #nome_empresa" do
81
+ @cobranca.nome_empresa.should == "345678901234567890123456789012"
82
+ end
84
83
 
85
- it "should set #numero_remessa" do
86
- @cobranca.numero_remessa.should == "34567890"
87
- end
84
+ it "should set #informacao1" do
85
+ @cobranca.informacao1.should == "3456789012345678901234567890123456789012"
86
+ end
88
87
 
89
- it "should set #data_gravacao" do
90
- @cobranca.data_gravacao.should == "12345678"
91
- end
88
+ it "should set #informacao2" do
89
+ @cobranca.informacao2.should == "3456789012345678901234567890123456789012"
90
+ end
92
91
 
93
- it "should set #data_credito" do
94
- @cobranca.data_credito.should == "90123456"
95
- end
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
- it "should set #res_cnab3" do
98
- @cobranca.res_cnab3.should == "789012345678901234567890123456789"
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
- before :each do
6
- @trailer_arquivo = Cnab::TrailerArquivo.new(LINE)
7
- end
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
- it "should set #lote" do
14
- @trailer_arquivo.lote.should == "3456"
15
- end
11
+ context "with a valid line" do
12
+ before :each do
13
+ @trailer_arquivo = Cnab::TrailerArquivo.new(LINE)
14
+ end
16
15
 
17
- it "should set #registro" do
18
- @trailer_arquivo.registro.should == "7"
19
- end
16
+ it "should set #banco" do
17
+ @trailer_arquivo.banco.should == "012"
18
+ end
20
19
 
21
- it "should set #res_cnab1" do
22
- @trailer_arquivo.res_cnab1.should == "890123456"
23
- end
20
+ it "should set #lote" do
21
+ @trailer_arquivo.lote.should == "3456"
22
+ end
24
23
 
25
- it "should set #qtd_lotes" do
26
- @trailer_arquivo.qtd_lotes.should == "789012"
27
- end
24
+ it "should set #registro" do
25
+ @trailer_arquivo.registro.should == "7"
26
+ end
28
27
 
29
- it "should set #qtd_registros" do
30
- @trailer_arquivo.qtd_registros.should == "345678"
31
- end
28
+ it "should set #res_cnab1" do
29
+ @trailer_arquivo.res_cnab1.should == "890123456"
30
+ end
32
31
 
33
- it "should set #qtd_contas" do
34
- @trailer_arquivo.qtd_contas.should == "901234"
35
- end
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
- it "should set #res_cnab2" do
38
- @trailer_arquivo.res_cnab2.should == "5678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
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