royw-roys_extensions 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/VERSION.yml +1 -1
- data/spec/file_extensions_spec.rb +23 -17
- data/spec/kernel_extensions_spec.rb +6 -5
- data/spec/module_extensions_spec.rb +21 -20
- data/spec/numeric_extensions_spec.rb +29 -28
- data/spec/object_extensions_spec.rb +32 -31
- data/spec/string_extensions_spec.rb +40 -21
- metadata +2 -2
data/Rakefile
CHANGED
@@ -20,7 +20,7 @@ require 'spec/rake/spectask'
|
|
20
20
|
Spec::Rake::SpecTask.new(:spec) do |spec|
|
21
21
|
spec.libs << 'lib' << 'spec'
|
22
22
|
spec.spec_files = FileList['spec/**/*_spec.rb']
|
23
|
-
spec.spec_opts = ["--color"]
|
23
|
+
spec.spec_opts = ["--color", "--format nested"]
|
24
24
|
end
|
25
25
|
|
26
26
|
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
data/VERSION.yml
CHANGED
@@ -5,7 +5,7 @@ include FileUtils
|
|
5
5
|
|
6
6
|
TMPDIR = File.join(File.dirname(__FILE__), '../tmp')
|
7
7
|
|
8
|
-
describe "
|
8
|
+
describe "file_extensions" do
|
9
9
|
before(:all) do
|
10
10
|
Dir.mkdir(TMPDIR) unless File.exist?(TMPDIR)
|
11
11
|
end
|
@@ -14,26 +14,32 @@ describe "FileExtensions" do
|
|
14
14
|
rm_rf(Dir.glob(File.join(TMPDIR,'file_extensions_spec*')))
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
describe("File.mkdirs") do
|
18
|
+
it "should make a single directory when it does not exist" do
|
19
|
+
dirspec = get_temp_filename
|
20
|
+
File.mkdirs(dirspec)
|
21
|
+
(File.exist?(dirspec).should be_true) && (File.directory?(dirspec).should be_true)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should make a multiple directories when they do not exist" do
|
25
|
+
dirspec = File.join(get_temp_filename, 'foo', 'bar')
|
26
|
+
File.mkdirs(dirspec)
|
27
|
+
(File.exist?(dirspec).should be_true) && (File.directory?(dirspec).should be_true)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should not make any directories when they already exist" do
|
31
|
+
dirspec = File.join(get_temp_filename, 'foo', 'bar')
|
32
|
+
File.mkdirs(dirspec)
|
33
|
+
File.mkdirs(dirspec)
|
34
|
+
(File.exist?(dirspec).should be_true) && (File.directory?(dirspec).should be_true)
|
35
|
+
end
|
21
36
|
end
|
22
37
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
(File.exist?(dirspec).should be_true) && (File.directory?(dirspec).should be_true)
|
38
|
+
describe("File.touch") do
|
39
|
+
it "should create new file if none exists"
|
40
|
+
it "should change the modification time to the current time for pre-existing file"
|
27
41
|
end
|
28
42
|
|
29
|
-
it "should not make any directories when they already exist" do
|
30
|
-
dirspec = File.join(get_temp_filename, 'foo', 'bar')
|
31
|
-
File.mkdirs(dirspec)
|
32
|
-
File.mkdirs(dirspec)
|
33
|
-
(File.exist?(dirspec).should be_true) && (File.directory?(dirspec).should be_true)
|
34
|
-
end
|
35
|
-
|
36
|
-
|
37
43
|
def get_temp_filename
|
38
44
|
outfile = Tempfile.new('file_extensions_spec', TMPDIR)
|
39
45
|
filespec = outfile.path
|
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
describe "kernel_extensions" do
|
4
|
+
describe "timer" do
|
5
|
+
it "should time a block of code" do
|
6
|
+
elapse = timer { sleep 1.1 }
|
7
|
+
(elapse.should > 1) && (elapse.should < 2)
|
8
|
+
end
|
7
9
|
end
|
8
|
-
|
9
10
|
end
|
@@ -1,34 +1,35 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'ruby-debug'
|
3
3
|
|
4
|
-
describe "
|
5
|
-
|
6
|
-
class
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
describe "module_extensions" do
|
5
|
+
describe "my_extension" do
|
6
|
+
it "should allow a method to be added to a class when the method does not already exists" do
|
7
|
+
class A
|
8
|
+
my_extension("foo") do
|
9
|
+
def foo
|
10
|
+
'foo'
|
11
|
+
end
|
10
12
|
end
|
11
13
|
end
|
14
|
+
A.instance_methods.include?('foo').should be_true
|
12
15
|
end
|
13
|
-
A.instance_methods.include?('foo').should be_true
|
14
|
-
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
it "should not allow adding a method to a class if the method already exists" do
|
18
|
+
class A
|
19
|
+
def foo
|
20
|
+
'bar'
|
21
|
+
end
|
20
22
|
end
|
21
|
-
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
class A
|
25
|
+
my_extension("foo") do
|
26
|
+
def foo
|
27
|
+
'foo'
|
28
|
+
end
|
27
29
|
end
|
28
30
|
end
|
31
|
+
a = A.new
|
32
|
+
a.foo.should == 'bar'
|
29
33
|
end
|
30
|
-
a = A.new
|
31
|
-
a.foo.should == 'bar'
|
32
34
|
end
|
33
|
-
|
34
35
|
end
|
@@ -1,41 +1,42 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
describe "numeric_extensions" do
|
4
|
+
describe "elapsed_time" do
|
5
|
+
it "should convert 0 seconds to '00:00:00'" do
|
6
|
+
0.elapsed_time_s.should == '00:00:00'
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
it "should convert 59 seconds to '00:00:59'" do
|
10
|
+
59.elapsed_time_s.should == '00:00:59'
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
it "should convert 60 seconds to '00:01:00'" do
|
14
|
+
60.elapsed_time_s.should == '00:01:00'
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
it "should convert 3599 seconds to '00:59:59'" do
|
18
|
+
3599.elapsed_time_s.should == '00:59:59'
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
it "should convert 3600 seconds to '01:00:00'" do
|
22
|
+
3600.elapsed_time_s.should == '01:00:00'
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
it "should convert 86399 seconds to '23:59:59'" do
|
26
|
+
86399.elapsed_time_s.should == '23:59:59'
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
it "should convert 86400 seconds to '24:00:00'" do
|
30
|
+
86400.elapsed_time_s.should == '24:00:00'
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
it "should convert 359999 seconds to '99:59:59'" do
|
34
|
+
359999.elapsed_time_s.should == '99:59:59'
|
35
|
+
end
|
35
36
|
|
36
|
-
|
37
|
-
|
37
|
+
it "should convert 360000 seconds to '100:00:00'" do
|
38
|
+
360000.elapsed_time_s.should == '100:00:00'
|
39
|
+
end
|
38
40
|
end
|
39
41
|
|
40
|
-
|
41
42
|
end
|
@@ -1,44 +1,45 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
describe "object_extensions" do
|
4
|
+
describe "blank?" do
|
5
|
+
it "should be blank for nil" do
|
6
|
+
nil.blank?.should be_true
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
it "should be blank for empty String" do
|
10
|
+
''.blank?.should be_true
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
it "should be blank for pure white space String" do
|
14
|
+
' '.blank?.should be_true
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
it "should be blank for empty Array" do
|
18
|
+
[].blank?.should be_true
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
it "should be blank for Array of nils" do
|
22
|
+
[nil, nil].blank?.should be_true
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
it "should be blank for empty Hash" do
|
26
|
+
{}.blank?.should be_true
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
it "should not be blank for non-empty String" do
|
30
|
+
' foo '.blank?.should be_false
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
it "should not be blank for non-empty Array" do
|
34
|
+
[1].blank?.should be_false
|
35
|
+
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
it "should not be blank for empty embedded Arrays" do
|
38
|
+
[[]].blank?.should be_false
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
41
|
+
it "should not be blank for non-empty Hash" do
|
42
|
+
{:a => nil}.blank?.should be_false
|
43
|
+
end
|
42
44
|
end
|
43
|
-
|
44
45
|
end
|
@@ -1,34 +1,53 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
describe "StringExtensions" do
|
5
|
-
it "should escape unicode binary in URL strings to %xx notation" do
|
6
|
-
s = "http://www.themoviedb.org/image/backdrops/23357/W\303\244hrend_Du_schliefst.jpg"
|
7
|
-
s.escape_unicode.should == "http://www.themoviedb.org/image/backdrops/23357/W%c3%a4hrend_Du_schliefst.jpg"
|
8
|
-
end
|
3
|
+
describe "string_extensions" do
|
9
4
|
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
describe "escape_unicode" do
|
6
|
+
it "should escape unicode binary in URL strings to %xx notation" do
|
7
|
+
s = "http://www.themoviedb.org/image/backdrops/23357/W\303\244hrend_Du_schliefst.jpg"
|
8
|
+
s.escape_unicode.should == "http://www.themoviedb.org/image/backdrops/23357/W%c3%a4hrend_Du_schliefst.jpg"
|
9
|
+
end
|
13
10
|
end
|
14
11
|
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
describe "strip_tags" do
|
13
|
+
it "should strip angle bracket tags" do
|
14
|
+
s = 'Now is the <b>time</b> for all <i>good</i> Aggies'
|
15
|
+
s.strip_tags.should == 'Now is the time for all good Aggies'
|
16
|
+
end
|
18
17
|
end
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
describe "ext" do
|
20
|
+
it "should replace file extension" do
|
21
|
+
s = 'a/b.c'
|
22
|
+
s.ext('d').should == 'a/b.d'
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should replace only the last file extension in the string" do
|
26
|
+
s = 'a.b.c'
|
27
|
+
s.ext('d').should == 'a.b.d'
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should append file extension when there is not one" do
|
31
|
+
s = 'a/b/c'
|
32
|
+
s.ext('d').should == 'a/b/c.d'
|
33
|
+
end
|
23
34
|
end
|
24
35
|
|
25
|
-
|
26
|
-
|
27
|
-
|
36
|
+
describe "remove_punctuation" do
|
37
|
+
it "should remove punctuation for a file name" do
|
38
|
+
s = '*abc?:!",.-/~;@#$%^def' + "\'ghi"
|
39
|
+
s.remove_punctuation.should == 'abc def ghi'
|
40
|
+
end
|
28
41
|
end
|
29
42
|
|
30
|
-
|
31
|
-
|
32
|
-
|
43
|
+
describe "unescape_html" do
|
44
|
+
it "should convert & to &" do
|
45
|
+
"M&M".unescape_html.should == 'M&M'
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should convert ó to ó" do
|
49
|
+
"ósmosis".unescape_html.should == 'ósmosis'
|
50
|
+
end
|
33
51
|
end
|
52
|
+
|
34
53
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: royw-roys_extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roy Wright
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-04-
|
12
|
+
date: 2009-04-24 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|