|
5 | 5 | describe Wpxf::Utility::Text do |
6 | 6 | describe '.alpha_ranges' do |
7 | 7 | it 'returns an array containing the a-z range when using :lower' do |
8 | | - expect(Wpxf::Utility::Text.alpha_ranges(:lower)).to eq [*'a'..'z'] |
| 8 | + expect(described_class.alpha_ranges(:lower)).to eq [*'a'..'z'] |
9 | 9 | end |
10 | 10 |
|
11 | 11 | it 'returns an array containing the A-Z range when using :upper' do |
12 | | - expect(Wpxf::Utility::Text.alpha_ranges(:upper)).to eq [*'A'..'Z'] |
| 12 | + expect(described_class.alpha_ranges(:upper)).to eq [*'A'..'Z'] |
13 | 13 | end |
14 | 14 |
|
15 | 15 | it 'returns an array containing the A-Z and a-z range when using :mixed' do |
16 | 16 | range = [*'A'..'Z', *'a'..'z'] |
17 | | - expect(Wpxf::Utility::Text.alpha_ranges(:mixed)).to eq range |
| 17 | + expect(described_class.alpha_ranges(:mixed)).to eq range |
18 | 18 | end |
19 | 19 | end |
20 | 20 |
|
21 | 21 | describe '.rand_alpha' do |
22 | 22 | it 'returns a string of the specified length' do |
23 | | - val = Wpxf::Utility::Text.rand_alpha(10) |
| 23 | + val = described_class.rand_alpha(10) |
24 | 24 | expect(val.length).to eq 10 |
25 | 25 | end |
26 | 26 |
|
27 | 27 | it 'returns a lower case string when :lower is specified as the casing' do |
28 | | - val = Wpxf::Utility::Text.rand_alpha(10, :lower) |
| 28 | + val = described_class.rand_alpha(10, :lower) |
29 | 29 | expect(val).to match(/^[a-z]{10}$/) |
30 | 30 | end |
31 | 31 |
|
32 | 32 | it 'returns an upper case string when :upper is specified as the casing' do |
33 | | - val = Wpxf::Utility::Text.rand_alpha(10, :upper) |
| 33 | + val = described_class.rand_alpha(10, :upper) |
34 | 34 | expect(val).to match(/^[A-Z]{10}$/) |
35 | 35 | end |
36 | 36 |
|
37 | 37 | it 'returns a mixed case string when :mixed is specified as the casing' do |
38 | | - val = Wpxf::Utility::Text.rand_alpha(10, :mixed) |
| 38 | + val = described_class.rand_alpha(10, :mixed) |
39 | 39 | expect(val).to match(/^[a-zA-Z]{10}$/) |
40 | 40 | end |
41 | 41 |
|
42 | 42 | it 'returns a mixed case string when no casing arg is specified' do |
43 | | - val = Wpxf::Utility::Text.rand_alpha(10) |
| 43 | + val = described_class.rand_alpha(10) |
44 | 44 | expect(val).to match(/^[a-zA-Z]{10}$/) |
45 | 45 | end |
46 | 46 | end |
47 | 47 |
|
48 | 48 | describe '.rand_alphanumeric' do |
49 | 49 | it 'returns a string of the specified length' do |
50 | | - val = Wpxf::Utility::Text.rand_alphanumeric(10) |
| 50 | + val = described_class.rand_alphanumeric(10) |
51 | 51 | expect(val.length).to eq 10 |
52 | 52 | end |
53 | 53 |
|
54 | 54 | it 'returns a lower case string when :lower is specified as the casing' do |
55 | | - val = Wpxf::Utility::Text.rand_alphanumeric(10, :lower) |
| 55 | + val = described_class.rand_alphanumeric(10, :lower) |
56 | 56 | expect(val).to match(/^[a-z0-9]{10}$/) |
57 | 57 | end |
58 | 58 |
|
59 | 59 | it 'returns an upper case string when :upper is specified as the casing' do |
60 | | - val = Wpxf::Utility::Text.rand_alphanumeric(10, :upper) |
| 60 | + val = described_class.rand_alphanumeric(10, :upper) |
61 | 61 | expect(val).to match(/^[A-Z0-9]{10}$/) |
62 | 62 | end |
63 | 63 |
|
64 | 64 | it 'returns a mixed case string when :mixed is specified as the casing' do |
65 | | - val = Wpxf::Utility::Text.rand_alphanumeric(10, :mixed) |
| 65 | + val = described_class.rand_alphanumeric(10, :mixed) |
66 | 66 | expect(val).to match(/^[a-zA-Z0-9]{10}$/) |
67 | 67 | end |
68 | 68 |
|
69 | 69 | it 'returns a mixed case string when no casing arg is specified' do |
70 | | - val = Wpxf::Utility::Text.rand_alphanumeric(10) |
| 70 | + val = described_class.rand_alphanumeric(10) |
71 | 71 | expect(val).to match(/^[a-zA-Z0-9]{10}$/) |
72 | 72 | end |
73 | 73 | end |
74 | 74 |
|
75 | 75 | describe '.rand_numeric' do |
76 | 76 | it 'returns a string of the specified length' do |
77 | | - val = Wpxf::Utility::Text.rand_numeric(10) |
| 77 | + val = described_class.rand_numeric(10) |
78 | 78 | expect(val.length).to eq 10 |
79 | 79 | end |
80 | 80 |
|
81 | 81 | it 'returns a numeric string' do |
82 | | - val = Wpxf::Utility::Text.rand_numeric(10) |
| 82 | + val = described_class.rand_numeric(10) |
83 | 83 | expect(val).to match(/^[0-9]{10}$/) |
84 | 84 | end |
85 | 85 |
|
86 | 86 | context 'when allow_leading_zero is set to false' do |
87 | 87 | it 'returns a value that does not start with zero' do |
88 | 88 | 1000.times do |
89 | | - val = Wpxf::Utility::Text.rand_numeric(3, false) |
| 89 | + val = described_class.rand_numeric(3, false) |
90 | 90 | expect(val[0]).to_not eq '0' |
91 | 91 | end |
92 | 92 | end |
|
95 | 95 |
|
96 | 96 | describe '.md5' do |
97 | 97 | it 'returns a hexadecimal representation of the md5 digest' do |
98 | | - hash = Wpxf::Utility::Text.md5('test') |
| 98 | + hash = described_class.md5('test') |
99 | 99 | expect(hash).to match(/^[a-f0-9]{32}$/i) |
100 | 100 | end |
101 | 101 |
|
102 | 102 | it 'returns an md5 hash' do |
103 | | - hash = Wpxf::Utility::Text.md5('test') |
| 103 | + hash = described_class.md5('test') |
104 | 104 | expect(hash).to eq '098f6bcd4621d373cade4e832627b4f6' |
105 | 105 | end |
106 | 106 | end |
107 | 107 |
|
108 | 108 | describe '.rand_email' do |
109 | 109 | it 'returns an address for a .com domain' do |
110 | | - email = Wpxf::Utility::Text.rand_email |
| 110 | + email = described_class.rand_email |
111 | 111 | expect(email).to match(/^[a-zA-Z0-9]+@[a-zA-Z0-9]+\.com$/) |
112 | 112 | end |
113 | 113 | end |
| 114 | + |
| 115 | + describe '.hexify_string' do |
| 116 | + it 'returns a hexadecimal representation of the string' do |
| 117 | + hex_value = described_class.hexify_string('test') |
| 118 | + expect(hex_value).to eq '74657374' |
| 119 | + end |
| 120 | + end |
114 | 121 | end |
0 commit comments