ruby-nuggets 0.9.8.1 → 0.9.9
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 +4 -4
- data/README +1 -1
- data/Rakefile +9 -3
- data/lib/nuggets/all.rb +1 -1
- data/lib/nuggets/array/combination.rb +2 -25
- data/lib/nuggets/array/flatten_once.rb +1 -12
- data/lib/nuggets/array/format.rb +2 -60
- data/lib/nuggets/array/in_order.rb +1 -12
- data/lib/nuggets/array/monotone.rb +10 -27
- data/lib/nuggets/array/only.rb +1 -16
- data/lib/nuggets/array/shuffle.rb +1 -1
- data/lib/nuggets/array/to_hash.rb +1 -22
- data/lib/nuggets/cli.rb +2 -2
- data/lib/nuggets/content_type.rb +3 -8
- data/lib/nuggets/dotted_decimal.rb +0 -18
- data/lib/nuggets/enumerable/all_any_extended.rb +0 -27
- data/lib/nuggets/enumerable/minmax.rb +4 -25
- data/lib/nuggets/hash/at.rb +2 -20
- data/lib/nuggets/hash/deep_fetch.rb +5 -0
- data/lib/nuggets/hash/deep_fetch_mixin.rb +75 -0
- data/lib/nuggets/hash/in_order.rb +0 -8
- data/lib/nuggets/hash/insert.rb +2 -13
- data/lib/nuggets/hash/only.rb +2 -18
- data/lib/nuggets/i18n.rb +1 -10
- data/lib/nuggets/integer/factorial.rb +0 -17
- data/lib/nuggets/integer/to_binary_s.rb +0 -8
- data/lib/nuggets/lsi.rb +2 -2
- data/lib/nuggets/midos.rb +2 -2
- data/lib/nuggets/mysql.rb +6 -207
- data/lib/nuggets/numeric/duration.rb +0 -8
- data/lib/nuggets/numeric/limit.rb +1 -8
- data/lib/nuggets/numeric/signum.rb +0 -7
- data/lib/nuggets/numeric/to_multiple.rb +0 -6
- data/lib/nuggets/rdf/compression.rb +3 -89
- data/lib/nuggets/rdf/prefix.rb +6 -32
- data/lib/nuggets/rdf/turtle/reader.rb +5 -70
- data/lib/nuggets/rdf/turtle.rb +6 -122
- data/lib/nuggets/rdf/uri.rb +5 -37
- data/lib/nuggets/ruby.rb +39 -147
- data/lib/nuggets/string/capitalize_first.rb +2 -18
- data/lib/nuggets/string/case.rb +0 -22
- data/lib/nuggets/string/msub.rb +0 -18
- data/lib/nuggets/string/nsub.rb +2 -16
- data/lib/nuggets/string/sub_with_md.rb +6 -25
- data/lib/nuggets/string/word_wrap.rb +1 -35
- data/lib/nuggets/util/ansicolor2css.rb +1 -1
- data/lib/nuggets/util/cli.rb +1 -1
- data/lib/nuggets/util/content_type.rb +1 -1
- data/lib/nuggets/util/dotted_decimal.rb +1 -2
- data/lib/nuggets/util/i18n.rb +1 -1
- data/lib/nuggets/util/lazy_attr.rb +1 -1
- data/lib/nuggets/util/log_parser/apache.rb +1 -1
- data/lib/nuggets/util/log_parser/rails.rb +1 -1
- data/lib/nuggets/util/log_parser.rb +1 -1
- data/lib/nuggets/util/midos.rb +1 -1
- data/lib/nuggets/util/mysql.rb +1 -1
- data/lib/nuggets/util/pluggable.rb +1 -1
- data/lib/nuggets/util/ruby.rb +1 -1
- data/lib/nuggets/version.rb +2 -2
- data/spec/nuggets/array/boost_spec.rb +1 -3
- data/spec/nuggets/array/combination_spec.rb +25 -0
- data/spec/nuggets/array/correlation_spec.rb +1 -3
- data/spec/nuggets/array/flatten_once_spec.rb +16 -0
- data/spec/nuggets/array/flush_spec.rb +1 -3
- data/spec/nuggets/array/format_spec.rb +52 -0
- data/spec/nuggets/array/hashify_spec.rb +1 -3
- data/spec/nuggets/array/histogram_spec.rb +1 -3
- data/spec/nuggets/array/in_order_spec.rb +13 -0
- data/spec/nuggets/array/limit_spec.rb +1 -3
- data/spec/nuggets/array/mean_spec.rb +3 -5
- data/spec/nuggets/array/median_spec.rb +3 -5
- data/spec/nuggets/array/mode_spec.rb +1 -3
- data/spec/nuggets/array/monotone_spec.rb +30 -0
- data/spec/nuggets/array/only_spec.rb +26 -0
- data/spec/nuggets/array/regression_spec.rb +1 -3
- data/spec/nuggets/array/runiq_spec.rb +1 -3
- data/spec/nuggets/array/standard_deviation_spec.rb +1 -3
- data/spec/nuggets/array/to_hash_spec.rb +28 -0
- data/spec/nuggets/array/variance_spec.rb +3 -5
- data/spec/nuggets/dotted_decimal_spec.rb +27 -0
- data/spec/nuggets/enumerable/all_any_extended_spec.rb +31 -0
- data/spec/nuggets/enumerable/minmax_spec.rb +21 -0
- data/spec/nuggets/env/set_spec.rb +1 -3
- data/spec/nuggets/env/user_encoding_spec.rb +1 -3
- data/spec/nuggets/env/user_home_spec.rb +12 -10
- data/spec/nuggets/file/ext_spec.rb +1 -3
- data/spec/nuggets/file/replace_spec.rb +1 -3
- data/spec/nuggets/file/sub_spec.rb +1 -3
- data/spec/nuggets/file/which_spec.rb +1 -3
- data/spec/nuggets/hash/at_spec.rb +19 -0
- data/spec/nuggets/hash/deep_fetch_spec.rb +159 -0
- data/spec/nuggets/hash/deep_merge_spec.rb +1 -3
- data/spec/nuggets/hash/in_order_spec.rb +12 -0
- data/spec/nuggets/hash/insert_spec.rb +13 -0
- data/spec/nuggets/hash/nest_spec.rb +1 -3
- data/spec/nuggets/hash/only_spec.rb +29 -0
- data/spec/nuggets/hash/seen_spec.rb +4 -6
- data/spec/nuggets/hash/unroll_spec.rb +2 -4
- data/spec/nuggets/i18n_spec.rb +13 -0
- data/spec/nuggets/integer/factorial_spec.rb +10 -0
- data/spec/nuggets/integer/length_spec.rb +1 -3
- data/spec/nuggets/integer/map_spec.rb +1 -3
- data/spec/nuggets/integer/to_binary_s_spec.rb +19 -0
- data/spec/nuggets/numeric/duration_spec.rb +25 -0
- data/spec/nuggets/numeric/limit_spec.rb +16 -0
- data/spec/nuggets/numeric/signum_spec.rb +16 -0
- data/spec/nuggets/numeric/to_multiple_spec.rb +16 -0
- data/spec/nuggets/object/blank_spec.rb +1 -2
- data/spec/nuggets/object/boolean_spec.rb +1 -3
- data/spec/nuggets/object/msend_spec.rb +1 -3
- data/spec/nuggets/object/silence_spec.rb +7 -4
- data/spec/nuggets/object/singleton_class_spec.rb +11 -4
- data/spec/nuggets/proc/bind_spec.rb +1 -3
- data/spec/nuggets/range/quantile_spec.rb +1 -3
- data/spec/nuggets/string/camelscore_spec.rb +11 -13
- data/spec/nuggets/string/capitalize_first_spec.rb +13 -0
- data/spec/nuggets/string/case_spec.rb +31 -0
- data/spec/nuggets/string/evaluate_spec.rb +1 -3
- data/spec/nuggets/string/msub_spec.rb +20 -0
- data/spec/nuggets/string/nsub_spec.rb +13 -0
- data/spec/nuggets/string/sub_with_md_spec.rb +25 -0
- data/spec/nuggets/string/wc_spec.rb +1 -3
- data/spec/nuggets/string/word_wrap_spec.rb +81 -0
- data/spec/nuggets/string/xor_spec.rb +1 -3
- data/spec/nuggets/uri/content_type_spec.rb +32 -27
- data/spec/nuggets/uri/exist_spec.rb +33 -9
- data/spec/spec_helper.rb +17 -0
- metadata +34 -5
- data/.rspec +0 -1
@@ -0,0 +1,159 @@
|
|
1
|
+
require 'nuggets/hash/deep_fetch'
|
2
|
+
|
3
|
+
describe_extended Hash, Nuggets::Hash::DeepFetchMixin do
|
4
|
+
|
5
|
+
example do
|
6
|
+
lambda { {}.deep_fetch('') }.should raise_error(ArgumentError, 'no keys given')
|
7
|
+
end
|
8
|
+
|
9
|
+
context do
|
10
|
+
|
11
|
+
let(:hash) { { 'foo' => { 'bar' => { 'baz' => 42 }, 'bay' => 23 } } }
|
12
|
+
|
13
|
+
example do
|
14
|
+
hash.deep_fetch('foo/bar/baz').should == 42
|
15
|
+
end
|
16
|
+
|
17
|
+
example do
|
18
|
+
hash.deep_fetch('foo/bar/bax').should == nil
|
19
|
+
end
|
20
|
+
|
21
|
+
example do
|
22
|
+
lambda { hash.deep_fetch('foo/bax/baz') }.should raise_error(KeyError)
|
23
|
+
end
|
24
|
+
|
25
|
+
example do
|
26
|
+
lambda { hash.deep_fetch('foo/bay/baz') }.should raise_error(TypeError)
|
27
|
+
end
|
28
|
+
|
29
|
+
example do
|
30
|
+
hash.deep_fetch('foo:bar:baz').should == nil
|
31
|
+
end
|
32
|
+
|
33
|
+
example do
|
34
|
+
hash.deep_fetch('foo:bar:baz', ':').should == 42
|
35
|
+
end
|
36
|
+
|
37
|
+
example do
|
38
|
+
hash.deep_fetch(%w[foo bar baz]).should == 42
|
39
|
+
end
|
40
|
+
|
41
|
+
example do
|
42
|
+
lambda { hash.deep_fetch([:foo, :bar, :baz]) }.should raise_error(KeyError)
|
43
|
+
end
|
44
|
+
|
45
|
+
example do
|
46
|
+
(hash % 'foo/bar/baz').should == 42
|
47
|
+
end
|
48
|
+
|
49
|
+
example do
|
50
|
+
(hash % %w[foo bar baz]).should == 42
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
context do
|
56
|
+
|
57
|
+
let(:hash) { { :foo => { :bar => { :baz => 42 } } } }
|
58
|
+
|
59
|
+
example do
|
60
|
+
lambda { hash.deep_fetch('foo/bar/baz') }.should raise_error(KeyError)
|
61
|
+
end
|
62
|
+
|
63
|
+
example do
|
64
|
+
hash.deep_fetch('foo/bar/baz', &:to_sym).should == 42
|
65
|
+
end
|
66
|
+
|
67
|
+
example do
|
68
|
+
hash.deep_fetch('foo:bar:baz', &:to_sym).should == nil
|
69
|
+
end
|
70
|
+
|
71
|
+
example do
|
72
|
+
hash.deep_fetch('foo:bar:baz', ':', &:to_sym).should == 42
|
73
|
+
end
|
74
|
+
|
75
|
+
example do
|
76
|
+
lambda { hash.deep_fetch(%w[foo bar baz]) }.should raise_error(KeyError)
|
77
|
+
end
|
78
|
+
|
79
|
+
example do
|
80
|
+
hash.deep_fetch([:foo, :bar, :baz]).should == 42
|
81
|
+
end
|
82
|
+
|
83
|
+
example do
|
84
|
+
lambda { hash % 'foo/bar/baz' }.should raise_error(KeyError)
|
85
|
+
end
|
86
|
+
|
87
|
+
example do
|
88
|
+
(hash % [:foo, :bar, :baz]).should == 42
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
context do
|
94
|
+
|
95
|
+
let(:hash) { { 1 => { 2 => { 3 => 42 } } } }
|
96
|
+
|
97
|
+
example do
|
98
|
+
lambda { hash.deep_fetch('1/2/3') }.should raise_error(KeyError)
|
99
|
+
end
|
100
|
+
|
101
|
+
example do
|
102
|
+
hash.deep_fetch('1/2/3', &:to_i).should == 42
|
103
|
+
end
|
104
|
+
|
105
|
+
example do
|
106
|
+
hash.deep_fetch('1:2:3', &:to_i).should == { 2 => { 3 => 42 } }
|
107
|
+
end
|
108
|
+
|
109
|
+
example do
|
110
|
+
hash.deep_fetch('1:2:3', ':', &:to_i).should == 42
|
111
|
+
end
|
112
|
+
|
113
|
+
example do
|
114
|
+
lambda { hash.deep_fetch(%w[1 2 3]) }.should raise_error(KeyError)
|
115
|
+
end
|
116
|
+
|
117
|
+
example do
|
118
|
+
hash.deep_fetch([1, 2, 3]).should == 42
|
119
|
+
end
|
120
|
+
|
121
|
+
example do
|
122
|
+
lambda { hash % '1/2/3' }.should raise_error(KeyError)
|
123
|
+
end
|
124
|
+
|
125
|
+
example do
|
126
|
+
(hash % [1, 2, 3]).should == 42
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
context do
|
132
|
+
|
133
|
+
let(:hash) { { 'foo' => Hash.new(0) } }
|
134
|
+
|
135
|
+
example do
|
136
|
+
hash.deep_fetch('foo/bar').should == 0
|
137
|
+
end
|
138
|
+
|
139
|
+
example do
|
140
|
+
lambda { hash.deep_fetch('foo/bar/baz') }.should raise_error(KeyError)
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
context do
|
146
|
+
|
147
|
+
let(:hash) { { 'foo' => Hash.new { |h, k| h[k] = [] } } }
|
148
|
+
|
149
|
+
example do
|
150
|
+
hash.deep_fetch('foo/bar').should == []
|
151
|
+
end
|
152
|
+
|
153
|
+
example do
|
154
|
+
lambda { hash.deep_fetch('foo/bar/baz') }.should raise_error(KeyError)
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'nuggets/hash/deep_merge'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
it { Hash.ancestors.should include(Nuggets::Hash::DeepMergeMixin) }
|
3
|
+
describe_extended Hash, Nuggets::Hash::DeepMergeMixin do
|
6
4
|
|
7
5
|
example do
|
8
6
|
{ :a => 1 }.deep_merge(:a => 2).should == { :a => 2 }
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'nuggets/hash/insert'
|
2
|
+
|
3
|
+
describe Hash, 'insert' do
|
4
|
+
|
5
|
+
let(:h) { { a: 0, b: { b1: 1, b2: 2 } } }
|
6
|
+
|
7
|
+
example { h.insert(a: -1).should == { a: -1, b: { b1: 1, b2: 2 } } }
|
8
|
+
|
9
|
+
example { h.insert(b: { b3: 3 }).should == { a: 0, b: { b1: 1, b2: 2, b3: 3 } } }
|
10
|
+
|
11
|
+
example { h.insert!(b: { b0: 0 }); h.should == { a: 0, b: { b1: 1, b2: 2, b0: 0 } } }
|
12
|
+
|
13
|
+
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'nuggets/hash/nest'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
it { (class << Hash; self; end).ancestors.should include(Nuggets::Hash::NestMixin) }
|
3
|
+
describe_extended Hash, Nuggets::Hash::NestMixin, true do
|
6
4
|
|
7
5
|
example do
|
8
6
|
hash = Hash.nest
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'nuggets/hash/only'
|
2
|
+
|
3
|
+
describe Hash, 'only' do
|
4
|
+
|
5
|
+
example {
|
6
|
+
h = { a: 5 }
|
7
|
+
|
8
|
+
h.only.should == { a: 5 }
|
9
|
+
h.only_pair.should == [:a, 5]
|
10
|
+
h.only(true).should == { a: 5 }
|
11
|
+
}
|
12
|
+
|
13
|
+
example {
|
14
|
+
h = { 1 => 2, 3 => 4 }
|
15
|
+
|
16
|
+
lambda { h.only }.should raise_error(IndexError, 'not a single-element hash')
|
17
|
+
lambda { h.only_pair }.should raise_error(IndexError, 'not a single-element hash')
|
18
|
+
h.only(true).should == { 1 => 2 }
|
19
|
+
}
|
20
|
+
|
21
|
+
example {
|
22
|
+
h = {}
|
23
|
+
|
24
|
+
lambda { h.only }.should raise_error(IndexError, 'not a single-element hash')
|
25
|
+
lambda { h.only_pair }.should raise_error(IndexError, 'not a single-element hash')
|
26
|
+
h.only(true).should == {}
|
27
|
+
}
|
28
|
+
|
29
|
+
end
|
@@ -1,18 +1,16 @@
|
|
1
1
|
require 'nuggets/hash/seen'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
it { (class << Hash; self; end).ancestors.should include(Nuggets::Hash::SeenMixin) }
|
3
|
+
describe_extended Hash, Nuggets::Hash::SeenMixin, true do
|
6
4
|
|
7
5
|
example do
|
8
6
|
hash = Hash.seen
|
9
7
|
hash.should be_an_instance_of(Hash)
|
10
8
|
|
11
|
-
hash[:a].should
|
9
|
+
hash[:a].should == false
|
12
10
|
hash.should have_key(:a)
|
13
11
|
|
14
|
-
hash[:a].should
|
15
|
-
hash[:a].should
|
12
|
+
hash[:a].should == true
|
13
|
+
hash[:a].should == true
|
16
14
|
end
|
17
15
|
|
18
16
|
example do
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'nuggets/hash/unroll'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
it { Hash.ancestors.should include(Nuggets::Hash::UnrollMixin) }
|
3
|
+
describe_extended Hash, Nuggets::Hash::UnrollMixin do
|
6
4
|
|
7
5
|
example do
|
8
6
|
hash = {}
|
@@ -28,7 +26,7 @@ describe Hash, 'when extended by', Nuggets::Hash::UnrollMixin do
|
|
28
26
|
hash = { :a => { :b => 1, :c => 2 } }
|
29
27
|
|
30
28
|
result = hash.unroll.first
|
31
|
-
result.should
|
29
|
+
result.size.should == 3
|
32
30
|
|
33
31
|
result.first.should == :a
|
34
32
|
result.should include(1)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'nuggets/i18n'
|
4
|
+
|
5
|
+
describe String, 'i18n' do
|
6
|
+
|
7
|
+
let(:s) { 'Äh, Rüby iß sö cüül, nö? SÖS!' }
|
8
|
+
|
9
|
+
example { s.replace_diacritics.should == 'Aeh, Rueby iss soe cueuel, noe? SOES!' }
|
10
|
+
|
11
|
+
example { s.replace_diacritics!; s.should == 'Aeh, Rueby iss soe cueuel, noe? SOES!' }
|
12
|
+
|
13
|
+
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'nuggets/integer/length'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
it { Integer.ancestors.should include(Nuggets::Integer::LengthMixin) }
|
3
|
+
describe_extended Integer, Nuggets::Integer::LengthMixin do
|
6
4
|
|
7
5
|
{
|
8
6
|
0 => [1, 1],
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'nuggets/integer/to_binary_s'
|
2
|
+
|
3
|
+
describe Integer, 'to_binary_s' do
|
4
|
+
|
5
|
+
{
|
6
|
+
20000 => %w[00000000000000000100111000100000 100111000100000],
|
7
|
+
800 => %w[00000000000000000000001100100000 1100100000],
|
8
|
+
300 => %w[00000000000000000000000100101100 100101100],
|
9
|
+
700 => %w[00000000000000000000001010111100 1010111100],
|
10
|
+
130 => %w[00000000000000000000000010000010 10000010],
|
11
|
+
480 => %w[00000000000000000000000111100000 111100000],
|
12
|
+
9999 => %w[00000000000000000010011100001111 10011100001111],
|
13
|
+
25000 => %w[00000000000000000110000110101000 110000110101000]
|
14
|
+
}.each { |i, (j, k)|
|
15
|
+
example { i.to_binary_s.should == k }
|
16
|
+
example { i.to_binary_s(32).should == j }
|
17
|
+
}
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'nuggets/numeric/duration'
|
2
|
+
|
3
|
+
describe Numeric, 'duration' do
|
4
|
+
|
5
|
+
{
|
6
|
+
123 => [[[ 0, 2, 3], '2m3s', '2m3.00s'], [[0, 0, 0.0014236111111111112], '0d', '0d 2m3s']],
|
7
|
+
123456789 => [[[34293, 33, 9], '34293h33m9s', '34293h33m9.00s'], [[3, 11, 3.1480208333333333], '3y11m3d', '3y11m3d 3h33m9s']],
|
8
|
+
0 => [[[ 0, 0, 0], '0s', '0.00s'], [[0, 0, 0.0], '0d', '0d 0s']],
|
9
|
+
0.001 => [[[ 0, 0, 0.001], '0s', '0.00s'], [[0, 0, 1.1574074074074074e-08], '0d', '0d 0s']],
|
10
|
+
1.23 => [[[ 0, 0, 1.23], '1s', '1.23s'], [[0, 0, 1.4236111111111111e-05], '0d', '0d 1s']],
|
11
|
+
1234.56789 => [[[ 0, 20, 34.567890000000034], '20m35s', '20m34.57s'], [[0, 0, 0.014288980208333333], '0d', '0d 20m35s']]
|
12
|
+
}.each { |n, (h, y)|
|
13
|
+
example { [n.hms, n.to_hms, n.to_hms(2)].should == h }
|
14
|
+
example { [n.ymd, n.to_ymd, n.to_ymd(true)].should == y }
|
15
|
+
}
|
16
|
+
|
17
|
+
example {
|
18
|
+
lambda { -1.hms }.should raise_error(ArgumentError, 'negative duration -1')
|
19
|
+
}
|
20
|
+
|
21
|
+
example {
|
22
|
+
lambda { -1.ymd }.should raise_error(ArgumentError, 'negative duration -1')
|
23
|
+
}
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'nuggets/numeric/to_multiple'
|
2
|
+
|
3
|
+
describe Numeric, 'to_multiple' do
|
4
|
+
|
5
|
+
{
|
6
|
+
123 => [ 120, 120, 130],
|
7
|
+
-123 => [-120, -130, -120],
|
8
|
+
0 => [ 0, 0, 0],
|
9
|
+
0.001 => [ 0, 0, 10],
|
10
|
+
5.67 => [ 10, 0, 10],
|
11
|
+
-12.3 => [ -10, -20, -10]
|
12
|
+
}.each { |n, m|
|
13
|
+
example { [n.round_to(10), n.floor_to(10), n.ceil_to(10)].should == m }
|
14
|
+
}
|
15
|
+
|
16
|
+
end
|
@@ -1,8 +1,7 @@
|
|
1
1
|
require 'nuggets/object/blank'
|
2
2
|
|
3
|
-
|
3
|
+
describe_extended Object, Nuggets::Object::BlankMixin do
|
4
4
|
|
5
|
-
it { Object.ancestors.should include(Nuggets::Object::BlankMixin) }
|
6
5
|
it { Array.ancestors.should include(Nuggets::Array::BlankMixin) }
|
7
6
|
it { Hash.ancestors.should include(Nuggets::Hash::BlankMixin) }
|
8
7
|
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'nuggets/object/boolean'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
it { Object.ancestors.should include(Nuggets::Object::BooleanMixin) }
|
3
|
+
describe_extended Object, Nuggets::Object::BooleanMixin do
|
6
4
|
|
7
5
|
[0, 1, -1, nil, '', 'abc', Class, Object.new].each { |o|
|
8
6
|
example { o.should_not be_boolean }
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'nuggets/object/msend'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
it { Object.ancestors.should include(Nuggets::Object::MSendMixin) }
|
3
|
+
describe_extended Object, Nuggets::Object::MSendMixin do
|
6
4
|
|
7
5
|
example do
|
8
6
|
o = 'foo bar'
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'nuggets/object/silence'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
it { Object.ancestors.should include(Nuggets::Object::SilenceMixin) }
|
3
|
+
describe_extended Object, Nuggets::Object::SilenceMixin do
|
6
4
|
|
7
5
|
before do
|
8
6
|
@stderr, @old_stderr = '', $stderr
|
@@ -20,7 +18,12 @@ describe Object, 'when extended by', Nuggets::Object::SilenceMixin do
|
|
20
18
|
AConst = :bar
|
21
19
|
|
22
20
|
AConst.should be_equal(:bar)
|
23
|
-
|
21
|
+
|
22
|
+
if RUBY_ENGINE == 'rbx'
|
23
|
+
@stderr.should == ''
|
24
|
+
else
|
25
|
+
@stderr.should =~ /warning: already initialized constant AConst/
|
26
|
+
end
|
24
27
|
end
|
25
28
|
|
26
29
|
example do
|
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'nuggets/object/singleton_class'
|
2
2
|
|
3
|
-
|
3
|
+
describe_extended Object, Nuggets::Object::SingletonClassMixin do
|
4
4
|
|
5
|
-
|
5
|
+
objects = [Class, Object.new, Class.new, 's', [1, 2], { :a => 'b' }]
|
6
|
+
objects.unshift(Object) unless RUBY_PLATFORM == 'java' || RUBY_ENGINE == 'rbx'
|
6
7
|
|
7
|
-
|
8
|
+
objects.each { |o|
|
8
9
|
example { o.should_not be_a_singleton_class }
|
9
10
|
example { lambda { o.singleton_object }.should raise_error(TypeError) }
|
10
11
|
|
@@ -23,7 +24,13 @@ describe Object, 'when extended by', Nuggets::Object::SingletonClassMixin do
|
|
23
24
|
|
24
25
|
example do
|
25
26
|
nil.singleton_class.should == NilClass
|
26
|
-
|
27
|
+
|
28
|
+
if RUBY_VERSION < '2'
|
29
|
+
NilClass.should be_a_singleton_class
|
30
|
+
else
|
31
|
+
NilClass.should be_a_virtual_class
|
32
|
+
end
|
33
|
+
|
27
34
|
NilClass.singleton_object.should be_equal(nil)
|
28
35
|
end
|
29
36
|
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'nuggets/range/quantile'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
it { Range.ancestors.should include(Nuggets::Range::QuantileMixin) }
|
3
|
+
describe_extended Range, Nuggets::Range::QuantileMixin do
|
6
4
|
|
7
5
|
example do
|
8
6
|
(1..5).quantile(0, 3).should == 1
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'nuggets/string/camelscore'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
it { String.ancestors.should include(Nuggets::String::CamelscoreMixin) }
|
3
|
+
describe_extended String, Nuggets::String::CamelscoreMixin do
|
6
4
|
|
7
5
|
def self.with_acronyms(acronyms, &block)
|
8
6
|
describe "with acronyms #{acronyms.inspect}" do
|
@@ -68,18 +66,18 @@ describe String, 'when extended by', Nuggets::String::CamelscoreMixin do
|
|
68
66
|
example { 'HTML'.underscore.should == 'html' }
|
69
67
|
example { 'html5'.camelcase.should == 'HTML5' }
|
70
68
|
example { 'HTML5'.underscore.should == 'html5' }
|
71
|
-
|
72
|
-
|
69
|
+
#pending { 'xhtml'.camelcase.should == 'XHTML' }
|
70
|
+
#pending { 'XHTML'.underscore.should == 'xhtml' }
|
73
71
|
example { 'sql'.camelcase.should == 'SQL' }
|
74
72
|
example { 'SQL'.underscore.should == 'sql' }
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
73
|
+
#pending { 'mysql'.camelcase.should == 'MySQL' }
|
74
|
+
#pending { 'MySQL'.underscore.should == 'mysql' }
|
75
|
+
#pending { 'postgresql'.camelcase.should == 'PostgreSQL' }
|
76
|
+
#pending { 'PostgreSQL'.underscore.should == 'postgresql' }
|
77
|
+
#pending { 'sqlite'.camelcase.should == 'SQLite' }
|
78
|
+
#pending { 'SQLite'.underscore.should == 'sqlite' }
|
79
|
+
#pending { 'nosql'.camelcase.should == 'NoSQL' }
|
80
|
+
#pending { 'NoSQL'.underscore.should == 'nosql' }
|
83
81
|
}
|
84
82
|
|
85
83
|
with_acronyms('rss' => 'RSS', 'xml' => 'XML') {
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'nuggets/string/capitalize_first'
|
2
|
+
|
3
|
+
describe String, 'capitalize_first' do
|
4
|
+
|
5
|
+
{
|
6
|
+
'Some string' => 'Some string',
|
7
|
+
'some string' => 'Some string',
|
8
|
+
'SOME STRING' => 'SOME STRING'
|
9
|
+
}.each { |s, c|
|
10
|
+
example { s.capitalize_first.should == c }
|
11
|
+
}
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'nuggets/string/case'
|
2
|
+
|
3
|
+
describe String, 'case' do
|
4
|
+
|
5
|
+
example {
|
6
|
+
s = 'Some string'
|
7
|
+
|
8
|
+
s.case.should == :mixed
|
9
|
+
s.should_not be_downcase
|
10
|
+
s.should_not be_upcase
|
11
|
+
s.should be_mixed_case
|
12
|
+
s.should be_capitalized
|
13
|
+
}
|
14
|
+
|
15
|
+
example {
|
16
|
+
s = 'some string'
|
17
|
+
|
18
|
+
s.case.should == :lower
|
19
|
+
s.should be_downcase
|
20
|
+
s.should_not be_mixed_case
|
21
|
+
}
|
22
|
+
|
23
|
+
example {
|
24
|
+
s = 'SOME STRING'
|
25
|
+
|
26
|
+
s.case.should == :upper
|
27
|
+
s.should be_upcase
|
28
|
+
s.should_not be_mixed_case
|
29
|
+
}
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'nuggets/string/msub'
|
2
|
+
|
3
|
+
describe String, 'msub' do
|
4
|
+
|
5
|
+
let(:s) { 'Foo, Bar - Baz' }
|
6
|
+
|
7
|
+
example { s.gsub(/a/, 'o').gsub(/o/, 'a').should == 'Faa, Bar - Baz' }
|
8
|
+
example { s.msub('a' => 'o', 'o' => 'a').should == 'Faa, Bor - Boz' }
|
9
|
+
|
10
|
+
example { s.msub!('a' => 'o', 'o' => 'a'); s.should == 'Faa, Bor - Boz' }
|
11
|
+
|
12
|
+
example { s.msub(/[A-Z]/ => '#{__match__.downcase}', __binding__: binding).should == 'foo, bar - baz' }
|
13
|
+
example { s.msub(/[A-Z]/ => lambda { |match| match.downcase }).should == 'foo, bar - baz' }
|
14
|
+
|
15
|
+
t = '!!!'
|
16
|
+
|
17
|
+
example { lambda { s.msub('r' => '???', 'z' => '#{t}') }.should raise_error(NameError) }
|
18
|
+
example { s.msub('r' => '???', 'z' => '#{t}', __binding__: binding).should == 'Foo, Ba??? - Ba!!!' }
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'nuggets/string/nsub'
|
2
|
+
|
3
|
+
describe String, 'nsub' do
|
4
|
+
|
5
|
+
let(:s) { 'a b c d e f g h i' }
|
6
|
+
|
7
|
+
example { s.nsub(' ', '', 6).should == 'abcdefg h i' }
|
8
|
+
|
9
|
+
example { s.nsub(' ', 6) { '' }.should == 'abcdefg h i' }
|
10
|
+
|
11
|
+
example { s.nsub!(' ', '', 6); s.should == 'abcdefg h i' }
|
12
|
+
|
13
|
+
end
|