cpf_cnpj 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe CNPJ::Formatter do
4
- it "formats strings without separators" do
5
- number = "12345678901234"
6
- expect(CNPJ::Formatter.format(number)).to eql("12.345.678/9012-34")
7
- end
8
-
9
- it "removes any non-numeric characters" do
10
- number = "\n12$345[678/9012-34"
11
- expect(CNPJ::Formatter.strip(number)).to eql("12345678901234")
12
- end
13
- end
@@ -1,15 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe CNPJ::Generator do
4
- it "generates valid numbers" do
5
- expect(CNPJ).to be_valid(CNPJ::Generator.generate)
6
- expect(CNPJ).to be_valid(CNPJ::Generator.generate)
7
- expect(CNPJ).to be_valid(CNPJ::Generator.generate)
8
- expect(CNPJ).to be_valid(CNPJ::Generator.generate)
9
- expect(CNPJ).to be_valid(CNPJ::Generator.generate)
10
- end
11
-
12
- it "generates random numbers" do
13
- expect(CNPJ::Generator.generate).not_to eql(CNPJ::Generator.generate)
14
- end
15
- end
@@ -1,46 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe CNPJ do
4
- it "blacklists common numbers" do
5
- expect(CNPJ).not_to be_valid("11111111111111")
6
- expect(CNPJ).not_to be_valid("22222222222222")
7
- expect(CNPJ).not_to be_valid("33333333333333")
8
- expect(CNPJ).not_to be_valid("44444444444444")
9
- expect(CNPJ).not_to be_valid("55555555555555")
10
- expect(CNPJ).not_to be_valid("66666666666666")
11
- expect(CNPJ).not_to be_valid("77777777777777")
12
- expect(CNPJ).not_to be_valid("88888888888888")
13
- expect(CNPJ).not_to be_valid("99999999999999")
14
- end
15
-
16
- it "rejects blank strings" do
17
- expect(CNPJ).not_to be_valid("")
18
- end
19
-
20
- it "rejects nil values" do
21
- expect(CNPJ).not_to be_valid(nil)
22
- end
23
-
24
- it "validates formatted strings" do
25
- number = "54.550.752/0001-55"
26
- expect(CNPJ).to be_valid(number)
27
- end
28
-
29
- it "validates unformatted strings" do
30
- number = "54550752000155"
31
- expect(CNPJ).to be_valid(number)
32
- end
33
-
34
- it "validates messed strings" do
35
- number = "54550[752#0001..$55"
36
- expect(CNPJ).to be_valid(number)
37
- end
38
-
39
- it "generates formatted number" do
40
- expect(CNPJ.generate(true)).to match(%r[\A\d{2}\.\d{3}\.\d{3}/\d{4}-\d{2}\z])
41
- end
42
-
43
- it "generates stripped number" do
44
- expect(CNPJ.generate).to match(/\A\d{14}\z/)
45
- end
46
- end
@@ -1,119 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe CPF::CLI do
4
- let(:stdout) { "" }
5
- let(:stderr) { "" }
6
- let(:stdin) { StringIO.new }
7
-
8
- context "check" do
9
- %w[-c --check].each do |switch|
10
- it "checks if provided number is valid [using #{switch}]" do
11
- capture_exit do
12
- CPF::CLI.new([switch, "77673736578"], stdin, stdout, stderr).start
13
- end
14
-
15
- expect(stdout).to eql("")
16
- end
17
-
18
- it "outputs error message if provided number is invalid [using #{switch}]" do
19
- capture_exit(1) do
20
- CPF::CLI.new([switch, "invalid"], stdin, stdout, stderr).start
21
- end
22
-
23
- expect(stderr).to include("Error: Invalid number")
24
- end
25
- end
26
- end
27
-
28
- context "help" do
29
- %w[-h --help].each do |switch|
30
- it "outputs help [using #{switch}]" do
31
- capture_exit(1) do
32
- CPF::CLI.new([switch], stdin, stdout, stderr).start
33
- end
34
-
35
- expect(stderr).to include("Usage: cpf")
36
- end
37
- end
38
-
39
- it "outputs help on tail" do
40
- capture_exit(1) do
41
- CPF::CLI.new([], stdin, stdout, stderr).start
42
- end
43
-
44
- expect(stderr).to include("Usage: cpf")
45
- end
46
- end
47
-
48
- context "version" do
49
- %w[-v --version].each do |switch|
50
- it "outputs version [using #{switch}]" do
51
- capture_exit do
52
- CPF::CLI.new([switch], stdin, stdout, stderr).start
53
- end
54
-
55
- expect(stdout).to include(CPF::VERSION.to_s)
56
- end
57
- end
58
- end
59
-
60
- context "generate" do
61
- %w[-g --generate].each do |switch|
62
- it "generates number [using -#{switch}]" do
63
- capture_exit do
64
- CPF::CLI.new([switch], stdin, stdout, stderr).start
65
- end
66
-
67
- expect(stdout).to match(CPF::REGEX)
68
- end
69
- end
70
-
71
- it "generates stripped number" do
72
- capture_exit do
73
- CPF::CLI.new(["-gs"], stdin, stdout, stderr).start
74
- end
75
-
76
- expect(stdout).to match(/\A\d{11}\Z/)
77
- end
78
- end
79
-
80
- context "format" do
81
- %w[-f --format].each do |switch|
82
- it "formats argument [using #{switch}]" do
83
- capture_exit do
84
- CPF::CLI.new([switch, "77673736578"], stdin, stdout, stderr).start
85
- end
86
-
87
- expect(stdout).to include("776.737.365-78")
88
- end
89
- end
90
-
91
- it "formats argument using stdin" do
92
- stdin = StringIO.new("77673736578")
93
-
94
- capture_exit do
95
- CPF::CLI.new(["--format"], stdin, stdout, stderr).start
96
- end
97
-
98
- expect(stdout).to include("776.737.365-78")
99
- end
100
-
101
- let(:switch) { "--format" }
102
- it_behaves_like "validation"
103
- end
104
-
105
- context "strip" do
106
- %w[-s --strip].each do |switch|
107
- it "strips argument [using #{switch}]" do
108
- capture_exit do
109
- CPF::CLI.new([switch, "776.737.365-78"], stdin, stdout, stderr).start
110
- end
111
-
112
- expect(stdout).to include("77673736578")
113
- end
114
- end
115
-
116
- let(:switch) { "--strip" }
117
- it_behaves_like "validation"
118
- end
119
- end
@@ -1,13 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe CPF::Formatter do
4
- it "formats strings without separators" do
5
- number = "12345678909"
6
- expect(CPF::Formatter.format(number)).to eql("123.456.789-09")
7
- end
8
-
9
- it "removes any non-numeric characters" do
10
- number = "\n12.-34567$8909"
11
- expect(CPF::Formatter.strip(number)).to eql("12345678909")
12
- end
13
- end
@@ -1,15 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe CPF::Generator do
4
- it "generates valid numbers" do
5
- expect(CPF).to be_valid(CPF::Generator.generate)
6
- expect(CPF).to be_valid(CPF::Generator.generate)
7
- expect(CPF).to be_valid(CPF::Generator.generate)
8
- expect(CPF).to be_valid(CPF::Generator.generate)
9
- expect(CPF).to be_valid(CPF::Generator.generate)
10
- end
11
-
12
- it "generates random numbers" do
13
- expect(CPF::Generator.generate).not_to eql(CPF::Generator.generate)
14
- end
15
- end
@@ -1,73 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe CPF do
4
- it "blacklists common numbers" do
5
- expect(CPF).not_to be_valid("11111111111")
6
- expect(CPF).not_to be_valid("22222222222")
7
- expect(CPF).not_to be_valid("33333333333")
8
- expect(CPF).not_to be_valid("44444444444")
9
- expect(CPF).not_to be_valid("55555555555")
10
- expect(CPF).not_to be_valid("66666666666")
11
- expect(CPF).not_to be_valid("77777777777")
12
- expect(CPF).not_to be_valid("88888888888")
13
- expect(CPF).not_to be_valid("99999999999")
14
- expect(CPF).not_to be_valid("12345678909")
15
- end
16
-
17
- it "rejects blank strings" do
18
- expect(CPF).not_to be_valid("")
19
- end
20
-
21
- it "rejects nil values" do
22
- expect(CPF).not_to be_valid(nil)
23
- end
24
-
25
- it "validates formatted strings" do
26
- number = "295.379.955-93"
27
- expect(CPF).to be_valid(number)
28
- end
29
-
30
- it "validates unformatted strings" do
31
- number = "29537995593"
32
- expect(CPF).to be_valid(number)
33
- end
34
-
35
- it "validates messed strings" do
36
- number = "295$379\n955...93"
37
- expect(CPF).to be_valid(number)
38
- end
39
-
40
- it "returns stripped number" do
41
- cpf = CPF.new("295.379.955-93")
42
- expect(cpf.stripped).to eql("29537995593")
43
- end
44
-
45
- it "formats number" do
46
- cpf = CPF.new("29537995593")
47
- expect(cpf.formatted).to eql("295.379.955-93")
48
- end
49
-
50
- it "generates formatted number" do
51
- expect(CPF.generate(true)).to match(/\A\d{3}\.\d{3}\.\d{3}-\d{2}\z/)
52
- end
53
-
54
- it "generates stripped number" do
55
- expect(CPF.generate).to match(/\A\d{11}\z/)
56
- end
57
-
58
- context "memoization" do
59
- let(:cpf) { CPF.new("29537995593") }
60
-
61
- before do
62
- cpf.number = "52139989171"
63
- end
64
-
65
- it "invalidates stripped number" do
66
- expect(cpf.stripped).to eql("52139989171")
67
- end
68
-
69
- it "invalidates formatted number" do
70
- expect(cpf.formatted).to eql("521.399.891-71")
71
- end
72
- end
73
- end
@@ -1,6 +0,0 @@
1
- require "bundler"
2
- Bundler.setup
3
- Bundler.require
4
-
5
- require "support/capture_exit"
6
- require "support/validation_shared"
@@ -1,10 +0,0 @@
1
- module CaptureExit
2
- def capture_exit(status = 0, &block)
3
- yield
4
- raise "Expected exit(#{status}); it didn't exit"
5
- rescue SystemExit => error
6
- raise "Expected exit(#{status}); got exit(#{error.status})" unless status == error.status
7
- end
8
- end
9
-
10
- RSpec.configuration.include(CaptureExit)
@@ -1,17 +0,0 @@
1
- shared_examples_for "validation" do
2
- it "fails when providing Invalid number" do
3
- capture_exit(1) do
4
- described_class.new([switch, "invalid"], stdin, stdout, stderr).start
5
- end
6
-
7
- expect(stderr).to include("Error: Invalid number")
8
- end
9
-
10
- it "fails when not providing a number" do
11
- capture_exit(1) do
12
- described_class.new([switch], stdin, stdout, stderr).start
13
- end
14
-
15
- expect(stderr).to include("Error: Invalid number")
16
- end
17
- end