br_documents 0.0.15 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/config.yml +54 -0
- data/.gitignore +1 -1
- data/.rubocop.yml +65 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +100 -0
- data/README.md +58 -1
- data/Rakefile +3 -3
- data/br_documents.gemspec +23 -19
- data/lib/br_documents.rb +3 -3
- data/lib/br_documents/cnpj_cpf/cnpj.rb +2 -2
- data/lib/br_documents/cnpj_cpf/cpf.rb +2 -2
- data/lib/br_documents/cnpj_cpf/document.rb +9 -9
- data/lib/br_documents/cnpj_validator.rb +4 -4
- data/lib/br_documents/commons/mod11.rb +1 -2
- data/lib/br_documents/commons/mod14.rb +20 -0
- data/lib/br_documents/cpf_validator.rb +4 -4
- data/lib/br_documents/gtin/gtin.rb +28 -0
- data/lib/br_documents/gtin_validator.rb +8 -0
- data/lib/br_documents/ie/ac.rb +3 -2
- data/lib/br_documents/ie/al.rb +2 -1
- data/lib/br_documents/ie/am.rb +3 -2
- data/lib/br_documents/ie/ap.rb +20 -16
- data/lib/br_documents/ie/ba.rb +28 -25
- data/lib/br_documents/ie/base.rb +1 -1
- data/lib/br_documents/ie/ce.rb +3 -2
- data/lib/br_documents/ie/df.rb +3 -2
- data/lib/br_documents/ie/es.rb +2 -1
- data/lib/br_documents/ie/factory.rb +3 -3
- data/lib/br_documents/ie/go.rb +3 -2
- data/lib/br_documents/ie/ma.rb +2 -1
- data/lib/br_documents/ie/mg.rb +14 -17
- data/lib/br_documents/ie/ms.rb +2 -1
- data/lib/br_documents/ie/mt.rb +6 -5
- data/lib/br_documents/ie/pa.rb +3 -2
- data/lib/br_documents/ie/pattern1.rb +10 -7
- data/lib/br_documents/ie/pattern2.rb +9 -8
- data/lib/br_documents/ie/pb.rb +3 -2
- data/lib/br_documents/ie/pe.rb +10 -10
- data/lib/br_documents/ie/pi.rb +2 -1
- data/lib/br_documents/ie/pr.rb +3 -2
- data/lib/br_documents/ie/rj.rb +3 -2
- data/lib/br_documents/ie/rn.rb +19 -16
- data/lib/br_documents/ie/ro.rb +17 -14
- data/lib/br_documents/ie/rr.rb +4 -3
- data/lib/br_documents/ie/rs.rb +3 -2
- data/lib/br_documents/ie/sc.rb +3 -2
- data/lib/br_documents/ie/se.rb +3 -2
- data/lib/br_documents/ie/sp.rb +17 -14
- data/lib/br_documents/ie/to.rb +6 -5
- data/lib/br_documents/ie_validator.rb +16 -15
- data/lib/br_documents/suframa/suframa.rb +60 -0
- data/lib/br_documents/suframa_validator.rb +8 -0
- data/lib/br_documents/version.rb +1 -1
- data/spec/cnpj_cpf/cnpj_spec.rb +21 -21
- data/spec/cnpj_cpf/cpf_spec.rb +21 -21
- data/spec/cnpj_validator_spec.rb +12 -12
- data/spec/cpf_validator_spec.rb +12 -12
- data/spec/gtin/gtin_spec.rb +49 -0
- data/spec/gtin_validator_spec.rb +47 -0
- data/spec/ie/ac_spec.rb +16 -16
- data/spec/ie/al_spec.rb +14 -14
- data/spec/ie/am_spec.rb +16 -16
- data/spec/ie/ap_spec.rb +14 -14
- data/spec/ie/ba_spec.rb +28 -28
- data/spec/ie/ce_spec.rb +9 -9
- data/spec/ie/df_spec.rb +16 -16
- data/spec/ie/es_spec.rb +9 -9
- data/spec/ie/factory_spec.rb +88 -89
- data/spec/ie/go_spec.rb +16 -16
- data/spec/ie/ma_spec.rb +9 -9
- data/spec/ie/mg_spec.rb +16 -16
- data/spec/ie/ms_spec.rb +9 -9
- data/spec/ie/mt_spec.rb +17 -17
- data/spec/ie/pa_spec.rb +16 -16
- data/spec/ie/pb_spec.rb +9 -9
- data/spec/ie/pe_spec.rb +27 -27
- data/spec/ie/pi_spec.rb +9 -9
- data/spec/ie/pr_spec.rb +14 -14
- data/spec/ie/rj_spec.rb +16 -16
- data/spec/ie/rn_spec.rb +27 -27
- data/spec/ie/ro_spec.rb +27 -27
- data/spec/ie/rr_spec.rb +16 -16
- data/spec/ie/rs_spec.rb +16 -16
- data/spec/ie/sc_spec.rb +16 -16
- data/spec/ie/se_spec.rb +9 -9
- data/spec/ie/shared_examples_for_pattern1.rb +11 -11
- data/spec/ie/shared_examples_for_to_remove_all_masks.rb +7 -8
- data/spec/ie/sp_spec.rb +19 -19
- data/spec/ie/to_spec.rb +35 -35
- data/spec/ie_validator_spec.rb +43 -31
- data/spec/spec_helper.rb +9 -6
- data/spec/suframa/suframa_spec.rb +109 -0
- data/spec/suframa_validator_spec.rb +36 -0
- data/spec/support/utilities.rb +2 -2
- metadata +94 -25
- data/.travis.yml +0 -6
- data/circle.yml +0 -3
data/spec/ie/ce_spec.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
require
|
2
|
-
require_relative
|
3
|
-
require_relative
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative 'shared_examples_for_pattern1'
|
3
|
+
require_relative 'shared_examples_for_to_remove_all_masks'
|
4
4
|
|
5
5
|
describe BrDocuments::IE::CE do
|
6
|
-
describe
|
7
|
-
it
|
8
|
-
ie = described_class.new(
|
9
|
-
expect(ie.formatted).to eq
|
6
|
+
describe '#formatted' do
|
7
|
+
it 'returns a formatted ie' do
|
8
|
+
ie = described_class.new('123456789')
|
9
|
+
expect(ie.formatted).to eq '12345678-9'
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
it_behaves_like
|
13
|
+
it_behaves_like 'a pattern1', 'CE'
|
14
14
|
|
15
|
-
include_examples
|
15
|
+
include_examples 'for to remove all masks', '12345678-9'
|
16
16
|
end
|
data/spec/ie/df_spec.rb
CHANGED
@@ -1,43 +1,43 @@
|
|
1
|
-
require
|
2
|
-
require_relative
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative 'shared_examples_for_to_remove_all_masks'
|
3
3
|
|
4
4
|
describe BrDocuments::IE::DF do
|
5
|
-
describe
|
6
|
-
it
|
7
|
-
ie = described_class.new(
|
8
|
-
expect(ie.formatted).to eq
|
5
|
+
describe '#formatted' do
|
6
|
+
it 'returns a formatted ie' do
|
7
|
+
ie = described_class.new('1234567890123')
|
8
|
+
expect(ie.formatted).to eq '12345678901-23'
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
describe
|
13
|
-
it
|
14
|
-
[
|
12
|
+
describe '#valid?' do
|
13
|
+
it 'is invalid with malformed number' do
|
14
|
+
['070648022871-3', '07.064.802.287-13', '0AB49871799-12'].each do |number|
|
15
15
|
ie = described_class.new(number)
|
16
16
|
expect(ie).to_not be_valid
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
21
|
-
[
|
20
|
+
it 'is invalid with length different to 13' do
|
21
|
+
['1234567890', '123456789012345'].each do |number|
|
22
22
|
ie = described_class.new(number)
|
23
23
|
expect(ie).to_not be_valid
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
28
|
-
[
|
27
|
+
it 'is invalid with invalid check number' do
|
28
|
+
['0733002219945', '0733002219943'].each do |number|
|
29
29
|
ie = described_class.new(number)
|
30
30
|
expect(ie).to_not be_valid
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
it
|
35
|
-
[
|
34
|
+
it 'is valid with valid number' do
|
35
|
+
['0746069399231', '0784748156211'].each do |number|
|
36
36
|
ie = described_class.new(number)
|
37
37
|
expect(ie).to be_valid
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
include_examples
|
41
|
+
include_examples 'for to remove all masks', '07847481562-11'
|
42
42
|
end
|
43
43
|
end
|
data/spec/ie/es_spec.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
require
|
2
|
-
require_relative
|
3
|
-
require_relative
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative 'shared_examples_for_pattern1'
|
3
|
+
require_relative 'shared_examples_for_to_remove_all_masks'
|
4
4
|
|
5
5
|
describe BrDocuments::IE::ES do
|
6
|
-
describe
|
7
|
-
it
|
8
|
-
ie = described_class.new(
|
9
|
-
expect(ie.formatted).to eq
|
6
|
+
describe '#formatted' do
|
7
|
+
it 'returns a formatted ie' do
|
8
|
+
ie = described_class.new('123456789')
|
9
|
+
expect(ie.formatted).to eq '123456789'
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
it_behaves_like
|
13
|
+
it_behaves_like 'a pattern1', 'ES'
|
14
14
|
|
15
|
-
include_examples
|
15
|
+
include_examples 'for to remove all masks', '12345678-9'
|
16
16
|
end
|
data/spec/ie/factory_spec.rb
CHANGED
@@ -1,202 +1,201 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe BrDocuments::IE::Factory do
|
4
|
-
describe
|
5
|
-
context
|
6
|
-
it
|
7
|
-
ie = BrDocuments::IE::Factory.create(
|
4
|
+
describe '.create' do
|
5
|
+
context 'when uf is AC' do
|
6
|
+
it 'returns an instance of BrDocuments::IE::AC' do
|
7
|
+
ie = BrDocuments::IE::Factory.create('AC', '123456789')
|
8
8
|
expect(ie).to be_an_instance_of BrDocuments::IE::AC
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
context
|
13
|
-
it
|
14
|
-
ie = BrDocuments::IE::Factory.create(
|
12
|
+
context 'when uf is AL' do
|
13
|
+
it 'returns an instance of BrDocuments::IE::AL' do
|
14
|
+
ie = BrDocuments::IE::Factory.create('AL', '123456789')
|
15
15
|
expect(ie).to be_an_instance_of BrDocuments::IE::AL
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
context
|
20
|
-
it
|
21
|
-
ie = BrDocuments::IE::Factory.create(
|
19
|
+
context 'when uf is AP' do
|
20
|
+
it 'returns an instance of BrDocuments::IE::AP' do
|
21
|
+
ie = BrDocuments::IE::Factory.create('AP', '123456789')
|
22
22
|
expect(ie).to be_an_instance_of BrDocuments::IE::AP
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
context
|
27
|
-
it
|
28
|
-
ie = BrDocuments::IE::Factory.create(
|
26
|
+
context 'when uf is AM' do
|
27
|
+
it 'returns an instance of BrDocuments::IE::AM' do
|
28
|
+
ie = BrDocuments::IE::Factory.create('AM', '123456789')
|
29
29
|
expect(ie).to be_an_instance_of BrDocuments::IE::AM
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
context
|
34
|
-
it
|
35
|
-
ie = BrDocuments::IE::Factory.create(
|
33
|
+
context 'when uf is BA' do
|
34
|
+
it 'returns an instance of BrDocuments::IE::BA' do
|
35
|
+
ie = BrDocuments::IE::Factory.create('BA', '123456789')
|
36
36
|
expect(ie).to be_an_instance_of BrDocuments::IE::BA
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
context
|
41
|
-
it
|
42
|
-
ie = BrDocuments::IE::Factory.create(
|
40
|
+
context 'when uf is CE' do
|
41
|
+
it 'returns an instance of BrDocuments::IE::CE' do
|
42
|
+
ie = BrDocuments::IE::Factory.create('CE', '123456789')
|
43
43
|
expect(ie).to be_an_instance_of BrDocuments::IE::CE
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
context
|
48
|
-
it
|
49
|
-
ie = BrDocuments::IE::Factory.create(
|
47
|
+
context 'when uf is DF' do
|
48
|
+
it 'returns an instance of BrDocuments::IE::DF' do
|
49
|
+
ie = BrDocuments::IE::Factory.create('DF', '123456789')
|
50
50
|
expect(ie).to be_an_instance_of BrDocuments::IE::DF
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
context
|
55
|
-
it
|
56
|
-
ie = BrDocuments::IE::Factory.create(
|
54
|
+
context 'when uf is ES' do
|
55
|
+
it 'returns an instance of BrDocuments::IE::ES' do
|
56
|
+
ie = BrDocuments::IE::Factory.create('ES', '123456789')
|
57
57
|
expect(ie).to be_an_instance_of BrDocuments::IE::ES
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
context
|
62
|
-
it
|
63
|
-
ie = BrDocuments::IE::Factory.create(
|
61
|
+
context 'when uf is GO' do
|
62
|
+
it 'returns an instance of BrDocuments::IE::GO' do
|
63
|
+
ie = BrDocuments::IE::Factory.create('GO', '123456789')
|
64
64
|
expect(ie).to be_an_instance_of BrDocuments::IE::GO
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
-
context
|
69
|
-
it
|
70
|
-
ie = BrDocuments::IE::Factory.create(
|
68
|
+
context 'when uf is MA' do
|
69
|
+
it 'returns an instance of BrDocuments::IE::MA' do
|
70
|
+
ie = BrDocuments::IE::Factory.create('MA', '123456789')
|
71
71
|
expect(ie).to be_an_instance_of BrDocuments::IE::MA
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
context
|
76
|
-
it
|
77
|
-
ie = BrDocuments::IE::Factory.create(
|
75
|
+
context 'when uf is MG' do
|
76
|
+
it 'returns an instance of BrDocuments::IE::MG' do
|
77
|
+
ie = BrDocuments::IE::Factory.create('MG', '123456789')
|
78
78
|
expect(ie).to be_an_instance_of BrDocuments::IE::MG
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
-
context
|
83
|
-
it
|
84
|
-
ie = BrDocuments::IE::Factory.create(
|
82
|
+
context 'when uf is MS' do
|
83
|
+
it 'returns an instance of BrDocuments::IE::MS' do
|
84
|
+
ie = BrDocuments::IE::Factory.create('MS', '123456789')
|
85
85
|
expect(ie).to be_an_instance_of BrDocuments::IE::MS
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
|
-
context
|
90
|
-
it
|
91
|
-
ie = BrDocuments::IE::Factory.create(
|
89
|
+
context 'when uf is MT' do
|
90
|
+
it 'returns an instance of BrDocuments::IE::MT' do
|
91
|
+
ie = BrDocuments::IE::Factory.create('MT', '123456789')
|
92
92
|
expect(ie).to be_an_instance_of BrDocuments::IE::MT
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
-
context
|
97
|
-
it
|
98
|
-
ie = BrDocuments::IE::Factory.create(
|
96
|
+
context 'when uf is PA' do
|
97
|
+
it 'returns an instance of BrDocuments::IE::PA' do
|
98
|
+
ie = BrDocuments::IE::Factory.create('PA', '123456789')
|
99
99
|
expect(ie).to be_an_instance_of BrDocuments::IE::PA
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
|
-
context
|
104
|
-
it
|
105
|
-
ie = BrDocuments::IE::Factory.create(
|
103
|
+
context 'when uf is PB' do
|
104
|
+
it 'returns an instance of BrDocuments::IE::PB' do
|
105
|
+
ie = BrDocuments::IE::Factory.create('PB', '123456789')
|
106
106
|
expect(ie).to be_an_instance_of BrDocuments::IE::PB
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
110
|
-
context
|
111
|
-
it
|
112
|
-
ie = BrDocuments::IE::Factory.create(
|
110
|
+
context 'when uf is PR' do
|
111
|
+
it 'returns an instance of BrDocuments::IE::PR' do
|
112
|
+
ie = BrDocuments::IE::Factory.create('PR', '123456789')
|
113
113
|
expect(ie).to be_an_instance_of BrDocuments::IE::PR
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
|
-
context
|
118
|
-
it
|
119
|
-
ie = BrDocuments::IE::Factory.create(
|
117
|
+
context 'when uf is PE' do
|
118
|
+
it 'returns an instance of BrDocuments::IE::PE' do
|
119
|
+
ie = BrDocuments::IE::Factory.create('PE', '123456789')
|
120
120
|
expect(ie).to be_an_instance_of BrDocuments::IE::PE
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
|
-
context
|
125
|
-
it
|
126
|
-
ie = BrDocuments::IE::Factory.create(
|
124
|
+
context 'when uf is PI' do
|
125
|
+
it 'returns an instance of BrDocuments::IE::PI' do
|
126
|
+
ie = BrDocuments::IE::Factory.create('PI', '123456789')
|
127
127
|
expect(ie).to be_an_instance_of BrDocuments::IE::PI
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
|
-
context
|
132
|
-
it
|
133
|
-
ie = BrDocuments::IE::Factory.create(
|
131
|
+
context 'when uf is RJ' do
|
132
|
+
it 'returns an instance of BrDocuments::IE::RJ' do
|
133
|
+
ie = BrDocuments::IE::Factory.create('RJ', '123456789')
|
134
134
|
expect(ie).to be_an_instance_of BrDocuments::IE::RJ
|
135
135
|
end
|
136
136
|
end
|
137
137
|
|
138
|
-
context
|
139
|
-
it
|
140
|
-
ie = BrDocuments::IE::Factory.create(
|
138
|
+
context 'when uf is returns' do
|
139
|
+
it 'returns an instance of BrDocuments::IE::RN' do
|
140
|
+
ie = BrDocuments::IE::Factory.create('RN', '123456789')
|
141
141
|
expect(ie).to be_an_instance_of BrDocuments::IE::RN
|
142
142
|
end
|
143
143
|
end
|
144
144
|
|
145
|
-
context
|
146
|
-
it
|
147
|
-
ie = BrDocuments::IE::Factory.create(
|
145
|
+
context 'when uf is RS' do
|
146
|
+
it 'returns an instance of BrDocuments::IE::RS' do
|
147
|
+
ie = BrDocuments::IE::Factory.create('RS', '123456789')
|
148
148
|
expect(ie).to be_an_instance_of BrDocuments::IE::RS
|
149
149
|
end
|
150
150
|
end
|
151
151
|
|
152
|
-
context
|
153
|
-
it
|
154
|
-
ie = BrDocuments::IE::Factory.create(
|
152
|
+
context 'when uf is RO' do
|
153
|
+
it 'returns an instance of BrDocuments::IE::RO' do
|
154
|
+
ie = BrDocuments::IE::Factory.create('RO', '123456789')
|
155
155
|
expect(ie).to be_an_instance_of BrDocuments::IE::RO
|
156
156
|
end
|
157
157
|
end
|
158
158
|
|
159
|
-
context
|
160
|
-
it
|
161
|
-
ie = BrDocuments::IE::Factory.create(
|
159
|
+
context 'when uf is RR' do
|
160
|
+
it 'returns an instance of BrDocuments::IE::RR' do
|
161
|
+
ie = BrDocuments::IE::Factory.create('RR', '123456789')
|
162
162
|
expect(ie).to be_an_instance_of BrDocuments::IE::RR
|
163
163
|
end
|
164
164
|
end
|
165
165
|
|
166
|
-
context
|
167
|
-
it
|
168
|
-
ie = BrDocuments::IE::Factory.create(
|
166
|
+
context 'when uf is SC' do
|
167
|
+
it 'returns an instance of BrDocuments::IE::SC' do
|
168
|
+
ie = BrDocuments::IE::Factory.create('SC', '123456789')
|
169
169
|
expect(ie).to be_an_instance_of BrDocuments::IE::SC
|
170
170
|
end
|
171
171
|
end
|
172
172
|
|
173
|
-
context
|
174
|
-
it
|
175
|
-
ie = BrDocuments::IE::Factory.create(
|
173
|
+
context 'when uf is SP' do
|
174
|
+
it 'returns an instance of BrDocuments::IE::SP' do
|
175
|
+
ie = BrDocuments::IE::Factory.create('SP', '123456789')
|
176
176
|
expect(ie).to be_an_instance_of BrDocuments::IE::SP
|
177
177
|
end
|
178
178
|
end
|
179
179
|
|
180
|
-
context
|
181
|
-
it
|
182
|
-
ie = BrDocuments::IE::Factory.create(
|
180
|
+
context 'when uf is SE' do
|
181
|
+
it 'returns an instance of BrDocuments::IE::SE' do
|
182
|
+
ie = BrDocuments::IE::Factory.create('SE', '123456789')
|
183
183
|
expect(ie).to be_an_instance_of BrDocuments::IE::SE
|
184
184
|
end
|
185
185
|
end
|
186
186
|
|
187
|
-
context
|
188
|
-
it
|
189
|
-
ie = BrDocuments::IE::Factory.create(
|
187
|
+
context 'when uf is TO' do
|
188
|
+
it 'returns an instance of BrDocuments::IE::TO' do
|
189
|
+
ie = BrDocuments::IE::Factory.create('TO', '123456789')
|
190
190
|
expect(ie).to be_an_instance_of BrDocuments::IE::TO
|
191
191
|
end
|
192
192
|
end
|
193
193
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
}.to raise_error(ArgumentError, t("validator.ie.uf.invalid"))
|
194
|
+
context 'when uf is invalid' do
|
195
|
+
it 'is returns an error' do
|
196
|
+
expect do
|
197
|
+
BrDocuments::IE::Factory.create('', '')
|
198
|
+
end.to raise_error(ArgumentError, t('validator.ie.uf.invalid'))
|
200
199
|
end
|
201
200
|
end
|
202
201
|
end
|
data/spec/ie/go_spec.rb
CHANGED
@@ -1,43 +1,43 @@
|
|
1
|
-
require
|
2
|
-
require_relative
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative 'shared_examples_for_to_remove_all_masks'
|
3
3
|
|
4
4
|
describe BrDocuments::IE::GO do
|
5
|
-
describe
|
6
|
-
it
|
7
|
-
ie = described_class.new(
|
8
|
-
expect(ie.formatted).to eq
|
5
|
+
describe '#formatted' do
|
6
|
+
it 'returns a formatted ie' do
|
7
|
+
ie = described_class.new('123456789')
|
8
|
+
expect(ie.formatted).to eq '12.345.678-9'
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
describe
|
13
|
-
it
|
14
|
-
[
|
12
|
+
describe '#valid?' do
|
13
|
+
it 'is invalid with malformed number' do
|
14
|
+
['01.390415.9', '280541-600', '1C78150A5'].each do |number|
|
15
15
|
ie = described_class.new(number)
|
16
16
|
expect(ie).to_not be_valid
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
21
|
-
[
|
20
|
+
it 'is invalid with length different to 9' do
|
21
|
+
['1234567', '122345678901'].each do |number|
|
22
22
|
ie = described_class.new(number)
|
23
23
|
expect(ie).to_not be_valid
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
28
|
-
[
|
27
|
+
it 'is invalid with invalid check number' do
|
28
|
+
['903473566', '493184742'].each do |number|
|
29
29
|
ie = described_class.new(number)
|
30
30
|
expect(ie).to_not be_valid
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
it
|
35
|
-
[
|
34
|
+
it 'is valid with valid number' do
|
35
|
+
['155432214', '916876470'].each do |number|
|
36
36
|
ie = described_class.new(number)
|
37
37
|
expect(ie).to be_valid
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
include_examples
|
41
|
+
include_examples 'for to remove all masks', '91.687.647-0'
|
42
42
|
end
|
43
43
|
end
|