rubycut-babushka 0.10.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +8 -0
- data/Gemfile.lock +31 -0
- data/README.markdown +246 -0
- data/Rakefile +26 -0
- data/bin/babushka +11 -0
- data/deps/babushka.rb +101 -0
- data/deps/dev.rb +12 -0
- data/deps/fhs.rb +31 -0
- data/deps/git.rb +29 -0
- data/deps/homebrew.rb +30 -0
- data/deps/os_x.rb +33 -0
- data/deps/packages.rb +22 -0
- data/deps/pkg_managers.rb +110 -0
- data/deps/ruby.rb +23 -0
- data/deps/rubygems.rb +24 -0
- data/deps/system.rb +10 -0
- data/deps/templates/app.rb +68 -0
- data/deps/templates/external.rb +12 -0
- data/deps/templates/installer.rb +31 -0
- data/deps/templates/managed.rb +105 -0
- data/deps/templates/ppa.rb +24 -0
- data/deps/templates/src.rb +42 -0
- data/deps/templates/tmbundle.rb +15 -0
- data/lib/babushka.rb +28 -0
- data/lib/babushka/accepts_block_for.rb +72 -0
- data/lib/babushka/accepts_list_for.rb +49 -0
- data/lib/babushka/accepts_value_for.rb +24 -0
- data/lib/babushka/base.rb +78 -0
- data/lib/babushka/bug_reporter.rb +55 -0
- data/lib/babushka/cmdline.rb +133 -0
- data/lib/babushka/cmdline/handler.rb +41 -0
- data/lib/babushka/cmdline/helpers.rb +127 -0
- data/lib/babushka/cmdline/parser.rb +69 -0
- data/lib/babushka/colorizer.rb +59 -0
- data/lib/babushka/core_patches/array.rb +171 -0
- data/lib/babushka/core_patches/blank.rb +22 -0
- data/lib/babushka/core_patches/bytes.rb +52 -0
- data/lib/babushka/core_patches/hash.rb +107 -0
- data/lib/babushka/core_patches/hashish.rb +14 -0
- data/lib/babushka/core_patches/integer.rb +25 -0
- data/lib/babushka/core_patches/io.rb +8 -0
- data/lib/babushka/core_patches/numeric.rb +16 -0
- data/lib/babushka/core_patches/object.rb +27 -0
- data/lib/babushka/core_patches/string.rb +116 -0
- data/lib/babushka/core_patches/symbol.rb +12 -0
- data/lib/babushka/core_patches/try.rb +15 -0
- data/lib/babushka/core_patches/uri.rb +24 -0
- data/lib/babushka/dep.rb +470 -0
- data/lib/babushka/dep_context.rb +18 -0
- data/lib/babushka/dep_definer.rb +115 -0
- data/lib/babushka/dep_pool.rb +49 -0
- data/lib/babushka/dep_runner.rb +85 -0
- data/lib/babushka/dsl.rb +26 -0
- data/lib/babushka/git_repo.rb +185 -0
- data/lib/babushka/helpers/git_helpers.rb +32 -0
- data/lib/babushka/helpers/log_helpers.rb +176 -0
- data/lib/babushka/helpers/path_helpers.rb +34 -0
- data/lib/babushka/helpers/run_helpers.rb +145 -0
- data/lib/babushka/helpers/shell_helpers.rb +229 -0
- data/lib/babushka/helpers/suggest_helpers.rb +16 -0
- data/lib/babushka/helpers/uri_helpers.rb +36 -0
- data/lib/babushka/ip.rb +160 -0
- data/lib/babushka/lambda_chooser.rb +40 -0
- data/lib/babushka/levenshtein.rb +125 -0
- data/lib/babushka/meta_dep.rb +65 -0
- data/lib/babushka/meta_dep_context.rb +15 -0
- data/lib/babushka/parameter.rb +143 -0
- data/lib/babushka/pkg_helper.rb +81 -0
- data/lib/babushka/pkg_helpers/apt_helper.rb +61 -0
- data/lib/babushka/pkg_helpers/base_helper.rb +19 -0
- data/lib/babushka/pkg_helpers/binpkgsrc_helper.rb +48 -0
- data/lib/babushka/pkg_helpers/binports_helper.rb +34 -0
- data/lib/babushka/pkg_helpers/brew_helper.rb +110 -0
- data/lib/babushka/pkg_helpers/gem_helper.rb +120 -0
- data/lib/babushka/pkg_helpers/macports_helper.rb +22 -0
- data/lib/babushka/pkg_helpers/npm_helper.rb +45 -0
- data/lib/babushka/pkg_helpers/pacman_helper.rb +27 -0
- data/lib/babushka/pkg_helpers/pip_helper.rb +45 -0
- data/lib/babushka/pkg_helpers/src_helper.rb +16 -0
- data/lib/babushka/pkg_helpers/yum_helper.rb +25 -0
- data/lib/babushka/popen.rb +40 -0
- data/lib/babushka/prompt.rb +176 -0
- data/lib/babushka/renderable.rb +67 -0
- data/lib/babushka/resource.rb +215 -0
- data/lib/babushka/run_reporter.rb +60 -0
- data/lib/babushka/shell.rb +108 -0
- data/lib/babushka/source.rb +216 -0
- data/lib/babushka/source_pool.rb +146 -0
- data/lib/babushka/system_definitions.rb +97 -0
- data/lib/babushka/system_profile.rb +210 -0
- data/lib/babushka/task.rb +142 -0
- data/lib/babushka/vars.rb +108 -0
- data/lib/babushka/version_of.rb +65 -0
- data/lib/babushka/version_str.rb +57 -0
- data/lib/babushka/xml_string.rb +28 -0
- data/lib/components.rb +82 -0
- data/lib/fancypath/fancypath.rb +200 -0
- data/lib/inkan/inkan.rb +76 -0
- data/spec/acceptance/acceptance.rb +43 -0
- data/spec/acceptance_helper.rb +113 -0
- data/spec/archives/Blah.app.zip +0 -0
- data/spec/archives/archive.tar +0 -0
- data/spec/archives/archive.tar.bz2 +0 -0
- data/spec/archives/archive.tar.gz +0 -0
- data/spec/archives/archive.tbz2 +0 -0
- data/spec/archives/archive.tgz +0 -0
- data/spec/archives/archive.zip +0 -0
- data/spec/archives/content.txt +5 -0
- data/spec/archives/invalid_archive +5 -0
- data/spec/archives/nested archive/content.txt +5 -0
- data/spec/archives/nested_archive.tar +0 -0
- data/spec/archives/really_a_gzip.zip +0 -0
- data/spec/archives/test-0.3.1.tgz +0 -0
- data/spec/archives/tgz_archive +0 -0
- data/spec/archives/zip_without_extension +0 -0
- data/spec/babushka/accepts_for_spec.rb +174 -0
- data/spec/babushka/accepts_for_support.rb +72 -0
- data/spec/babushka/cmdline/console_spec.rb +11 -0
- data/spec/babushka/cmdline/help_spec.rb +61 -0
- data/spec/babushka/cmdline/version_spec.rb +10 -0
- data/spec/babushka/core_patches_spec.rb +171 -0
- data/spec/babushka/dep_context_spec.rb +58 -0
- data/spec/babushka/dep_definer_spec.rb +152 -0
- data/spec/babushka/dep_definer_support.rb +36 -0
- data/spec/babushka/dep_spec.rb +567 -0
- data/spec/babushka/dep_support.rb +29 -0
- data/spec/babushka/deps_spec.rb +113 -0
- data/spec/babushka/gem_helper_spec.rb +90 -0
- data/spec/babushka/git_repo_spec.rb +396 -0
- data/spec/babushka/ip_spec.rb +131 -0
- data/spec/babushka/lambda_chooser_spec.rb +115 -0
- data/spec/babushka/meta_dep_definer_spec.rb +127 -0
- data/spec/babushka/meta_dep_wrapper_spec.rb +32 -0
- data/spec/babushka/parameter_spec.rb +135 -0
- data/spec/babushka/path_helpers_spec.rb +102 -0
- data/spec/babushka/prompt_spec.rb +188 -0
- data/spec/babushka/renderable_spec.rb +100 -0
- data/spec/babushka/resource_spec.rb +141 -0
- data/spec/babushka/run_helpers_spec.rb +26 -0
- data/spec/babushka/shell_helpers_spec.rb +244 -0
- data/spec/babushka/shell_spec.rb +19 -0
- data/spec/babushka/source_pool_spec.rb +320 -0
- data/spec/babushka/source_pool_support.rb +31 -0
- data/spec/babushka/source_spec.rb +382 -0
- data/spec/babushka/source_support.rb +17 -0
- data/spec/babushka/system_profile_spec.rb +61 -0
- data/spec/babushka/task_spec.rb +141 -0
- data/spec/babushka/uri_spec.rb +13 -0
- data/spec/babushka/vars_spec.rb +59 -0
- data/spec/babushka/version_of_spec.rb +110 -0
- data/spec/babushka/version_str_spec.rb +130 -0
- data/spec/babushka/version_str_support.rb +37 -0
- data/spec/babushka/xml_string_spec.rb +98 -0
- data/spec/deps/bad/broken.rb +7 -0
- data/spec/deps/bad/working.rb +3 -0
- data/spec/deps/good/meta.rb +14 -0
- data/spec/deps/good/test.rb +11 -0
- data/spec/deps/outer/deps.rb +19 -0
- data/spec/deps/outer/more deps.rb +11 -0
- data/spec/deps/params/params.rb +10 -0
- data/spec/fancypath/fancypath_spec.rb +272 -0
- data/spec/fancypath_support.rb +10 -0
- data/spec/inkan/inkan_spec.rb +217 -0
- data/spec/renderable/different_example.conf.erb +4 -0
- data/spec/renderable/example.conf.erb +3 -0
- data/spec/renderable/example.sh +6 -0
- data/spec/renderable/with_binding.conf.erb +4 -0
- data/spec/renderable/xml_example.conf.erb +8 -0
- data/spec/repos/remote.git.tgz +0 -0
- data/spec/spec_helper.rb +87 -0
- metadata +238 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
def pairs
|
2
|
+
[
|
3
|
+
%w[0.3.1 0.3.1],
|
4
|
+
%w[0.3.1 0.3.2],
|
5
|
+
%w[0.3.1 0.3.1.10],
|
6
|
+
%w[0.3.1.1 0.3.1.10],
|
7
|
+
%w[0.3.1.9 0.3.1.10],
|
8
|
+
%w[0.3.1.9 0.3.0.10],
|
9
|
+
%w[0.3.1 0.3.0.10],
|
10
|
+
%w[0.3.1.9 1],
|
11
|
+
%w[0.3.1.9 0.4],
|
12
|
+
%w[0.3.1.9 0.3.2],
|
13
|
+
%w[0.3.1.9 0.3.0],
|
14
|
+
%w[1 0.3.1.9],
|
15
|
+
%w[0.4 0.3.1.9],
|
16
|
+
%w[0.3.2 0.3.1.9],
|
17
|
+
%w[0.3.2 0.3.1],
|
18
|
+
%w[0.3.1.10 0.3.1.9],
|
19
|
+
%w[0.3.1 0.3],
|
20
|
+
%w[0.3.1 0.4],
|
21
|
+
]
|
22
|
+
end
|
23
|
+
|
24
|
+
def t; true end
|
25
|
+
def f; false end
|
26
|
+
|
27
|
+
def results
|
28
|
+
{
|
29
|
+
"==" => [t, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f],
|
30
|
+
"!=" => [f, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t],
|
31
|
+
">" => [f, f, f, f, f, t, t, f, f, f, t, t, t, t, t, t, t, f],
|
32
|
+
"<" => [f, t, t, t, t, f, f, t, t, t, f, f, f, f, f, f, f, t],
|
33
|
+
">=" => [t, f, f, f, f, t, t, f, f, f, t, t, t, t, t, t, t, f],
|
34
|
+
"<=" => [t, t, t, t, t, f, f, t, t, t, f, f, f, f, f, f, f, t],
|
35
|
+
"~>" => [t, f, f, f, f, f, f, f, f, f, t, f, f, f, t, t, t, f]
|
36
|
+
}
|
37
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe XMLString do
|
4
|
+
it "should parse xml like a son of a bitch" do
|
5
|
+
sample_xml.val_for('CFBundleShortVersionString').should == '5.0.310.0'
|
6
|
+
sample_xml.val_for('CFBundleSignature').should == 'Cr24 Example String'
|
7
|
+
sample_xml.val_for('SVNRevision').should == '37609'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def sample_xml
|
12
|
+
XMLString.new %Q{
|
13
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
14
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
15
|
+
<plist version="1.0">
|
16
|
+
<dict>
|
17
|
+
<key>CFBundleExecutable</key>
|
18
|
+
<string>Chromium</string>
|
19
|
+
<key>CFBundleIconFile</key>
|
20
|
+
<string>app.icns</string>
|
21
|
+
<key>CFBundleIdentifier</key>
|
22
|
+
<string>org.chromium.Chromium</string>
|
23
|
+
<key>CFBundleInfoDictionaryVersion</key>
|
24
|
+
<string>6.0</string>
|
25
|
+
<key>CFBundleName</key>
|
26
|
+
<string>Chromium</string>
|
27
|
+
<key>CFBundlePackageType</key>
|
28
|
+
<string>APPL</string>
|
29
|
+
<key>CFBundleShortVersionString</key>
|
30
|
+
<string>5.0.310.0</string>
|
31
|
+
<key>CFBundleSignature</key>
|
32
|
+
<string>Cr24 Example String</string>
|
33
|
+
<key>CFBundleURLTypes</key>
|
34
|
+
<array>
|
35
|
+
<dict>
|
36
|
+
<key>CFBundleURLName</key>
|
37
|
+
<string>Web site URL</string>
|
38
|
+
<key>CFBundleURLSchemes</key>
|
39
|
+
<array>
|
40
|
+
<string>http</string>
|
41
|
+
<string>https</string>
|
42
|
+
</array>
|
43
|
+
</dict>
|
44
|
+
<dict>
|
45
|
+
<key>CFBundleURLName</key>
|
46
|
+
<string>FTP site URL</string>
|
47
|
+
<key>CFBundleURLSchemes</key>
|
48
|
+
<array>
|
49
|
+
<string>ftp</string>
|
50
|
+
</array>
|
51
|
+
</dict>
|
52
|
+
<dict>
|
53
|
+
<key>CFBundleURLName</key>
|
54
|
+
<string>Local file URL</string>
|
55
|
+
<key>CFBundleURLSchemes</key>
|
56
|
+
<array>
|
57
|
+
<string>file</string>
|
58
|
+
</array>
|
59
|
+
</dict>
|
60
|
+
</array>
|
61
|
+
<key>CFBundleVersion</key>
|
62
|
+
<string>310.0</string>
|
63
|
+
<key>LSFileQuarantineEnabled</key>
|
64
|
+
<true/>
|
65
|
+
<key>LSHasLocalizedDisplayName</key>
|
66
|
+
<string>1</string>
|
67
|
+
<key>LSMinimumSystemVersion</key>
|
68
|
+
<string>10.5.0</string>
|
69
|
+
<key>NSAppleScriptEnabled</key>
|
70
|
+
<true/>
|
71
|
+
<key>SVNPath</key>
|
72
|
+
<string>/trunk/src</string>
|
73
|
+
<key>SVNRevision</key>
|
74
|
+
<string>37609</string>
|
75
|
+
<key>UTExportedTypeDeclarations</key>
|
76
|
+
<array>
|
77
|
+
<dict>
|
78
|
+
<key>UTTypeConformsTo</key>
|
79
|
+
<array>
|
80
|
+
<string>public.data</string>
|
81
|
+
</array>
|
82
|
+
<key>UTTypeDescription</key>
|
83
|
+
<string>Chromium Extra</string>
|
84
|
+
<key>UTTypeIdentifier</key>
|
85
|
+
<string>org.chromium.extension</string>
|
86
|
+
<key>UTTypeTagSpecification</key>
|
87
|
+
<dict>
|
88
|
+
<key>public.filename-extension</key>
|
89
|
+
<array>
|
90
|
+
<string>crx</string>
|
91
|
+
</array>
|
92
|
+
</dict>
|
93
|
+
</dict>
|
94
|
+
</array>
|
95
|
+
</dict>
|
96
|
+
</plist>
|
97
|
+
}
|
98
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
meta :test_template do
|
2
|
+
accepts_list_for :uri
|
3
|
+
template {
|
4
|
+
requires 'test dep 1'
|
5
|
+
}
|
6
|
+
end
|
7
|
+
|
8
|
+
dep 'option-templated dep', :template => 'test_template' do
|
9
|
+
uri 'http://option.test.org'
|
10
|
+
end
|
11
|
+
|
12
|
+
dep 'suffix-templated dep.test_template' do
|
13
|
+
uri 'http://suffix.test.org'
|
14
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
dep 'test dep 1' do
|
2
|
+
|
3
|
+
end
|
4
|
+
|
5
|
+
dep 'externally templated', :template => 'nested source:test_template' do
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
meta 'local_template' do
|
10
|
+
accepts_list_for :uri
|
11
|
+
end
|
12
|
+
|
13
|
+
dep 'locally templated', :template => 'local_template' do
|
14
|
+
uri 'http://local.test.org'
|
15
|
+
end
|
16
|
+
|
17
|
+
dep 'locally templated.local_template' do
|
18
|
+
uri 'http://local.test.org'
|
19
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
meta 'another_local_template' do
|
2
|
+
accepts_list_for :uri
|
3
|
+
end
|
4
|
+
|
5
|
+
dep 'separate file', :template => 'another_local_template' do
|
6
|
+
uri 'http://option.local.test.org'
|
7
|
+
end
|
8
|
+
|
9
|
+
dep 'separate file.another_local_template' do
|
10
|
+
uri 'http://suffix.local.test.org'
|
11
|
+
end
|
@@ -0,0 +1,272 @@
|
|
1
|
+
require 'fancypath_support'
|
2
|
+
|
3
|
+
describe Fancypath do
|
4
|
+
before do
|
5
|
+
TMP_DIR.rmtree if TMP_DIR.exist?
|
6
|
+
TMP_DIR.mkpath
|
7
|
+
@file = TMP_DIR.to_fancypath/'testfile'
|
8
|
+
@dir = TMP_DIR.to_fancypath/'testdir'
|
9
|
+
end
|
10
|
+
after { TMP_DIR.rmtree }
|
11
|
+
|
12
|
+
describe '#==' do
|
13
|
+
it "should compare properly with other fancypaths" do
|
14
|
+
Fancypath('test').should == Fancypath('test')
|
15
|
+
Fancypath('test').should_not == Fancypath('test2')
|
16
|
+
end
|
17
|
+
it "should compare properly with strings" do
|
18
|
+
Fancypath('test').should == 'test'
|
19
|
+
Fancypath('test').should_not == 'test2'
|
20
|
+
end
|
21
|
+
it "should compare in reverse with strings" do
|
22
|
+
'test'.should == Fancypath('test')
|
23
|
+
'test2'.should_not == Fancypath('test')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#length' do
|
28
|
+
it "should calculate the length" do
|
29
|
+
@file.length.should == @file.to_s.length
|
30
|
+
@file.length.should == File.join(TMP_DIR, 'testfile').length
|
31
|
+
@dir.length.should == File.join(TMP_DIR, 'testdir').length
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#hypothetically_writable?' do
|
36
|
+
it "initial conditions" do
|
37
|
+
@file.should_not be_exists
|
38
|
+
@dir.should_not be_exists
|
39
|
+
@dir.parent.should be_exists
|
40
|
+
@dir.parent.should be_writable
|
41
|
+
end
|
42
|
+
it "returns true for writable paths" do
|
43
|
+
@file.stub!(:writable?).and_return(true)
|
44
|
+
|
45
|
+
@file.should be_hypothetically_writable
|
46
|
+
end
|
47
|
+
it "returns false for existing, nonwritable paths" do
|
48
|
+
@file.stub!(:exists?).and_return(true)
|
49
|
+
@file.stub!(:writable?).and_return(false)
|
50
|
+
|
51
|
+
@file.should_not be_hypothetically_writable
|
52
|
+
end
|
53
|
+
it "returns true for nonexistent paths when the parent is writable" do
|
54
|
+
@file.stub(:parent).and_return(@dir)
|
55
|
+
@dir.stub!(:writable?).and_return(true)
|
56
|
+
dir_parent = @dir.parent
|
57
|
+
dir_parent.stub!(:hypothetically_writable?).and_return(false)
|
58
|
+
@dir.stub!(:parent).and_return(dir_parent)
|
59
|
+
|
60
|
+
subfile = @file / 'subfile'
|
61
|
+
subfile.stub!(:parent).and_return(@file)
|
62
|
+
|
63
|
+
@file.should be_hypothetically_writable
|
64
|
+
subfile.should be_hypothetically_writable
|
65
|
+
end
|
66
|
+
it "returns false for nonexistent paths when the parent isn't writable" do
|
67
|
+
@file.stub(:parent).and_return(@dir)
|
68
|
+
@dir.stub!(:exists?).and_return(true)
|
69
|
+
@dir.stub!(:writable?).and_return(false)
|
70
|
+
|
71
|
+
subfile = @file / 'subfile'
|
72
|
+
subfile.stub!(:parent).and_return(@file)
|
73
|
+
|
74
|
+
@file.should_not be_hypothetically_writable
|
75
|
+
subfile.should_not be_hypothetically_writable
|
76
|
+
end
|
77
|
+
it "works for the root" do
|
78
|
+
@root = '/'.p
|
79
|
+
@root.stub!(:writable?).and_return(false)
|
80
|
+
@root.should_not be_hypothetically_writable
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '#join', 'aliased to #/' do
|
85
|
+
it('returns a Fancypath') { (@dir/'somefile').class.should == Fancypath }
|
86
|
+
it('joins paths') { (@dir/'somefile').to_s.should =~ /\/somefile$/ }
|
87
|
+
it('joins absolute paths') { (@dir/'/somefile').to_s.should == File.join(@dir, 'somefile') }
|
88
|
+
end
|
89
|
+
|
90
|
+
describe '#parent' do
|
91
|
+
it('returns parent') { @file.parent.should == TMP_DIR.to_fancypath }
|
92
|
+
it('returns Fancypath') { @file.parent.should be_instance_of(Fancypath) }
|
93
|
+
end
|
94
|
+
|
95
|
+
describe '#touch', 'file does not exist' do
|
96
|
+
it('returns self') { @file.touch.should == @file }
|
97
|
+
it('returns a Fancypath') { @file.touch.should be_instance_of(Fancypath) }
|
98
|
+
it('creates file') { @file.touch.should be_file }
|
99
|
+
end
|
100
|
+
|
101
|
+
describe '#create', 'dir does not exist' do
|
102
|
+
it('returns self') { @dir.create.should == @dir }
|
103
|
+
it('returns a Fancypath') { @dir.create.should be_instance_of(Fancypath) }
|
104
|
+
it('creates directory') { @dir.create.should be_directory }
|
105
|
+
end
|
106
|
+
|
107
|
+
describe '#remove' do
|
108
|
+
it('returns self') { @file.remove.should == @file }
|
109
|
+
it('returns a Fancypath') { @file.remove.should be_instance_of(Fancypath) }
|
110
|
+
it('removes file') { @file.touch.remove.should_not exist }
|
111
|
+
it('removes directory') { @dir.create.remove.should_not exist }
|
112
|
+
end
|
113
|
+
|
114
|
+
describe '#readlink' do
|
115
|
+
before {
|
116
|
+
@file.touch
|
117
|
+
@dir.mkdir
|
118
|
+
Dir.chdir @dir do
|
119
|
+
`ln -s ../testfile testlink_relative`
|
120
|
+
`ln -s /bin/bash testlink_absolute`
|
121
|
+
end
|
122
|
+
@relative_link = @dir/'testlink_relative'
|
123
|
+
@absolute_link = @dir/'testlink_absolute'
|
124
|
+
}
|
125
|
+
it('returns self for non-symlinks') { @file.readlink.should == @file }
|
126
|
+
it('returns the target for relative symlinks') { @relative_link.readlink.should == @file }
|
127
|
+
it('returns the target for absolute symlinks') { @absolute_link.readlink.should == '/bin/bash' }
|
128
|
+
end
|
129
|
+
|
130
|
+
describe '#mkdir' do
|
131
|
+
before {
|
132
|
+
@mkdir = Fancypath(TMP_DIR/'nested/mkdir')
|
133
|
+
}
|
134
|
+
it "should create directories" do
|
135
|
+
@mkdir.exists?.should == false
|
136
|
+
@mkdir.mkdir
|
137
|
+
@mkdir.exists?.should == true
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe '#glob' do
|
142
|
+
before {
|
143
|
+
@dir.create_dir
|
144
|
+
@file.touch
|
145
|
+
}
|
146
|
+
it "should glob" do
|
147
|
+
TMP_DIR.glob('**/*').should =~ ['tmp/fancypath/testdir'.p.to_s, 'tmp/fancypath/testfile'.p.to_s]
|
148
|
+
end
|
149
|
+
it "should glob with no args" do
|
150
|
+
(TMP_DIR / '**/*').glob.should =~ ['tmp/fancypath/testdir'.p.to_s, 'tmp/fancypath/testfile'.p.to_s]
|
151
|
+
end
|
152
|
+
it "should be case insensitive" do
|
153
|
+
TMP_DIR.glob('**/TEST*').should =~ ['tmp/fancypath/testdir'.p.to_s, 'tmp/fancypath/testfile'.p.to_s]
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
describe '#write' do
|
158
|
+
it('returns self') { @file.write('').should == @file }
|
159
|
+
it('returns a Fancypath') { @file.write('').should be_instance_of(Fancypath) }
|
160
|
+
it('writes contents to file') { @file.write('test').read.should == 'test' }
|
161
|
+
end
|
162
|
+
|
163
|
+
describe '#copy' do
|
164
|
+
before { @file.touch }
|
165
|
+
it('returns a Fancypath') { @file.copy(TMP_DIR/'foo').should be_instance_of(Fancypath) }
|
166
|
+
it('creates a new file') { @file.copy(TMP_DIR/'foo').should exist }
|
167
|
+
it('keeps the original') { @file.copy(TMP_DIR/'foo'); @file.should exist }
|
168
|
+
it('copies the contents') { @file.copy(TMP_DIR/'foo').read.should == @file.read }
|
169
|
+
end
|
170
|
+
|
171
|
+
describe '#copy on a directory' do
|
172
|
+
before {
|
173
|
+
@dir.mkdir
|
174
|
+
(@dir / 'testfile').touch
|
175
|
+
}
|
176
|
+
it('returns a Fancypath') { @dir.copy(TMP_DIR/'foo').should be_instance_of(Fancypath) }
|
177
|
+
it('creates a new dir with a file in it') {
|
178
|
+
@dir.copy(TMP_DIR/'foo')
|
179
|
+
(TMP_DIR/'foo').should exist
|
180
|
+
(TMP_DIR/'foo/testfile').should exist
|
181
|
+
}
|
182
|
+
it('keeps the original') { @dir.copy(TMP_DIR/'foo'); @dir.should exist }
|
183
|
+
it('copies the contents') { @dir.copy(TMP_DIR/'foo'); (TMP_DIR/'foo/testfile').read.should == (@dir/'testfile').read }
|
184
|
+
end
|
185
|
+
|
186
|
+
describe '#set_extension' do
|
187
|
+
example "file without extension" do
|
188
|
+
Fancypath('/tmp/foo').set_extension('rb').should == Fancypath('/tmp/foo.rb')
|
189
|
+
end
|
190
|
+
example "single extension" do
|
191
|
+
Fancypath('/tmp/foo.py').set_extension('rb').should == Fancypath('/tmp/foo.rb')
|
192
|
+
end
|
193
|
+
example "multi extension" do
|
194
|
+
Fancypath('/tmp/foo.py.z').set_extension('rb').should == Fancypath('/tmp/foo.py.rb')
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
describe '#move' do
|
199
|
+
example "destination has the file contents, source does not exist" do
|
200
|
+
@file.write('foo')
|
201
|
+
dest = TMP_DIR/'newfile'
|
202
|
+
@file.move( dest )
|
203
|
+
@file.should_not exist
|
204
|
+
dest.read.should == 'foo'
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
describe '#has_extension?' do
|
209
|
+
example do
|
210
|
+
Fancypath('/tmp/foo.bar').has_extension?('bar').should be_true
|
211
|
+
end
|
212
|
+
example do
|
213
|
+
Fancypath('/tmp/foo.bar').has_extension?('foo').should be_false
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
describe '#select' do
|
218
|
+
example 'with symbol' do
|
219
|
+
@dir.create_dir
|
220
|
+
%W(a.jpg b.jpg c.gif).each { |f| (@dir/f).touch }
|
221
|
+
@dir.select(:jpg).should =~ [@dir/'a.jpg', @dir/'b.jpg']
|
222
|
+
end
|
223
|
+
|
224
|
+
example 'with glob' do
|
225
|
+
@dir.create_dir
|
226
|
+
%W(a.jpg b.jpg c.gif).each { |f| (@dir/f).touch }
|
227
|
+
@dir.select("*.jpg").should =~ [@dir/'a.jpg', @dir/'b.jpg']
|
228
|
+
end
|
229
|
+
|
230
|
+
example 'with regex' do
|
231
|
+
@dir.create_dir
|
232
|
+
%W(a.jpg b.jpg c.gif 1.jpg).each { |f| (@dir/f).touch }
|
233
|
+
@dir.select(/[^\d]\.(jpg|gif)$/).should =~ [@dir/'a.jpg', @dir/'b.jpg', @dir/'c.gif']
|
234
|
+
end
|
235
|
+
|
236
|
+
example 'with multiple args' do
|
237
|
+
@dir.create_dir
|
238
|
+
%W(a.jpg b.jpg c.gif).each { |f| (@dir/f).touch }
|
239
|
+
@dir.select(:jpg, '*.gif').should =~ [@dir/'a.jpg', @dir/'b.jpg', @dir/'c.gif']
|
240
|
+
end
|
241
|
+
|
242
|
+
# todo: with block
|
243
|
+
end
|
244
|
+
|
245
|
+
describe '#empty?' do
|
246
|
+
example 'with empty file' do
|
247
|
+
@file.touch
|
248
|
+
@file.empty?.should be_true
|
249
|
+
end
|
250
|
+
example 'with non-empty file' do
|
251
|
+
@file.write 'foo'
|
252
|
+
@file.empty?.should be_false
|
253
|
+
end
|
254
|
+
example 'with empty dir' do
|
255
|
+
@dir.create_dir
|
256
|
+
@dir.empty?.should be_true
|
257
|
+
end
|
258
|
+
example 'with non-empty dir' do
|
259
|
+
@dir.create_dir
|
260
|
+
(@dir/'foo').touch
|
261
|
+
@dir.empty?.should be_false
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end #/Fancypath
|
265
|
+
|
266
|
+
describe "String#to_fancypath" do
|
267
|
+
it('returns a Fancypath') { 'test'.to_fancypath.should be_instance_of(Fancypath) }
|
268
|
+
end
|
269
|
+
|
270
|
+
describe "Pathname#to_fancypath" do
|
271
|
+
it('returns a Fancypath') { Fancypath.new('/').to_fancypath.should be_instance_of(Fancypath) }
|
272
|
+
end
|