ruby-nuggets 0.9.9 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- metadata +20 -324
- data/COPYING +0 -663
- data/ChangeLog +0 -7
- data/README +0 -62
- data/Rakefile +0 -47
- data/lib/nuggets.rb +0 -73
- data/lib/nuggets/all.rb +0 -36
- data/lib/nuggets/all_mixins.rb +0 -34
- data/lib/nuggets/ansicolor2css.rb +0 -125
- data/lib/nuggets/argv/option.rb +0 -3
- data/lib/nuggets/argv/option_mixin.rb +0 -85
- data/lib/nuggets/array/boost.rb +0 -5
- data/lib/nuggets/array/boost_mixin.rb +0 -78
- data/lib/nuggets/array/combination.rb +0 -63
- data/lib/nuggets/array/correlation.rb +0 -5
- data/lib/nuggets/array/correlation_mixin.rb +0 -64
- data/lib/nuggets/array/flatten_once.rb +0 -57
- data/lib/nuggets/array/flush.rb +0 -5
- data/lib/nuggets/array/flush_mixin.rb +0 -47
- data/lib/nuggets/array/format.rb +0 -66
- data/lib/nuggets/array/hashify.rb +0 -5
- data/lib/nuggets/array/hashify_mixin.rb +0 -48
- data/lib/nuggets/array/histogram.rb +0 -5
- data/lib/nuggets/array/histogram_mixin.rb +0 -170
- data/lib/nuggets/array/in_order.rb +0 -51
- data/lib/nuggets/array/limit.rb +0 -5
- data/lib/nuggets/array/limit_mixin.rb +0 -57
- data/lib/nuggets/array/mean.rb +0 -5
- data/lib/nuggets/array/mean_mixin.rb +0 -203
- data/lib/nuggets/array/median.rb +0 -5
- data/lib/nuggets/array/median_mixin.rb +0 -74
- data/lib/nuggets/array/mode.rb +0 -5
- data/lib/nuggets/array/mode_mixin.rb +0 -70
- data/lib/nuggets/array/monotone.rb +0 -84
- data/lib/nuggets/array/only.rb +0 -42
- data/lib/nuggets/array/rand.rb +0 -45
- data/lib/nuggets/array/regression.rb +0 -5
- data/lib/nuggets/array/regression_mixin.rb +0 -150
- data/lib/nuggets/array/runiq.rb +0 -5
- data/lib/nuggets/array/runiq_mixin.rb +0 -53
- data/lib/nuggets/array/shuffle.rb +0 -133
- data/lib/nuggets/array/standard_deviation.rb +0 -5
- data/lib/nuggets/array/standard_deviation_mixin.rb +0 -51
- data/lib/nuggets/array/to_hash.rb +0 -65
- data/lib/nuggets/array/variance.rb +0 -5
- data/lib/nuggets/array/variance_mixin.rb +0 -82
- data/lib/nuggets/cli.rb +0 -8
- data/lib/nuggets/content_type.rb +0 -98
- data/lib/nuggets/dotted_decimal.rb +0 -60
- data/lib/nuggets/enumerable/agrep.rb +0 -80
- data/lib/nuggets/enumerable/all_any_extended.rb +0 -67
- data/lib/nuggets/enumerable/minmax.rb +0 -103
- data/lib/nuggets/env/set.rb +0 -3
- data/lib/nuggets/env/set_mixin.rb +0 -68
- data/lib/nuggets/env/user_encoding.rb +0 -3
- data/lib/nuggets/env/user_encoding_mixin.rb +0 -55
- data/lib/nuggets/env/user_home.rb +0 -3
- data/lib/nuggets/env/user_home_mixin.rb +0 -57
- data/lib/nuggets/file/ext.rb +0 -5
- data/lib/nuggets/file/ext_mixin.rb +0 -88
- data/lib/nuggets/file/replace.rb +0 -5
- data/lib/nuggets/file/replace_mixin.rb +0 -56
- data/lib/nuggets/file/sub.rb +0 -5
- data/lib/nuggets/file/sub_mixin.rb +0 -96
- data/lib/nuggets/file/which.rb +0 -5
- data/lib/nuggets/file/which_mixin.rb +0 -73
- data/lib/nuggets/hash/at.rb +0 -69
- data/lib/nuggets/hash/deep_fetch.rb +0 -5
- data/lib/nuggets/hash/deep_fetch_mixin.rb +0 -75
- data/lib/nuggets/hash/deep_merge.rb +0 -5
- data/lib/nuggets/hash/deep_merge_mixin.rb +0 -54
- data/lib/nuggets/hash/idmap.rb +0 -5
- data/lib/nuggets/hash/idmap_mixin.rb +0 -42
- data/lib/nuggets/hash/in_order.rb +0 -44
- data/lib/nuggets/hash/insert.rb +0 -54
- data/lib/nuggets/hash/nest.rb +0 -5
- data/lib/nuggets/hash/nest_mixin.rb +0 -79
- data/lib/nuggets/hash/only.rb +0 -53
- data/lib/nuggets/hash/seen.rb +0 -5
- data/lib/nuggets/hash/seen_mixin.rb +0 -59
- data/lib/nuggets/hash/unroll.rb +0 -5
- data/lib/nuggets/hash/unroll_mixin.rb +0 -89
- data/lib/nuggets/hash/zip.rb +0 -5
- data/lib/nuggets/hash/zip_mixin.rb +0 -160
- data/lib/nuggets/i18n.rb +0 -156
- data/lib/nuggets/integer/factorial.rb +0 -57
- data/lib/nuggets/integer/length.rb +0 -5
- data/lib/nuggets/integer/length_mixin.rb +0 -50
- data/lib/nuggets/integer/map.rb +0 -5
- data/lib/nuggets/integer/map_mixin.rb +0 -43
- data/lib/nuggets/integer/to_binary_s.rb +0 -39
- data/lib/nuggets/io/agrep.rb +0 -44
- data/lib/nuggets/io/interact.rb +0 -5
- data/lib/nuggets/io/interact_mixin.rb +0 -160
- data/lib/nuggets/io/modes.rb +0 -122
- data/lib/nuggets/io/null.rb +0 -5
- data/lib/nuggets/io/null_mixin.rb +0 -41
- data/lib/nuggets/io/redirect.rb +0 -5
- data/lib/nuggets/io/redirect_mixin.rb +0 -51
- data/lib/nuggets/lazy_attr.rb +0 -45
- data/lib/nuggets/log_parser.rb +0 -71
- data/lib/nuggets/log_parser/apache.rb +0 -102
- data/lib/nuggets/log_parser/rails.rb +0 -220
- data/lib/nuggets/lsi.rb +0 -8
- data/lib/nuggets/midos.rb +0 -8
- data/lib/nuggets/mysql.rb +0 -8
- data/lib/nuggets/net/success.rb +0 -60
- data/lib/nuggets/numeric/between.rb +0 -2
- data/lib/nuggets/numeric/duration.rb +0 -101
- data/lib/nuggets/numeric/limit.rb +0 -63
- data/lib/nuggets/numeric/signum.rb +0 -53
- data/lib/nuggets/numeric/to_multiple.rb +0 -62
- data/lib/nuggets/object/blank.rb +0 -20
- data/lib/nuggets/object/blank_mixin.rb +0 -100
- data/lib/nuggets/object/boolean.rb +0 -5
- data/lib/nuggets/object/boolean_mixin.rb +0 -62
- data/lib/nuggets/object/eigenclass.rb +0 -2
- data/lib/nuggets/object/ghost_class.rb +0 -2
- data/lib/nuggets/object/metaclass.rb +0 -2
- data/lib/nuggets/object/msend.rb +0 -5
- data/lib/nuggets/object/msend_mixin.rb +0 -44
- data/lib/nuggets/object/silence.rb +0 -5
- data/lib/nuggets/object/silence_mixin.rb +0 -45
- data/lib/nuggets/object/singleton_class.rb +0 -5
- data/lib/nuggets/object/singleton_class_mixin.rb +0 -96
- data/lib/nuggets/object/uniclass.rb +0 -2
- data/lib/nuggets/object/virtual_class.rb +0 -2
- data/lib/nuggets/pluggable.rb +0 -92
- data/lib/nuggets/proc/bind.rb +0 -5
- data/lib/nuggets/proc/bind_mixin.rb +0 -52
- data/lib/nuggets/range/quantile.rb +0 -5
- data/lib/nuggets/range/quantile_mixin.rb +0 -43
- data/lib/nuggets/rdf/compression.rb +0 -6
- data/lib/nuggets/rdf/prefix.rb +0 -6
- data/lib/nuggets/rdf/turtle.rb +0 -8
- data/lib/nuggets/rdf/turtle/reader.rb +0 -6
- data/lib/nuggets/rdf/uri.rb +0 -6
- data/lib/nuggets/ruby.rb +0 -236
- data/lib/nuggets/statistics.rb +0 -12
- data/lib/nuggets/statistics_mixins.rb +0 -12
- data/lib/nuggets/string/camelscore.rb +0 -5
- data/lib/nuggets/string/camelscore_mixin.rb +0 -117
- data/lib/nuggets/string/capitalize_first.rb +0 -47
- data/lib/nuggets/string/case.rb +0 -82
- data/lib/nuggets/string/evaluate.rb +0 -5
- data/lib/nuggets/string/evaluate_mixin.rb +0 -48
- data/lib/nuggets/string/msub.rb +0 -85
- data/lib/nuggets/string/nsub.rb +0 -66
- data/lib/nuggets/string/sub_with_md.rb +0 -112
- data/lib/nuggets/string/wc.rb +0 -5
- data/lib/nuggets/string/wc_mixin.rb +0 -96
- data/lib/nuggets/string/word_wrap.rb +0 -77
- data/lib/nuggets/string/xor.rb +0 -5
- data/lib/nuggets/string/xor_mixin.rb +0 -60
- data/lib/nuggets/tempfile/open.rb +0 -58
- data/lib/nuggets/uri/content_type.rb +0 -5
- data/lib/nuggets/uri/content_type_mixin.rb +0 -48
- data/lib/nuggets/uri/exist.rb +0 -5
- data/lib/nuggets/uri/exist_mixin.rb +0 -57
- data/lib/nuggets/uri/redirect.rb +0 -5
- data/lib/nuggets/uri/redirect_mixin.rb +0 -102
- data/lib/nuggets/util/ansicolor2css.rb +0 -4
- data/lib/nuggets/util/cli.rb +0 -4
- data/lib/nuggets/util/content_type.rb +0 -4
- data/lib/nuggets/util/dotted_decimal.rb +0 -3
- data/lib/nuggets/util/i18n.rb +0 -4
- data/lib/nuggets/util/lazy_attr.rb +0 -4
- data/lib/nuggets/util/log_parser.rb +0 -4
- data/lib/nuggets/util/log_parser/apache.rb +0 -4
- data/lib/nuggets/util/log_parser/rails.rb +0 -4
- data/lib/nuggets/util/midos.rb +0 -4
- data/lib/nuggets/util/mysql.rb +0 -4
- data/lib/nuggets/util/pluggable.rb +0 -4
- data/lib/nuggets/util/ruby.rb +0 -4
- data/lib/nuggets/version.rb +0 -27
- data/spec/nuggets/array/boost_spec.rb +0 -50
- data/spec/nuggets/array/combination_spec.rb +0 -25
- data/spec/nuggets/array/correlation_spec.rb +0 -81
- data/spec/nuggets/array/flatten_once_spec.rb +0 -16
- data/spec/nuggets/array/flush_spec.rb +0 -43
- data/spec/nuggets/array/format_spec.rb +0 -52
- data/spec/nuggets/array/hashify_spec.rb +0 -41
- data/spec/nuggets/array/histogram_spec.rb +0 -87
- data/spec/nuggets/array/in_order_spec.rb +0 -13
- data/spec/nuggets/array/limit_spec.rb +0 -62
- data/spec/nuggets/array/mean_spec.rb +0 -203
- data/spec/nuggets/array/median_spec.rb +0 -77
- data/spec/nuggets/array/mode_spec.rb +0 -57
- data/spec/nuggets/array/monotone_spec.rb +0 -30
- data/spec/nuggets/array/only_spec.rb +0 -26
- data/spec/nuggets/array/regression_spec.rb +0 -54
- data/spec/nuggets/array/runiq_spec.rb +0 -25
- data/spec/nuggets/array/standard_deviation_spec.rb +0 -33
- data/spec/nuggets/array/to_hash_spec.rb +0 -28
- data/spec/nuggets/array/variance_spec.rb +0 -106
- data/spec/nuggets/dotted_decimal_spec.rb +0 -27
- data/spec/nuggets/enumerable/all_any_extended_spec.rb +0 -31
- data/spec/nuggets/enumerable/minmax_spec.rb +0 -21
- data/spec/nuggets/env/set_spec.rb +0 -29
- data/spec/nuggets/env/user_encoding_spec.rb +0 -38
- data/spec/nuggets/env/user_home_spec.rb +0 -42
- data/spec/nuggets/file/ext_spec.rb +0 -38
- data/spec/nuggets/file/replace_spec.rb +0 -95
- data/spec/nuggets/file/sub_spec.rb +0 -149
- data/spec/nuggets/file/which_spec.rb +0 -22
- data/spec/nuggets/hash/at_spec.rb +0 -19
- data/spec/nuggets/hash/deep_fetch_spec.rb +0 -159
- data/spec/nuggets/hash/deep_merge_spec.rb +0 -78
- data/spec/nuggets/hash/in_order_spec.rb +0 -12
- data/spec/nuggets/hash/insert_spec.rb +0 -13
- data/spec/nuggets/hash/nest_spec.rb +0 -102
- data/spec/nuggets/hash/only_spec.rb +0 -29
- data/spec/nuggets/hash/seen_spec.rb +0 -36
- data/spec/nuggets/hash/unroll_spec.rb +0 -68
- data/spec/nuggets/i18n_spec.rb +0 -13
- data/spec/nuggets/integer/factorial_spec.rb +0 -10
- data/spec/nuggets/integer/length_spec.rb +0 -18
- data/spec/nuggets/integer/map_spec.rb +0 -19
- data/spec/nuggets/integer/to_binary_s_spec.rb +0 -19
- data/spec/nuggets/numeric/duration_spec.rb +0 -25
- data/spec/nuggets/numeric/limit_spec.rb +0 -16
- data/spec/nuggets/numeric/signum_spec.rb +0 -16
- data/spec/nuggets/numeric/to_multiple_spec.rb +0 -16
- data/spec/nuggets/object/blank_spec.rb +0 -34
- data/spec/nuggets/object/boolean_spec.rb +0 -23
- data/spec/nuggets/object/msend_spec.rb +0 -25
- data/spec/nuggets/object/silence_spec.rb +0 -36
- data/spec/nuggets/object/singleton_class_spec.rb +0 -51
- data/spec/nuggets/proc/bind_spec.rb +0 -28
- data/spec/nuggets/range/quantile_spec.rb +0 -33
- data/spec/nuggets/string/camelscore_spec.rb +0 -114
- data/spec/nuggets/string/capitalize_first_spec.rb +0 -13
- data/spec/nuggets/string/case_spec.rb +0 -31
- data/spec/nuggets/string/evaluate_spec.rb +0 -24
- data/spec/nuggets/string/msub_spec.rb +0 -20
- data/spec/nuggets/string/nsub_spec.rb +0 -13
- data/spec/nuggets/string/sub_with_md_spec.rb +0 -25
- data/spec/nuggets/string/wc_spec.rb +0 -73
- data/spec/nuggets/string/word_wrap_spec.rb +0 -81
- data/spec/nuggets/string/xor_spec.rb +0 -57
- data/spec/nuggets/uri/content_type_spec.rb +0 -42
- data/spec/nuggets/uri/exist_spec.rb +0 -49
- data/spec/spec_helper.rb +0 -36
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'nuggets/file/ext'
|
2
|
-
|
3
|
-
describe_extended File, Nuggets::File::ExtMixin, true do
|
4
|
-
|
5
|
-
[
|
6
|
-
['foo', nil, '.baz'],
|
7
|
-
%w[foo.bar foo .baz],
|
8
|
-
%w[foo.bar.baz foo.bar .baz]
|
9
|
-
].each { |path, new_path, new_ext|
|
10
|
-
example {
|
11
|
-
File.chomp_ext(path).should == (new_path || path)
|
12
|
-
}
|
13
|
-
|
14
|
-
example {
|
15
|
-
File.chomp_ext!(_path = path.dup).should == new_path
|
16
|
-
_path.should == (new_path || path)
|
17
|
-
}
|
18
|
-
|
19
|
-
example {
|
20
|
-
File.sub_ext(path, new_ext).should == (new_path ? "#{new_path}#{new_ext}" : path)
|
21
|
-
}
|
22
|
-
|
23
|
-
example {
|
24
|
-
File.sub_ext!(_path = path.dup, new_ext).should == (new_path && "#{new_path}#{new_ext}")
|
25
|
-
_path.should == (new_path ? "#{new_path}#{new_ext}" : path)
|
26
|
-
}
|
27
|
-
|
28
|
-
example {
|
29
|
-
File.set_ext(path, new_ext).should == "#{new_path || path}#{new_ext}"
|
30
|
-
}
|
31
|
-
|
32
|
-
example {
|
33
|
-
File.set_ext!(_path = path.dup, new_ext).should == "#{new_path || path}#{new_ext}"
|
34
|
-
_path.should == "#{new_path || path}#{new_ext}"
|
35
|
-
}
|
36
|
-
}
|
37
|
-
|
38
|
-
end
|
@@ -1,95 +0,0 @@
|
|
1
|
-
require 'nuggets/file/replace'
|
2
|
-
require 'nuggets/tempfile/open'
|
3
|
-
|
4
|
-
describe_extended File, Nuggets::File::ReplaceMixin, true do
|
5
|
-
|
6
|
-
before :each do
|
7
|
-
@txt = <<-EOT.freeze
|
8
|
-
The fox went out on a chilly night
|
9
|
-
Prayed for the moon to give him light
|
10
|
-
For he had many a mile to go that night
|
11
|
-
Before he reached the town o
|
12
|
-
EOT
|
13
|
-
|
14
|
-
@res1 = <<-EOT.freeze
|
15
|
-
He ran til he came to a great big bin
|
16
|
-
Where the ducks and the geese were kept therein
|
17
|
-
Said, a couple of you are going to grease my chin
|
18
|
-
Before I leave this town o
|
19
|
-
EOT
|
20
|
-
|
21
|
-
@res2 = <<-EOT.freeze
|
22
|
-
THE FOX WENT OUT ON A CHILLY NIGHT
|
23
|
-
PRAYED FOR THE MOON TO GIVE HIM LIGHT
|
24
|
-
FOR HE HAD MANY A MILE TO GO THAT NIGHT
|
25
|
-
BEFORE HE REACHED THE TOWN O
|
26
|
-
EOT
|
27
|
-
end
|
28
|
-
|
29
|
-
example do
|
30
|
-
tempfile { |path|
|
31
|
-
res = File.replace(path) { @res1 }
|
32
|
-
res.should == @res1
|
33
|
-
File.read(path).should == @res1
|
34
|
-
}
|
35
|
-
end
|
36
|
-
|
37
|
-
example do
|
38
|
-
tempfile { |path|
|
39
|
-
res = File.replace(path) { |content| content }
|
40
|
-
res.should == @txt
|
41
|
-
File.read(path).should == @txt
|
42
|
-
}
|
43
|
-
end
|
44
|
-
|
45
|
-
example do
|
46
|
-
tempfile { |path|
|
47
|
-
res = File.replace(path) { |content| @res1 }
|
48
|
-
res.should == @res1
|
49
|
-
File.read(path).should == @res1
|
50
|
-
}
|
51
|
-
end
|
52
|
-
|
53
|
-
example do
|
54
|
-
tempfile { |path|
|
55
|
-
res = File.replace(path) { |content| content.upcase }
|
56
|
-
res.should == @res2
|
57
|
-
File.read(path).should == @res2
|
58
|
-
}
|
59
|
-
end
|
60
|
-
|
61
|
-
example do
|
62
|
-
lambda { File.replace(tempfile) { @res1 } }.should raise_error(Errno::ENOENT)
|
63
|
-
end
|
64
|
-
|
65
|
-
example do
|
66
|
-
begin
|
67
|
-
res = File.replace(path = tempfile, true) { @res1 }
|
68
|
-
res.should == @res1
|
69
|
-
File.read(path).should == @res1
|
70
|
-
ensure
|
71
|
-
File.unlink(path) if path
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
example do
|
76
|
-
begin
|
77
|
-
res = File.replace(path = tempfile, true) { |content| content }
|
78
|
-
res.should == ''
|
79
|
-
File.read(path).should == ''
|
80
|
-
ensure
|
81
|
-
File.unlink(path) if path
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
example do
|
86
|
-
begin
|
87
|
-
res = File.replace(path = tempfile, true) { |content| @res1 }
|
88
|
-
res.should == @res1
|
89
|
-
File.read(path).should == @res1
|
90
|
-
ensure
|
91
|
-
File.unlink(path) if path
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
end
|
@@ -1,149 +0,0 @@
|
|
1
|
-
require 'nuggets/file/sub'
|
2
|
-
require 'nuggets/tempfile/open'
|
3
|
-
|
4
|
-
describe_extended File, Nuggets::File::SubMixin, true do
|
5
|
-
|
6
|
-
before :each do
|
7
|
-
@txt = <<-EOT.freeze
|
8
|
-
The fox went out on a chilly night
|
9
|
-
Prayed for the moon to give him light
|
10
|
-
For he had many a mile to go that night
|
11
|
-
Before he reached the town o
|
12
|
-
EOT
|
13
|
-
|
14
|
-
@res1 = <<-EOT.freeze
|
15
|
-
The fox went out on a chilly nXIGHTX
|
16
|
-
Prayed for the moon to give him light
|
17
|
-
For he had many a mile to go that night
|
18
|
-
Before he reached the town o
|
19
|
-
EOT
|
20
|
-
|
21
|
-
@res2 = <<-EOT.freeze
|
22
|
-
The fox went out on a chilly nXIGHTX
|
23
|
-
Prayed for the moon to give him lXIGHTX
|
24
|
-
For he had many a mile to go that nXIGHTX
|
25
|
-
Before he reached the town o
|
26
|
-
EOT
|
27
|
-
end
|
28
|
-
|
29
|
-
example do
|
30
|
-
tempfile { |path|
|
31
|
-
res = File.sub(path, /ight/, 'XIGHTX')
|
32
|
-
res.should == @res1
|
33
|
-
@txt.should_not == @res1
|
34
|
-
File.read(path).should == @txt
|
35
|
-
}
|
36
|
-
end
|
37
|
-
|
38
|
-
example do
|
39
|
-
tempfile { |path|
|
40
|
-
res = File.sub(path, /XightX/, 'xIGHTx')
|
41
|
-
res.should == @txt
|
42
|
-
File.read(path).should == @txt
|
43
|
-
}
|
44
|
-
end
|
45
|
-
|
46
|
-
example do
|
47
|
-
tempfile { |path|
|
48
|
-
res = File.sub(path, /ight/) { |m| "X#{m.upcase}X" }
|
49
|
-
res.should == @res1
|
50
|
-
@txt.should_not == @res1
|
51
|
-
File.read(path).should == @txt
|
52
|
-
}
|
53
|
-
end
|
54
|
-
|
55
|
-
example do
|
56
|
-
tempfile { |path|
|
57
|
-
res = File.sub(path, /XightX/) { |m| "x#{m.upcase}x" }
|
58
|
-
res.should == @txt
|
59
|
-
File.read(path).should == @txt
|
60
|
-
}
|
61
|
-
end
|
62
|
-
|
63
|
-
example do
|
64
|
-
tempfile { |path|
|
65
|
-
res = File.gsub(path, /ight/, 'XIGHTX')
|
66
|
-
res.should == @res2
|
67
|
-
@txt.should_not == @res2
|
68
|
-
File.read(path).should == @txt
|
69
|
-
}
|
70
|
-
end
|
71
|
-
|
72
|
-
example do
|
73
|
-
tempfile { |path|
|
74
|
-
res = File.gsub(path, /ight/) { |m| "X#{m.upcase}X" }
|
75
|
-
res.should == @res2
|
76
|
-
@txt.should_not == @res2
|
77
|
-
File.read(path).should == @txt
|
78
|
-
}
|
79
|
-
end
|
80
|
-
|
81
|
-
example do
|
82
|
-
tempfile { |path|
|
83
|
-
res = File.sub!(path, /ight/, 'XIGHTX')
|
84
|
-
res.should == @res1
|
85
|
-
@txt.should_not == @res1
|
86
|
-
File.read(path).should == @res1
|
87
|
-
}
|
88
|
-
end
|
89
|
-
|
90
|
-
example do
|
91
|
-
tempfile { |path|
|
92
|
-
res = File.sub!(path, /XightX/, 'xIGHTx')
|
93
|
-
res.should be_nil
|
94
|
-
File.read(path).should == @txt
|
95
|
-
}
|
96
|
-
end
|
97
|
-
|
98
|
-
example do
|
99
|
-
tempfile { |path|
|
100
|
-
res = File.sub!(path, /ight/) { |m| "X#{m.upcase}X" }
|
101
|
-
res.should == @res1
|
102
|
-
@txt.should_not == @res1
|
103
|
-
File.read(path).should == @res1
|
104
|
-
}
|
105
|
-
end
|
106
|
-
|
107
|
-
example do
|
108
|
-
tempfile { |path|
|
109
|
-
res = File.sub!(path, /XightX/) { |m| "x#{m.upcase}x" }
|
110
|
-
res.should be_nil
|
111
|
-
File.read(path).should == @txt
|
112
|
-
}
|
113
|
-
end
|
114
|
-
|
115
|
-
example do
|
116
|
-
tempfile { |path|
|
117
|
-
res = File.gsub!(path, /ight/, 'XIGHTX')
|
118
|
-
res.should == @res2
|
119
|
-
@txt.should_not == @res2
|
120
|
-
File.read(path).should == @res2
|
121
|
-
}
|
122
|
-
end
|
123
|
-
|
124
|
-
example do
|
125
|
-
tempfile { |path|
|
126
|
-
res = File.gsub!(path, /ight/) { |m| "X#{m.upcase}X" }
|
127
|
-
res.should == @res2
|
128
|
-
@txt.should_not == @res2
|
129
|
-
File.read(path).should == @res2
|
130
|
-
}
|
131
|
-
end
|
132
|
-
|
133
|
-
example do
|
134
|
-
lambda { File.sub(tempfile, /ight/, 'XIGHTX') }.should raise_error(Errno::ENOENT)
|
135
|
-
end
|
136
|
-
|
137
|
-
example do
|
138
|
-
lambda { File.sub!(tempfile, /ight/, 'XIGHTX') }.should raise_error(Errno::ENOENT)
|
139
|
-
end
|
140
|
-
|
141
|
-
example do
|
142
|
-
lambda { File.gsub(tempfile, /ight/, 'XIGHTX') }.should raise_error(Errno::ENOENT)
|
143
|
-
end
|
144
|
-
|
145
|
-
example do
|
146
|
-
lambda { File.gsub!(tempfile, /ight/, 'XIGHTX') }.should raise_error(Errno::ENOENT)
|
147
|
-
end
|
148
|
-
|
149
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'nuggets/file/which'
|
2
|
-
|
3
|
-
describe_extended File, Nuggets::File::WhichMixin, true do
|
4
|
-
|
5
|
-
%w[cat dog rat gcc /usr/bin/X11/gcc].each { |c|
|
6
|
-
example do
|
7
|
-
r = %x{which #{c}}.chomp
|
8
|
-
File.which(c).should == (r.empty? ? nil : r)
|
9
|
-
end
|
10
|
-
}
|
11
|
-
|
12
|
-
example do
|
13
|
-
c = [
|
14
|
-
'unison --args source target',
|
15
|
-
'rsync --args source target',
|
16
|
-
'scp --args source target'
|
17
|
-
]
|
18
|
-
r = c.find { |s| !%x{which #{s[/\S+/]}}.chomp.empty? }
|
19
|
-
File.which_command(c).should == r
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'nuggets/hash/at'
|
2
|
-
|
3
|
-
describe Hash, 'at' do
|
4
|
-
|
5
|
-
let(:h) { { :a => 1, 2 => 3, nil => nil, 'foo' => %w[b a r] } }
|
6
|
-
|
7
|
-
example { h.first.should == { a: 1 } }
|
8
|
-
|
9
|
-
example { h.last.should == { 'foo' => %w[b a r] } }
|
10
|
-
|
11
|
-
example { h.rand.should be_a(Hash) }
|
12
|
-
|
13
|
-
example { h.at(0).should == { a: 1 } }
|
14
|
-
|
15
|
-
example { h.at(1).should == { 2 => 3 } }
|
16
|
-
|
17
|
-
example { h.at(-1).should == { 'foo' => %w[b a r] } }
|
18
|
-
|
19
|
-
end
|
@@ -1,159 +0,0 @@
|
|
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
|