more_core_extensions 1.2.0 → 2.0.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.
- checksums.yaml +7 -0
- data/.rspec +2 -1
- data/README.md +5 -5
- data/lib/more_core_extensions/core_ext/array/deletes.rb +2 -1
- data/lib/more_core_extensions/core_ext/array/duplicates.rb +1 -1
- data/lib/more_core_extensions/core_ext/array/element_counts.rb +8 -2
- data/lib/more_core_extensions/core_ext/array/inclusions.rb +3 -0
- data/lib/more_core_extensions/core_ext/hash/deletes.rb +1 -0
- data/lib/more_core_extensions/core_ext/object/namespace.rb +1 -9
- data/lib/more_core_extensions/version.rb +1 -1
- data/spec/core_ext/array/deletes_spec.rb +9 -11
- data/spec/core_ext/array/duplicates_spec.rb +4 -6
- data/spec/core_ext/array/element_counts_spec.rb +13 -7
- data/spec/core_ext/array/inclusions_spec.rb +35 -25
- data/spec/core_ext/array/nested_spec.rb +61 -63
- data/spec/core_ext/array/random_spec.rb +8 -10
- data/spec/core_ext/array/stretch_spec.rb +9 -11
- data/spec/core_ext/array/tableize_spec.rb +23 -25
- data/spec/core_ext/hash/deletes_spec.rb +8 -10
- data/spec/core_ext/hash/nested_spec.rb +63 -64
- data/spec/core_ext/object/namespace_spec.rb +4 -20
- data/spec/core_ext/string/formats_spec.rb +46 -48
- data/spec/core_ext/string/hex_dump_spec.rb +12 -14
- data/spec/spec_helper.rb +70 -6
- metadata +22 -44
- data/.gitignore +0 -17
- data/.travis.yml +0 -4
- data/Gemfile +0 -4
- data/Rakefile +0 -6
- data/more_core_extensions.gemspec +0 -27
@@ -1,5 +1,3 @@
|
|
1
|
-
require_relative "../../spec_helper"
|
2
|
-
|
3
1
|
describe Array do
|
4
2
|
context '#tableize' do
|
5
3
|
context "on an Array of Arrays" do
|
@@ -11,7 +9,7 @@ describe Array do
|
|
11
9
|
Val1 | Val2
|
12
10
|
Value3 | Value4
|
13
11
|
EOF
|
14
|
-
test.tableize.
|
12
|
+
expect(test.tableize).to eq(expected)
|
15
13
|
end
|
16
14
|
|
17
15
|
it 'with numeric column values right justified' do
|
@@ -22,7 +20,7 @@ EOF
|
|
22
20
|
Val1 | 200
|
23
21
|
Value3 | 30
|
24
22
|
EOF
|
25
|
-
test.tableize.
|
23
|
+
expect(test.tableize).to eq(expected)
|
26
24
|
end
|
27
25
|
|
28
26
|
it 'with really long column value' do
|
@@ -33,7 +31,7 @@ EOF
|
|
33
31
|
Val1 | Val2
|
34
32
|
Really Really Long Value3 | Value4
|
35
33
|
EOF
|
36
|
-
test.tableize.
|
34
|
+
expect(test.tableize).to eq(expected)
|
37
35
|
end
|
38
36
|
|
39
37
|
it 'with really long column value and :max_width option' do
|
@@ -44,7 +42,7 @@ EOF
|
|
44
42
|
Val1 | Val2
|
45
43
|
Really Rea | Value4
|
46
44
|
EOF
|
47
|
-
test.tableize(:max_width => 10).
|
45
|
+
expect(test.tableize(:max_width => 10)).to eq(expected)
|
48
46
|
end
|
49
47
|
|
50
48
|
it 'with :header => false option' do
|
@@ -54,7 +52,7 @@ EOF
|
|
54
52
|
Val1 | Val2
|
55
53
|
Value3 | Value4
|
56
54
|
EOF
|
57
|
-
test.tableize(:header => false).
|
55
|
+
expect(test.tableize(:header => false)).to eq(expected)
|
58
56
|
end
|
59
57
|
end
|
60
58
|
|
@@ -72,8 +70,8 @@ EOF
|
|
72
70
|
Value4 | Value5 | Value6
|
73
71
|
EOF
|
74
72
|
|
75
|
-
@str_case.tableize.
|
76
|
-
@sym_case.tableize.
|
73
|
+
expect(@str_case.tableize).to eq(expected)
|
74
|
+
expect(@sym_case.tableize).to eq(expected)
|
77
75
|
end
|
78
76
|
|
79
77
|
context "with :columns option" do
|
@@ -87,8 +85,8 @@ EOF
|
|
87
85
|
end
|
88
86
|
|
89
87
|
it "normal case" do
|
90
|
-
@str_case.tableize(:columns => ["Col3", "Col1", "Col2"]).
|
91
|
-
@sym_case.tableize(:columns => [:Col3, :Col1, :Col2 ]).
|
88
|
+
expect(@str_case.tableize(:columns => ["Col3", "Col1", "Col2"])).to eq(@expected)
|
89
|
+
expect(@sym_case.tableize(:columns => [:Col3, :Col1, :Col2 ])).to eq(@expected)
|
92
90
|
end
|
93
91
|
|
94
92
|
it "with only some values" do
|
@@ -99,18 +97,18 @@ EOF
|
|
99
97
|
Value6 | Value4
|
100
98
|
EOF
|
101
99
|
|
102
|
-
@str_case.tableize(:columns => ["Col3", "Col1"]).
|
103
|
-
@sym_case.tableize(:columns => [:Col3, :Col1 ]).
|
100
|
+
expect(@str_case.tableize(:columns => ["Col3", "Col1"])).to eq(expected)
|
101
|
+
expect(@sym_case.tableize(:columns => [:Col3, :Col1 ])).to eq(expected)
|
104
102
|
end
|
105
103
|
|
106
104
|
it "and :leading_columns option" do
|
107
|
-
@str_case.tableize(:columns => ["Col3", "Col1", "Col2"], :leading_columns => ["Col1"]).
|
108
|
-
@sym_case.tableize(:columns => [:Col3, :Col1, :Col2 ], :leading_columns => [:Col1 ]).
|
105
|
+
expect(@str_case.tableize(:columns => ["Col3", "Col1", "Col2"], :leading_columns => ["Col1"])).to eq(@expected)
|
106
|
+
expect(@sym_case.tableize(:columns => [:Col3, :Col1, :Col2 ], :leading_columns => [:Col1 ])).to eq(@expected)
|
109
107
|
end
|
110
108
|
|
111
109
|
it "and :trailing_columns option" do
|
112
|
-
@str_case.tableize(:columns => ["Col3", "Col1", "Col2"], :trailing_columns => ["Col1"]).
|
113
|
-
@sym_case.tableize(:columns => [:Col3, :Col1, :Col2 ], :trailing_columns => [:Col1 ]).
|
110
|
+
expect(@str_case.tableize(:columns => ["Col3", "Col1", "Col2"], :trailing_columns => ["Col1"])).to eq(@expected)
|
111
|
+
expect(@sym_case.tableize(:columns => [:Col3, :Col1, :Col2 ], :trailing_columns => [:Col1 ])).to eq(@expected)
|
114
112
|
end
|
115
113
|
end
|
116
114
|
|
@@ -122,8 +120,8 @@ EOF
|
|
122
120
|
Value6 | Value5 | Value4
|
123
121
|
EOF
|
124
122
|
|
125
|
-
@str_case.tableize(:leading_columns => ["Col3", "Col2"]).
|
126
|
-
@sym_case.tableize(:leading_columns => [:Col3, :Col2 ]).
|
123
|
+
expect(@str_case.tableize(:leading_columns => ["Col3", "Col2"])).to eq(expected)
|
124
|
+
expect(@sym_case.tableize(:leading_columns => [:Col3, :Col2 ])).to eq(expected)
|
127
125
|
end
|
128
126
|
|
129
127
|
it "with :trailing_columns option" do
|
@@ -134,8 +132,8 @@ EOF
|
|
134
132
|
Value4 | Value6 | Value5
|
135
133
|
EOF
|
136
134
|
|
137
|
-
@str_case.tableize(:trailing_columns => ["Col3", "Col2"]).
|
138
|
-
@sym_case.tableize(:trailing_columns => [:Col3, :Col2 ]).
|
135
|
+
expect(@str_case.tableize(:trailing_columns => ["Col3", "Col2"])).to eq(expected)
|
136
|
+
expect(@sym_case.tableize(:trailing_columns => [:Col3, :Col2 ])).to eq(expected)
|
139
137
|
end
|
140
138
|
|
141
139
|
it "with both :leading_columns and :trailing_columns options" do
|
@@ -146,13 +144,13 @@ EOF
|
|
146
144
|
Value6 | Value4 | Value5
|
147
145
|
EOF
|
148
146
|
|
149
|
-
@str_case.tableize(:leading_columns => ["Col3"], :trailing_columns => ["Col2"]).
|
150
|
-
@sym_case.tableize(:leading_columns => [:Col3 ], :trailing_columns => [:Col2 ]).
|
147
|
+
expect(@str_case.tableize(:leading_columns => ["Col3"], :trailing_columns => ["Col2"])).to eq(expected)
|
148
|
+
expect(@sym_case.tableize(:leading_columns => [:Col3 ], :trailing_columns => [:Col2 ])).to eq(expected)
|
151
149
|
end
|
152
150
|
end
|
153
151
|
|
154
152
|
it 'with an invalid receiver' do
|
155
|
-
|
153
|
+
expect { [1, 2, 3].tableize }.to raise_error(RuntimeError)
|
156
154
|
end
|
157
155
|
end
|
158
|
-
end
|
156
|
+
end
|
@@ -1,17 +1,15 @@
|
|
1
|
-
require_relative "../../spec_helper"
|
2
|
-
|
3
1
|
describe Hash do
|
4
2
|
it "#delete_nils" do
|
5
|
-
{}.delete_nils.
|
6
|
-
{:a => 1}.delete_nils.
|
7
|
-
{:c => nil}.delete_nils.
|
8
|
-
{:a => 1, :b => [], :c => nil}.delete_nils.
|
3
|
+
expect({}.delete_nils).to eq({})
|
4
|
+
expect({:a => 1}.delete_nils).to eq({:a => 1})
|
5
|
+
expect({:c => nil}.delete_nils).to eq({})
|
6
|
+
expect({:a => 1, :b => [], :c => nil}.delete_nils).to eq({:a => 1, :b => []})
|
9
7
|
end
|
10
8
|
|
11
9
|
it "#delete_blanks" do
|
12
|
-
{}.delete_blanks.
|
13
|
-
{:a => 1}.delete_blanks.
|
14
|
-
{:c => nil}.delete_blanks.
|
15
|
-
{:a => 1, :b => [], :c => nil}.delete_blanks.
|
10
|
+
expect({}.delete_blanks).to eq({})
|
11
|
+
expect({:a => 1}.delete_blanks).to eq({:a => 1})
|
12
|
+
expect({:c => nil}.delete_blanks).to eq({})
|
13
|
+
expect({:a => 1, :b => [], :c => nil}.delete_blanks).to eq({:a => 1})
|
16
14
|
end
|
17
15
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require_relative "../../spec_helper"
|
2
|
-
|
3
1
|
shared_examples_for "core_ext/hash/nested will not modify arguments" do |meth|
|
4
2
|
it "will not modify arguments" do
|
5
3
|
args = (meth == :store_path ? [1] : [])
|
@@ -7,49 +5,49 @@ shared_examples_for "core_ext/hash/nested will not modify arguments" do |meth|
|
|
7
5
|
key = ["d", "d1", "d2", "d3"]
|
8
6
|
key2 = key.dup
|
9
7
|
hash.send(meth, key2, *args)
|
10
|
-
key2.
|
8
|
+
expect(key2).to eq(key)
|
11
9
|
|
12
10
|
key = ["e", "e1", "e2"]
|
13
11
|
key2 = key.dup
|
14
12
|
hash.send(meth, key2, *args)
|
15
|
-
key2.
|
13
|
+
expect(key2).to eq(key)
|
16
14
|
end
|
17
15
|
end
|
18
16
|
|
19
17
|
shared_examples_for "core_ext/hash/nested" do
|
20
18
|
context '#fetch_path' do
|
21
19
|
it "with various values" do
|
22
|
-
hash.fetch_path("a").
|
23
|
-
hash.fetch_path("b").
|
24
|
-
hash.fetch_path("b", "b1").
|
25
|
-
hash.fetch_path("b", "b1", "b2").
|
26
|
-
hash.fetch_path("c").
|
27
|
-
hash.fetch_path("c", "c1").
|
28
|
-
hash.fetch_path("c", "c1", "c2").
|
29
|
-
hash.fetch_path("d", "d1", "d2", "d3").
|
30
|
-
hash.fetch_path("d", "d1", "d2", "dx").
|
31
|
-
hash.fetch_path("d", "d1", "d2", "d3", "d4").
|
32
|
-
hash.fetch_path("e").
|
33
|
-
hash.fetch_path("e", "e1").
|
34
|
-
hash.fetch_path("e", "e1", "e2").
|
35
|
-
hash.fetch_path("f").
|
36
|
-
hash.fetch_path("f", "f1").
|
37
|
-
hash.fetch_path("f", "f1", "f2").
|
20
|
+
expect(hash.fetch_path("a")).to eq(1)
|
21
|
+
expect(hash.fetch_path("b")).to eq({})
|
22
|
+
expect(hash.fetch_path("b", "b1")).to be_nil
|
23
|
+
expect(hash.fetch_path("b", "b1", "b2")).to be_nil
|
24
|
+
expect(hash.fetch_path("c")).to eq({"c1" => 2})
|
25
|
+
expect(hash.fetch_path("c", "c1")).to eq(2)
|
26
|
+
expect(hash.fetch_path("c", "c1", "c2")).to be_nil
|
27
|
+
expect(hash.fetch_path("d", "d1", "d2", "d3")).to eq(3)
|
28
|
+
expect(hash.fetch_path("d", "d1", "d2", "dx")).to be_nil
|
29
|
+
expect(hash.fetch_path("d", "d1", "d2", "d3", "d4")).to be_nil
|
30
|
+
expect(hash.fetch_path("e")).to eq({})
|
31
|
+
expect(hash.fetch_path("e", "e1")).to eq(4)
|
32
|
+
expect(hash.fetch_path("e", "e1", "e2")).to be_nil
|
33
|
+
expect(hash.fetch_path("f")).to eq({})
|
34
|
+
expect(hash.fetch_path("f", "f1")).to eq({})
|
35
|
+
expect(hash.fetch_path("f", "f1", "f2")).to be_nil
|
38
36
|
end
|
39
37
|
|
40
38
|
it "with a nil value" do
|
41
|
-
hash.fetch_path(nil).
|
42
|
-
hash.fetch_path("d", nil, "d1").
|
43
|
-
hash.fetch_path("e", nil).
|
44
|
-
hash.fetch_path("e", nil, "e1").
|
39
|
+
expect(hash.fetch_path(nil)).to eq({nil => 7})
|
40
|
+
expect(hash.fetch_path("d", nil, "d1")).to be_nil
|
41
|
+
expect(hash.fetch_path("e", nil)).to eq(4)
|
42
|
+
expect(hash.fetch_path("e", nil, "e1")).to be_nil
|
45
43
|
end
|
46
44
|
|
47
45
|
it "with array key" do
|
48
|
-
hash.fetch_path([["h", "i"]]).
|
46
|
+
expect(hash.fetch_path([["h", "i"]])).to eq(8)
|
49
47
|
end
|
50
48
|
|
51
49
|
it "with invalid values" do
|
52
|
-
|
50
|
+
expect { hash.fetch_path }.to raise_error(ArgumentError)
|
53
51
|
end
|
54
52
|
|
55
53
|
include_examples "core_ext/hash/nested will not modify arguments", :fetch_path
|
@@ -59,54 +57,54 @@ shared_examples_for "core_ext/hash/nested" do
|
|
59
57
|
it "on an empty hash" do
|
60
58
|
h = described_class.new
|
61
59
|
h.store_path("a", 1)
|
62
|
-
h.
|
60
|
+
expect(h).to eq({"a" => 1})
|
63
61
|
|
64
62
|
h = described_class.new
|
65
63
|
h.store_path("b", "b1", 2)
|
66
|
-
h.
|
64
|
+
expect(h).to eq({"b" => {"b1" => 2}})
|
67
65
|
end
|
68
66
|
|
69
67
|
it "on an existing hash" do
|
70
68
|
hash.store_path("b", "b1", 2)
|
71
|
-
hash["b"].
|
69
|
+
expect(hash["b"]).to eq({"b1" => 2})
|
72
70
|
hash.store_path("c", "c1", 3)
|
73
|
-
hash["c"].
|
71
|
+
expect(hash["c"]).to eq({"c1" => 3})
|
74
72
|
end
|
75
73
|
|
76
74
|
it "on an existing item that is not a hash" do
|
77
75
|
hash.store_path("a", 2)
|
78
|
-
hash["a"].
|
76
|
+
expect(hash["a"]).to eq(2)
|
79
77
|
hash.store_path("a", "a1", 3)
|
80
|
-
hash["a"].
|
78
|
+
expect(hash["a"]).to eq({"a1" => 3})
|
81
79
|
end
|
82
80
|
|
83
81
|
it "with an array key" do
|
84
82
|
h = described_class.new
|
85
83
|
h.store_path([["d", "d1"], ["d2", "d3"]], 3)
|
86
|
-
h.
|
84
|
+
expect(h).to eq({["d", "d1"] => {["d2", "d3"] => 3}})
|
87
85
|
end
|
88
86
|
|
89
87
|
it "with a nil value" do
|
90
88
|
h = described_class.new
|
91
89
|
h.store_path("a", "b", nil)
|
92
|
-
h.
|
90
|
+
expect(h).to eq({"a" => {"b" => nil}})
|
93
91
|
end
|
94
92
|
|
95
93
|
it "with an Array value" do
|
96
94
|
h = described_class.new
|
97
95
|
h.store_path("a", "b", ["c", "d"])
|
98
|
-
h.
|
96
|
+
expect(h).to eq({"a" => {"b" => ["c", "d"]}})
|
99
97
|
end
|
100
98
|
|
101
99
|
it "with a Hash value" do
|
102
100
|
h = described_class.new
|
103
101
|
h.store_path("a", "b", {"c" => "d"})
|
104
|
-
h.
|
102
|
+
expect(h).to eq({"a" => {"b" => {"c" => "d"}}})
|
105
103
|
end
|
106
104
|
|
107
105
|
it "with invalid values" do
|
108
|
-
|
109
|
-
|
106
|
+
expect { described_class.new.store_path }.to raise_error(ArgumentError)
|
107
|
+
expect { described_class.new.store_path(1) }.to raise_error(ArgumentError)
|
110
108
|
end
|
111
109
|
|
112
110
|
include_examples "core_ext/hash/nested will not modify arguments", :store_path
|
@@ -114,33 +112,33 @@ shared_examples_for "core_ext/hash/nested" do
|
|
114
112
|
|
115
113
|
context '#has_key_path?' do
|
116
114
|
it "with various values" do
|
117
|
-
hash.has_key_path?("a").
|
118
|
-
hash.has_key_path?("b").
|
119
|
-
hash.has_key_path?("b", "b1").
|
120
|
-
hash.has_key_path?("b", "b1", "b2").
|
121
|
-
hash.has_key_path?("c").
|
122
|
-
hash.has_key_path?("c", "c1").
|
123
|
-
hash.has_key_path?("c", "c1", "c2").
|
124
|
-
hash.has_key_path?("d", "d1", "d2", "d3").
|
125
|
-
hash.has_key_path?("d", "d1", "d2", "dx").
|
126
|
-
hash.has_key_path?("d", "d1", "d2", "d3", "d4").
|
127
|
-
hash.has_key_path?("e").
|
128
|
-
hash.has_key_path?("e", "e1").
|
129
|
-
hash.has_key_path?("e", "e1", "e2").
|
130
|
-
hash.has_key_path?("f").
|
131
|
-
hash.has_key_path?("f", "f1").
|
132
|
-
hash.has_key_path?("f", "f1", "f2").
|
115
|
+
expect(hash.has_key_path?("a")).to be_truthy
|
116
|
+
expect(hash.has_key_path?("b")).to be_truthy
|
117
|
+
expect(hash.has_key_path?("b", "b1")).to be_falsey
|
118
|
+
expect(hash.has_key_path?("b", "b1", "b2")).to be_falsey
|
119
|
+
expect(hash.has_key_path?("c")).to be_truthy
|
120
|
+
expect(hash.has_key_path?("c", "c1")).to be_truthy
|
121
|
+
expect(hash.has_key_path?("c", "c1", "c2")).to be_falsey
|
122
|
+
expect(hash.has_key_path?("d", "d1", "d2", "d3")).to be_truthy
|
123
|
+
expect(hash.has_key_path?("d", "d1", "d2", "dx")).to be_falsey
|
124
|
+
expect(hash.has_key_path?("d", "d1", "d2", "d3", "d4")).to be_falsey
|
125
|
+
expect(hash.has_key_path?("e")).to be_truthy
|
126
|
+
expect(hash.has_key_path?("e", "e1")).to be_falsey
|
127
|
+
expect(hash.has_key_path?("e", "e1", "e2")).to be_falsey
|
128
|
+
expect(hash.has_key_path?("f")).to be_truthy
|
129
|
+
expect(hash.has_key_path?("f", "f1")).to be_falsey
|
130
|
+
expect(hash.has_key_path?("f", "f1", "f2")).to be_falsey
|
133
131
|
end
|
134
132
|
|
135
133
|
it "with a nil value" do
|
136
|
-
hash.has_key_path?(nil).
|
137
|
-
hash.has_key_path?("d", nil, "d1").
|
138
|
-
hash.has_key_path?("e", nil).
|
139
|
-
hash.has_key_path?("e", nil, "e1").
|
134
|
+
expect(hash.has_key_path?(nil)).to be_truthy
|
135
|
+
expect(hash.has_key_path?("d", nil, "d1")).to be_falsey
|
136
|
+
expect(hash.has_key_path?("e", nil)).to be_falsey
|
137
|
+
expect(hash.has_key_path?("e", nil, "e1")).to be_falsey
|
140
138
|
end
|
141
139
|
|
142
140
|
it "with invalid values" do
|
143
|
-
|
141
|
+
expect { hash.has_key_path? }.to raise_error(ArgumentError)
|
144
142
|
end
|
145
143
|
|
146
144
|
include_examples "core_ext/hash/nested will not modify arguments", :has_key_path?
|
@@ -149,28 +147,28 @@ shared_examples_for "core_ext/hash/nested" do
|
|
149
147
|
context "#delete_path" do
|
150
148
|
it "on a nested hash" do
|
151
149
|
hash.delete_path("d", "d1", "d2", "d3")
|
152
|
-
hash["d"].
|
150
|
+
expect(hash["d"]).to eq({"d1"=>{"d2"=>{}}})
|
153
151
|
end
|
154
152
|
|
155
153
|
it "with an invalid path" do
|
156
154
|
hash.delete_path("d", "d1", :d)
|
157
|
-
hash["d"].
|
155
|
+
expect(hash["d"]).to eq({"d1"=>{"d2"=>{"d3"=>3}}})
|
158
156
|
end
|
159
157
|
|
160
158
|
include_examples "core_ext/hash/nested will not modify arguments", :delete_path
|
161
159
|
end
|
162
160
|
|
163
161
|
it "#delete_blank_paths" do
|
164
|
-
hash.delete_blank_paths.
|
162
|
+
expect(hash.delete_blank_paths).to eq({"a"=>1, "c"=>{"c1"=>2}, "d"=>{"d1"=>{"d2"=>{"d3"=>3}}}, nil=>{nil=>7}, ["h", "i"]=>8})
|
165
163
|
end
|
166
164
|
|
167
165
|
context "#find_path" do
|
168
166
|
it "with a real value" do
|
169
|
-
hash.find_path(3).
|
167
|
+
expect(hash.find_path(3)).to eq(["d", "d1", "d2", "d3"])
|
170
168
|
end
|
171
169
|
|
172
170
|
it "with non-existent value" do
|
173
|
-
hash.find_path(42).
|
171
|
+
expect(hash.find_path(42)).to eq([])
|
174
172
|
end
|
175
173
|
end
|
176
174
|
end
|
@@ -192,6 +190,7 @@ describe Hash do
|
|
192
190
|
include_examples "core_ext/hash/nested"
|
193
191
|
end
|
194
192
|
|
193
|
+
require 'active_support'
|
195
194
|
require 'active_support/core_ext/hash'
|
196
195
|
describe HashWithIndifferentAccess do
|
197
196
|
let(:hash) do
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
1
|
describe Class do
|
4
2
|
before do
|
5
3
|
module Aaa
|
@@ -14,33 +12,19 @@ describe Class do
|
|
14
12
|
|
15
13
|
context "in_namespace?" do
|
16
14
|
it "Class in Module" do
|
17
|
-
Aaa::Bbb::Ccc::Ddd.in_namespace?(Aaa::Bbb).
|
15
|
+
expect(Aaa::Bbb::Ccc::Ddd.in_namespace?(Aaa::Bbb)).to be_truthy
|
18
16
|
end
|
19
17
|
|
20
18
|
it "Module in Module" do
|
21
|
-
Aaa::Bbb::Ccc::Eee.in_namespace?("Aaa::Bbb").
|
19
|
+
expect(Aaa::Bbb::Ccc::Eee.in_namespace?("Aaa::Bbb")).to be_truthy
|
22
20
|
end
|
23
21
|
|
24
22
|
it "Instance of Class" do
|
25
|
-
Aaa::Bbb::Ccc::Ddd.new.in_namespace?(Aaa::Bbb).
|
23
|
+
expect(Aaa::Bbb::Ccc::Ddd.new.in_namespace?(Aaa::Bbb)).to be_truthy
|
26
24
|
end
|
27
25
|
|
28
26
|
it "Not in namespace" do
|
29
|
-
Aaa::Bbb::Ccc::Eee.in_namespace?(Aaa::Bbb::Ccc::Ddd).
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context "namespace" do
|
34
|
-
it "Class in Module" do
|
35
|
-
expect(Aaa::Bbb::Ccc::Ddd.namespace).to eq(["Aaa", "Bbb", "Ccc", "Ddd"])
|
36
|
-
end
|
37
|
-
|
38
|
-
it "Module in Module" do
|
39
|
-
expect(Aaa::Bbb::Ccc::Eee.namespace).to eq(["Aaa", "Bbb", "Ccc", "Eee"])
|
40
|
-
end
|
41
|
-
|
42
|
-
it "Instance of a Class" do
|
43
|
-
expect(Aaa::Bbb::Ccc::Ddd.new.namespace).to eq(["Aaa", "Bbb", "Ccc", "Ddd"])
|
27
|
+
expect(Aaa::Bbb::Ccc::Eee.in_namespace?(Aaa::Bbb::Ccc::Ddd)).to be_falsey
|
44
28
|
end
|
45
29
|
end
|
46
30
|
end
|
@@ -1,76 +1,74 @@
|
|
1
|
-
require_relative "../../spec_helper"
|
2
|
-
|
3
1
|
describe String do
|
4
2
|
it '#email?' do
|
5
|
-
"john@example.com".
|
6
|
-
"john.doe@example.com".
|
3
|
+
expect("john@example.com").to be_email
|
4
|
+
expect("john.doe@example.com").to be_email
|
7
5
|
|
8
|
-
"john.doe@examplecom".
|
9
|
-
"john.doe@example-com".
|
10
|
-
"".
|
11
|
-
"foo".
|
6
|
+
expect("john.doe@examplecom").not_to be_email
|
7
|
+
expect("john.doe@example-com").not_to be_email
|
8
|
+
expect("").not_to be_email
|
9
|
+
expect("foo").not_to be_email
|
12
10
|
end
|
13
11
|
|
14
12
|
it '#domain_name?' do
|
15
|
-
"example.com".
|
13
|
+
expect("example.com").to be_domain_name
|
16
14
|
|
17
|
-
"example..com".
|
18
|
-
"john.doe@example.com".
|
19
|
-
"".
|
20
|
-
"foo".
|
15
|
+
expect("example..com").not_to be_domain_name
|
16
|
+
expect("john.doe@example.com").not_to be_domain_name
|
17
|
+
expect("").not_to be_domain_name
|
18
|
+
expect("foo").not_to be_domain_name
|
21
19
|
end
|
22
20
|
|
23
21
|
it '#ipv4?' do
|
24
|
-
"192.168.252.15".
|
22
|
+
expect("192.168.252.15").to be_ipv4
|
25
23
|
|
26
|
-
"392.168.252.15".
|
27
|
-
"".
|
28
|
-
"foo".
|
29
|
-
"::1".
|
30
|
-
"1762:0:0:0:0:B03:1:AF18".
|
31
|
-
"1762:0:0:0:0:B03:127.32.67.15".
|
32
|
-
"1762::B03:1:AF18".
|
24
|
+
expect("392.168.252.15").not_to be_ipv4
|
25
|
+
expect("").not_to be_ipv4
|
26
|
+
expect("foo").not_to be_ipv4
|
27
|
+
expect("::1").not_to be_ipv4 # 127.0.0.1 in IPv6
|
28
|
+
expect("1762:0:0:0:0:B03:1:AF18").not_to be_ipv4 # Standard Notation
|
29
|
+
expect("1762:0:0:0:0:B03:127.32.67.15").not_to be_ipv4 # Mixed Notation
|
30
|
+
expect("1762::B03:1:AF18").not_to be_ipv4 # Compressed Notation
|
33
31
|
end
|
34
32
|
|
35
33
|
it '#ipv6?' do
|
36
|
-
"::1".
|
37
|
-
"1762:0:0:0:0:B03:1:AF18".
|
38
|
-
"1762:0:0:0:0:B03:127.32.67.15".
|
39
|
-
"1762::B03:1:AF18".
|
34
|
+
expect("::1").to be_ipv6 # 127.0.0.1 in IPv6
|
35
|
+
expect("1762:0:0:0:0:B03:1:AF18").to be_ipv6 # Standard Notation
|
36
|
+
expect("1762:0:0:0:0:B03:127.32.67.15").to be_ipv6 # Mixed Notation
|
37
|
+
expect("1762::B03:1:AF18").to be_ipv6 # Compressed Notation
|
40
38
|
|
41
|
-
"192.168.252.15".
|
42
|
-
"392.168.252.15".
|
43
|
-
"".
|
44
|
-
"foo".
|
39
|
+
expect("192.168.252.15").not_to be_ipv6
|
40
|
+
expect("392.168.252.15").not_to be_ipv6
|
41
|
+
expect("").not_to be_ipv6
|
42
|
+
expect("foo").not_to be_ipv6
|
45
43
|
end
|
46
44
|
|
47
45
|
it "#ipaddress?" do
|
48
|
-
"192.168.252.15".
|
49
|
-
"::1".
|
50
|
-
"1762:0:0:0:0:B03:1:AF18".
|
51
|
-
"1762:0:0:0:0:B03:127.32.67.15".
|
52
|
-
"1762::B03:1:AF18".
|
46
|
+
expect("192.168.252.15").to be_ipaddress
|
47
|
+
expect("::1").to be_ipaddress # 127.0.0.1 in IPv6
|
48
|
+
expect("1762:0:0:0:0:B03:1:AF18").to be_ipaddress # Standard Notation
|
49
|
+
expect("1762:0:0:0:0:B03:127.32.67.15").to be_ipaddress # Mixed Notation
|
50
|
+
expect("1762::B03:1:AF18").to be_ipaddress # Compressed Notation
|
53
51
|
|
54
|
-
"392.168.252.15".
|
55
|
-
"".
|
56
|
-
"foo".
|
52
|
+
expect("392.168.252.15").not_to be_ipaddress
|
53
|
+
expect("").not_to be_ipaddress
|
54
|
+
expect("foo").not_to be_ipaddress
|
57
55
|
end
|
58
56
|
|
59
57
|
it "#integer?" do
|
60
|
-
"100".
|
61
|
-
"-100".
|
58
|
+
expect("100").to be_integer
|
59
|
+
expect("-100").to be_integer
|
62
60
|
|
63
|
-
"".
|
64
|
-
"100.2".
|
65
|
-
"A".
|
66
|
-
"100A".
|
61
|
+
expect("").not_to be_integer
|
62
|
+
expect("100.2").not_to be_integer
|
63
|
+
expect("A").not_to be_integer
|
64
|
+
expect("100A").not_to be_integer
|
67
65
|
end
|
68
66
|
|
69
67
|
it '#guid?' do
|
70
|
-
'01234567-89ab-cdef-abcd-ef0123456789'.
|
68
|
+
expect('01234567-89ab-cdef-abcd-ef0123456789').to be_guid
|
71
69
|
|
72
|
-
'012ZZZ67-89ab-cdef-abcd-ef0123456789'.
|
73
|
-
"".
|
74
|
-
"foo".
|
70
|
+
expect('012ZZZ67-89ab-cdef-abcd-ef0123456789').not_to be_guid
|
71
|
+
expect("").not_to be_guid
|
72
|
+
expect("foo").not_to be_guid
|
75
73
|
end
|
76
|
-
end
|
74
|
+
end
|