cpf_cnpj 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +3 -0
- data/.github/dependabot.yml +15 -0
- data/.github/workflows/ruby-tests.yml +47 -0
- data/.rubocop.yml +10 -56
- data/README.md +24 -14
- data/Rakefile +4 -1
- data/bin/cnpj +1 -1
- data/bin/cpf +1 -1
- data/cpf_cnpj.gemspec +21 -14
- data/lib/cnpj/formatter.rb +4 -3
- data/lib/cnpj/verifier_digit.rb +1 -1
- data/lib/cnpj.rb +22 -13
- data/lib/cpf/formatter.rb +2 -2
- data/lib/cpf/verifier_digit.rb +1 -1
- data/lib/cpf.rb +22 -14
- data/lib/cpf_cnpj/cli.rb +1 -2
- data/lib/cpf_cnpj/generator.rb +2 -2
- data/lib/cpf_cnpj/version.rb +1 -1
- data/test/cnpj/cli_test.rb +112 -0
- data/test/{unit/cnpj → cnpj}/formatter_test.rb +2 -0
- data/test/{unit/cnpj_test.rb → cnpj_test.rb} +21 -2
- data/test/cpf/cli_test.rb +112 -0
- data/test/{unit/cpf → cpf}/formatter_test.rb +6 -4
- data/test/{unit/cpf_test.rb → cpf_test.rb} +15 -2
- data/test/support/run_command.rb +30 -0
- data/test/test_helper.rb +1 -1
- metadata +54 -32
- data/.travis.yml +0 -8
- data/test/support/capture_syscall.rb +0 -18
- data/test/unit/cnpj/cli_test.rb +0 -134
- data/test/unit/cpf/cli_test.rb +0 -134
- /data/test/{unit/cnpj → cnpj}/generator_test.rb +0 -0
- /data/test/{unit/cpf → cpf}/generator_test.rb +0 -0
data/test/unit/cpf/cli_test.rb
DELETED
@@ -1,134 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "test_helper"
|
4
|
-
|
5
|
-
module CPFCli
|
6
|
-
class CheckTest < Minitest::Test
|
7
|
-
include CaptureSyscall
|
8
|
-
|
9
|
-
%w[-c --check].each do |switch|
|
10
|
-
test "checks if provided number is valid [using #{switch}]" do
|
11
|
-
exit_status, stdout = capture_syscall do
|
12
|
-
system "./bin/cpf #{switch} 76616598837"
|
13
|
-
end
|
14
|
-
|
15
|
-
assert_equal 0, exit_status
|
16
|
-
assert_equal stdout, ""
|
17
|
-
end
|
18
|
-
|
19
|
-
test "outputs error message if provided number is invalid [using #{switch}]" do
|
20
|
-
exit_status, _, stderr = capture_syscall do
|
21
|
-
system "./bin/cpf #{switch} invalid"
|
22
|
-
end
|
23
|
-
|
24
|
-
assert_equal 1, exit_status
|
25
|
-
assert stderr.include?("Error: Invalid number")
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
class HelpTest < Minitest::Test
|
31
|
-
include CaptureSyscall
|
32
|
-
|
33
|
-
%w[-h --help].each do |switch|
|
34
|
-
test "outputs help [using #{switch}]" do
|
35
|
-
exit_status, _, stderr = capture_syscall do
|
36
|
-
system "./bin/cpf #{switch}"
|
37
|
-
end
|
38
|
-
|
39
|
-
assert_equal 1, exit_status
|
40
|
-
assert stderr.include?("Usage: cpf")
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
test "outputs help on tail" do
|
45
|
-
exit_status, _, stderr = capture_syscall do
|
46
|
-
system "./bin/cpf"
|
47
|
-
end
|
48
|
-
|
49
|
-
assert_equal 1, exit_status
|
50
|
-
assert stderr.include?("Usage: cpf")
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
class VersionTest < Minitest::Test
|
55
|
-
include CaptureSyscall
|
56
|
-
|
57
|
-
%w[-v --version].each do |switch|
|
58
|
-
test "outputs version [using #{switch}]" do
|
59
|
-
exit_status, stdout, _stderr = capture_syscall do
|
60
|
-
system "./bin/cpf #{switch}"
|
61
|
-
end
|
62
|
-
|
63
|
-
assert_equal 0, exit_status
|
64
|
-
assert stdout.include?(CPF::VERSION.to_s)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
class GenerateTest < Minitest::Test
|
70
|
-
include CaptureSyscall
|
71
|
-
|
72
|
-
%w[-g --generate].each do |switch|
|
73
|
-
test "generates number [using #{switch}]" do
|
74
|
-
exit_status, stdout = capture_syscall do
|
75
|
-
system "./bin/cpf #{switch}"
|
76
|
-
end
|
77
|
-
|
78
|
-
assert_equal 0, exit_status
|
79
|
-
assert_match CPF::REGEX, stdout
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
test "generates stripped number" do
|
84
|
-
exit_status, stdout = capture_syscall do
|
85
|
-
system "./bin/cpf -gs"
|
86
|
-
end
|
87
|
-
|
88
|
-
assert_equal 0, exit_status
|
89
|
-
assert_match(/\A\d{11}\Z/, stdout)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
class FormatTest < Minitest::Test
|
94
|
-
include CaptureSyscall
|
95
|
-
|
96
|
-
%w[-f --format].each do |switch|
|
97
|
-
test "formats argument [using #{switch}]" do
|
98
|
-
exit_status, stdout = capture_syscall do
|
99
|
-
system "./bin/cpf #{switch} 76616598837"
|
100
|
-
end
|
101
|
-
|
102
|
-
assert_equal 0, exit_status
|
103
|
-
assert stdout.include?("766.165.988-37")
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
test "formats argument using stdin" do
|
108
|
-
exit_status, stdout = capture_syscall do
|
109
|
-
system "echo 76616598837 | ./bin/cpf --format"
|
110
|
-
end
|
111
|
-
|
112
|
-
assert_equal 0, exit_status
|
113
|
-
assert stdout.include?("766.165.988-37")
|
114
|
-
end
|
115
|
-
|
116
|
-
test "fails when providing invalid number" do
|
117
|
-
exit_status, _, stderr = capture_syscall do
|
118
|
-
system "./bin/cpf --format invalid"
|
119
|
-
end
|
120
|
-
|
121
|
-
assert_equal 1, exit_status
|
122
|
-
assert stderr.include?("Error: Invalid number")
|
123
|
-
end
|
124
|
-
|
125
|
-
test "fails when not providing a number" do
|
126
|
-
exit_status, _, stderr = capture_syscall do
|
127
|
-
system "./bin/cpf --format"
|
128
|
-
end
|
129
|
-
|
130
|
-
assert_equal 1, exit_status
|
131
|
-
assert stderr.include?("Error: Invalid number")
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
File without changes
|
File without changes
|