imw 0.1.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.
- data/.gitignore +15 -0
- data/CHANGELOG +0 -0
- data/LICENSE +674 -0
- data/README.rdoc +101 -0
- data/Rakefile +20 -0
- data/VERSION +1 -0
- data/etc/imwrc.rb +76 -0
- data/lib/imw.rb +42 -0
- data/lib/imw/boot.rb +58 -0
- data/lib/imw/dataset.rb +233 -0
- data/lib/imw/dataset/datamapper.rb +66 -0
- data/lib/imw/dataset/datamapper/time_and_user_stamps.rb +37 -0
- data/lib/imw/dataset/loaddump.rb +50 -0
- data/lib/imw/dataset/old/file_collection.rb +88 -0
- data/lib/imw/dataset/old/file_collection_utils.rb +71 -0
- data/lib/imw/dataset/scaffold.rb +132 -0
- data/lib/imw/dataset/scraped_uri.rb +305 -0
- data/lib/imw/dataset/scrub/old_working_scrubber.rb +87 -0
- data/lib/imw/dataset/scrub/scrub.rb +147 -0
- data/lib/imw/dataset/scrub/scrub_simple_url.rb +38 -0
- data/lib/imw/dataset/scrub/scrub_test.rb +60 -0
- data/lib/imw/dataset/scrub/slug.rb +101 -0
- data/lib/imw/dataset/stats.rb +73 -0
- data/lib/imw/dataset/stats/counter.rb +23 -0
- data/lib/imw/dataset/task.rb +38 -0
- data/lib/imw/dataset/workflow.rb +81 -0
- data/lib/imw/files.rb +110 -0
- data/lib/imw/files/archive.rb +113 -0
- data/lib/imw/files/basicfile.rb +122 -0
- data/lib/imw/files/binary.rb +28 -0
- data/lib/imw/files/compressed_file.rb +93 -0
- data/lib/imw/files/compressed_files_and_archives.rb +348 -0
- data/lib/imw/files/compressible.rb +103 -0
- data/lib/imw/files/csv.rb +112 -0
- data/lib/imw/files/json.rb +41 -0
- data/lib/imw/files/sgml.rb +65 -0
- data/lib/imw/files/text.rb +68 -0
- data/lib/imw/files/yaml.rb +46 -0
- data/lib/imw/packagers.rb +8 -0
- data/lib/imw/packagers/archiver.rb +108 -0
- data/lib/imw/packagers/s3_mover.rb +28 -0
- data/lib/imw/parsers.rb +7 -0
- data/lib/imw/parsers/html_parser.rb +382 -0
- data/lib/imw/parsers/html_parser/matchers.rb +306 -0
- data/lib/imw/parsers/line_parser.rb +87 -0
- data/lib/imw/parsers/regexp_parser.rb +72 -0
- data/lib/imw/utils.rb +24 -0
- data/lib/imw/utils/components.rb +61 -0
- data/lib/imw/utils/config.rb +46 -0
- data/lib/imw/utils/error.rb +54 -0
- data/lib/imw/utils/extensions/array.rb +125 -0
- data/lib/imw/utils/extensions/class/attribute_accessors.rb +8 -0
- data/lib/imw/utils/extensions/core.rb +43 -0
- data/lib/imw/utils/extensions/dir.rb +24 -0
- data/lib/imw/utils/extensions/file_core.rb +64 -0
- data/lib/imw/utils/extensions/hash.rb +218 -0
- data/lib/imw/utils/extensions/hpricot.rb +48 -0
- data/lib/imw/utils/extensions/string.rb +49 -0
- data/lib/imw/utils/extensions/struct.rb +42 -0
- data/lib/imw/utils/extensions/symbol.rb +28 -0
- data/lib/imw/utils/extensions/typed_struct.rb +22 -0
- data/lib/imw/utils/extensions/uri.rb +59 -0
- data/lib/imw/utils/log.rb +67 -0
- data/lib/imw/utils/misc.rb +63 -0
- data/lib/imw/utils/paths.rb +115 -0
- data/lib/imw/utils/uri.rb +59 -0
- data/lib/imw/utils/uuid.rb +33 -0
- data/lib/imw/utils/validate.rb +38 -0
- data/lib/imw/utils/version.rb +12 -0
- data/lib/imw/utils/view.rb +113 -0
- data/lib/imw/utils/view/dump_csv.rb +112 -0
- data/lib/imw/utils/view/dump_csv_older.rb +117 -0
- data/spec/data/sample.csv +131 -0
- data/spec/data/sample.tsv +131 -0
- data/spec/data/sample.txt +131 -0
- data/spec/data/sample.xml +653 -0
- data/spec/data/sample.yaml +652 -0
- data/spec/imw/dataset/datamapper/uri_spec.rb +43 -0
- data/spec/imw/dataset/datamapper_spec_helper.rb +11 -0
- data/spec/imw/files/archive_spec.rb +118 -0
- data/spec/imw/files/basicfile_spec.rb +121 -0
- data/spec/imw/files/bz2_spec.rb +32 -0
- data/spec/imw/files/compressed_file_spec.rb +96 -0
- data/spec/imw/files/compressible_spec.rb +100 -0
- data/spec/imw/files/file_spec.rb +144 -0
- data/spec/imw/files/gz_spec.rb +32 -0
- data/spec/imw/files/rar_spec.rb +33 -0
- data/spec/imw/files/tar_spec.rb +31 -0
- data/spec/imw/files/text_spec.rb +23 -0
- data/spec/imw/files/zip_spec.rb +31 -0
- data/spec/imw/files_spec.rb +38 -0
- data/spec/imw/packagers/archiver_spec.rb +125 -0
- data/spec/imw/packagers/s3_mover_spec.rb +7 -0
- data/spec/imw/parsers/line_parser_spec.rb +96 -0
- data/spec/imw/parsers/regexp_parser_spec.rb +42 -0
- data/spec/imw/utils/extensions/file_core_spec.rb +72 -0
- data/spec/imw/utils/extensions/find_spec.rb +113 -0
- data/spec/imw/utils/paths_spec.rb +38 -0
- data/spec/imw/workflow/rip/local_spec.rb +89 -0
- data/spec/imw/workflow/rip_spec.rb +27 -0
- data/spec/rcov.opts +1 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +32 -0
- data/spec/support/archive_contents_matcher.rb +94 -0
- data/spec/support/custom_matchers.rb +21 -0
- data/spec/support/directory_contents_matcher.rb +61 -0
- data/spec/support/extensions.rb +18 -0
- data/spec/support/file_contents_matcher.rb +50 -0
- data/spec/support/random.rb +210 -0
- data/spec/support/without_regard_to_order_matcher.rb +58 -0
- metadata +196 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
#
|
|
2
|
+
# h2. spec/imw/model/files/basicfile_spec.rb -- spec for a file object
|
|
3
|
+
#
|
|
4
|
+
# == About
|
|
5
|
+
#
|
|
6
|
+
# RSpec test code for <tt>IMW::Files::BasicFile</tt>.
|
|
7
|
+
#
|
|
8
|
+
# Author:: (Philip flip Kromer, Dhruv Bansal) for Infinite Monkeywrench Project (mailto:coders@infochimps.org)
|
|
9
|
+
# Copyright:: Copyright (c) 2008 infochimps.org
|
|
10
|
+
# License:: GPL 3.0
|
|
11
|
+
# Website:: http://infinitemonkeywrench.org/
|
|
12
|
+
#
|
|
13
|
+
require File.join(File.dirname(__FILE__),'../../../spec_helper')
|
|
14
|
+
require IMW_SPEC_DIR+'/imw/matchers/file_contents_matcher'
|
|
15
|
+
|
|
16
|
+
require 'imw/utils/random'
|
|
17
|
+
require 'imw/model/files/basicfile'
|
|
18
|
+
|
|
19
|
+
describe IMW::Files::BasicFile do
|
|
20
|
+
|
|
21
|
+
include Spec::Matchers::IMW
|
|
22
|
+
|
|
23
|
+
def create_file
|
|
24
|
+
IMW::Random.file @path
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
before(:all) do
|
|
28
|
+
@root_directory = IMW::DIRECTORIES[:dump] + "/file_spec"
|
|
29
|
+
FileUtils.mkdir @root_directory
|
|
30
|
+
|
|
31
|
+
@path = @root_directory + "/file.ext"
|
|
32
|
+
@copy_of_original_path = @root_directory + "/file_copy.ext"
|
|
33
|
+
|
|
34
|
+
@file = IMW::Files::BasicFile.new(@path)
|
|
35
|
+
|
|
36
|
+
@new_path_same_extension = @root_directory + "/file_new.ext"
|
|
37
|
+
@new_path_different_extension = @root_directory + "/file_new.next"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
after(:each) do
|
|
41
|
+
FileUtils.rm Dir.glob(@root_directory + "/*")
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
after(:all) do
|
|
45
|
+
FileUtils.rm_rf @root_directory
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
describe "(attributes)" do
|
|
49
|
+
it "should have the correct path" do
|
|
50
|
+
@file.path.should eql(@path)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "should have the correct directory name" do
|
|
54
|
+
@file.dirname.should eql(@root_directory)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "should have the correct basename" do
|
|
58
|
+
@file.basename.should eql("file.ext")
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "should have the correct extension" do
|
|
62
|
+
@file.extname.should eql(".ext")
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "should have the correct name" do
|
|
66
|
+
@file.name.should eql("file")
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
describe "(existence)" do
|
|
72
|
+
it "should not exist if there is no file matching it on disk" do
|
|
73
|
+
@file.exist?.should eql(false)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it "should exist if there is a file matching it on disk" do
|
|
77
|
+
create_file
|
|
78
|
+
@file.exist?.should eql(true)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
describe "(deletion)" do
|
|
83
|
+
it "should raise an error if it tries to delete itself but it doesn't exist" do
|
|
84
|
+
lambda { @file.rm }.should raise_error(IMW::PathError)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it "should delete itself if it it exists on disk" do
|
|
88
|
+
create_file
|
|
89
|
+
@file.rm
|
|
90
|
+
@file.exist?.should eql(false)
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
describe "(copying)" do
|
|
95
|
+
it "should raise an error if it tries to copy itself but it doesn't exist" do
|
|
96
|
+
lambda { @file.cp @new_path_same_extension }.should raise_error(IMW::PathError)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it "should copy itself with the same extension" do
|
|
100
|
+
create_file
|
|
101
|
+
new_file = @file.cp @new_path_same_extension
|
|
102
|
+
new_file.path.should have_contents_matching_those_of(@file.path)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it "should raise an error if it tries to copy itself with a differing extension without :force" do
|
|
106
|
+
create_file
|
|
107
|
+
lambda { @file.cp @new_path_different_extension }.should raise_error(IMW::Error)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it "should copy itself with a differing extension with :force" do
|
|
111
|
+
create_file
|
|
112
|
+
new_file = @file.cp @new_path_different_extension, :force => true
|
|
113
|
+
new_file.path.should have_contents_matching_those_of(@file.path)
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
describe "(moving)" do
|
|
118
|
+
it "should raise an error if it tries to move itself but it doesn't exist" do
|
|
119
|
+
lambda { @file.mv @new_path_same_extension }.should raise_error(IMW::PathError)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
it "should move itself with the same extension" do
|
|
123
|
+
create_file
|
|
124
|
+
old_file = @file.cp @copy_of_original_path
|
|
125
|
+
new_file = @file.mv @new_path_same_extension
|
|
126
|
+
new_file.path.should have_contents_matching_those_of(old_file.path)
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
it "should raise an error if it tries to move itself with a differing extension without :force" do
|
|
130
|
+
create_file
|
|
131
|
+
lambda { @file.mv @new_path_different_extension }.should raise_error(IMW::Error)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it "should move itself with a differing extension with :force" do
|
|
135
|
+
create_file
|
|
136
|
+
old_file = @file.cp @copy_of_original_path
|
|
137
|
+
new_file = @file.mv @new_path_different_extension, :force => true
|
|
138
|
+
new_file.path.should have_contents_matching_those_of(old_file.path)
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
# puts "#{File.basename(__FILE__)}: You place the manilla file folder between the rusty teeth of your Monkeywrench and tighten..." # at bottom
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#
|
|
2
|
+
# h2. spec/imw/model/files/gz_spec.rb -- spec for gz files
|
|
3
|
+
#
|
|
4
|
+
# == About
|
|
5
|
+
#
|
|
6
|
+
# RSpec code for <tt>IMW::Files::Gz</tt>.
|
|
7
|
+
#
|
|
8
|
+
# Author:: (Philip flip Kromer, Dhruv Bansal) for Infinite Monkeywrench Project (mailto:coders@infochimps.org)
|
|
9
|
+
# Copyright:: Copyright (c) 2008 infochimps.org
|
|
10
|
+
# License:: GPL 3.0
|
|
11
|
+
# Website:: http://infinitemonkeywrench.org/
|
|
12
|
+
#
|
|
13
|
+
require File.join(File.dirname(__FILE__),'../../../spec_helper')
|
|
14
|
+
require IMW_SPEC_DIR+'/imw/model/files/compressed_file_spec'
|
|
15
|
+
|
|
16
|
+
require 'imw/utils'
|
|
17
|
+
require 'imw/model/files/gz'
|
|
18
|
+
describe IMW::Files::Gz do
|
|
19
|
+
|
|
20
|
+
before(:all) do
|
|
21
|
+
@root_directory = IMW::DIRECTORIES[:dump] + "/gz_spec"
|
|
22
|
+
|
|
23
|
+
@path = @root_directory + "/file.txt.gz"
|
|
24
|
+
@file = IMW::Files::Gz.new(@path)
|
|
25
|
+
|
|
26
|
+
@copy_of_original_path = @root_directory + "/file_copy.txt.gz"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it_should_behave_like "a compressed file"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# puts "#{File.basename(__FILE__)}: You squeeze yourself and your Monkeywrench through a narrow opening." # at bottom
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#
|
|
2
|
+
# h2. test/imw/model/files/rar_spec.rb -- tests of rar file
|
|
3
|
+
#
|
|
4
|
+
# == About
|
|
5
|
+
#
|
|
6
|
+
# RSpec tests for <tt>IMW::Files::Rar</tt> class.
|
|
7
|
+
#
|
|
8
|
+
# Author:: (Philip flip Kromer, Dhruv Bansal) for Infinite Monkeywrench Project (mailto:coders@infochimps.org)
|
|
9
|
+
# Copyright:: Copyright (c) 2008 infochimps.org
|
|
10
|
+
# License:: GPL 3.0
|
|
11
|
+
# Website:: http://infinitemonkeywrench.org/
|
|
12
|
+
#
|
|
13
|
+
require File.join(File.dirname(__FILE__),'../../../spec_helper')
|
|
14
|
+
require IMW_SPEC_DIR+'/imw/model/files/archive_spec'
|
|
15
|
+
|
|
16
|
+
unless IMW::SpecConfig::SKIP_ARCHIVE_FORMATS.include? :rar
|
|
17
|
+
require 'imw/model/files/rar'
|
|
18
|
+
describe IMW::Files::Rar do
|
|
19
|
+
|
|
20
|
+
before(:all) do
|
|
21
|
+
@root_directory = ::IMW::DIRECTORIES[:dump] + "/archive_test"
|
|
22
|
+
@initial_directory = @root_directory + "/create_and_append/initial"
|
|
23
|
+
@appending_directory = @root_directory + "/create_and_append/appending"
|
|
24
|
+
@extraction_directory = ::IMW::DIRECTORIES[:dump] + "/extract"
|
|
25
|
+
@archive = IMW::Files::Rar.new(@root_directory + "/test.rar")
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it_should_behave_like "an archive of files"
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# puts "#{File.basename(__FILE__)}: You bang your Monkeywrench uselessly on the locked file cabinet." # at bottom
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#
|
|
2
|
+
# h2. test/imw/model/files/tar_spec.rb -- tests of tar file
|
|
3
|
+
#
|
|
4
|
+
# == About
|
|
5
|
+
#
|
|
6
|
+
# RSpec tests for <tt>IMW::Files::Tar</tt> class.
|
|
7
|
+
#
|
|
8
|
+
# Author:: (Philip flip Kromer, Dhruv Bansal) for Infinite Monkeywrench Project (mailto:coders@infochimps.org)
|
|
9
|
+
# Copyright:: Copyright (c) 2008 infochimps.org
|
|
10
|
+
# License:: GPL 3.0
|
|
11
|
+
# Website:: http://infinitemonkeywrench.org/
|
|
12
|
+
#
|
|
13
|
+
require File.join(File.dirname(__FILE__),'../../../spec_helper')
|
|
14
|
+
require IMW_SPEC_DIR+'/imw/model/files/archive_spec'
|
|
15
|
+
|
|
16
|
+
require 'imw/model/files/tar'
|
|
17
|
+
describe IMW::Files::Tar do
|
|
18
|
+
|
|
19
|
+
before(:all) do
|
|
20
|
+
@root_directory = ::IMW::DIRECTORIES[:dump] + "/archive_test"
|
|
21
|
+
@initial_directory = @root_directory + "/create_and_append/initial"
|
|
22
|
+
@appending_directory = @root_directory + "/create_and_append/appending"
|
|
23
|
+
@extraction_directory = ::IMW::DIRECTORIES[:dump] + "/extract"
|
|
24
|
+
@archive = IMW::Files::Tar.new(@root_directory + "/test.tar")
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it_should_behave_like "an archive of files"
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# puts "#{File.basename(__FILE__)}: The tar pits are just /wonderful/ today; really, you should go in for a dip!" # at bottom
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__),'../../spec_helper')
|
|
2
|
+
|
|
3
|
+
describe IMW::Files::Text do
|
|
4
|
+
|
|
5
|
+
before do
|
|
6
|
+
@path = "foobar.txt"
|
|
7
|
+
@text = <<EOF
|
|
8
|
+
Here is the first line
|
|
9
|
+
And here is the second
|
|
10
|
+
EOF
|
|
11
|
+
File.open(@path, 'w') { |f| f.write(@text) }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "should return its entries" do
|
|
15
|
+
IMW.open(@path).entries.should == ["Here is the first line", "And here is the second"]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "should be able to parse each line" do
|
|
19
|
+
file = IMW.open(@path)
|
|
20
|
+
results = file.parse :by_regexp => /^([^\s]+) ([^\s]+)/, :into_fields => [:word1, :word2]
|
|
21
|
+
file.parser.class.should == IMW::Parsers::RegexpParser
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#
|
|
2
|
+
# h2. test/imw/model/files/zip_spec.rb -- tests of zip file
|
|
3
|
+
#
|
|
4
|
+
# == About
|
|
5
|
+
#
|
|
6
|
+
# RSpec tests for <tt>IMW::Files::Zip</tt> class.
|
|
7
|
+
#
|
|
8
|
+
# Author:: (Philip flip Kromer, Dhruv Bansal) for Infinite Monkeywrench Project (mailto:coders@infochimps.org)
|
|
9
|
+
# Copyright:: Copyright (c) 2008 infochimps.org
|
|
10
|
+
# License:: GPL 3.0
|
|
11
|
+
# Website:: http://infinitemonkeywrench.org/
|
|
12
|
+
#
|
|
13
|
+
require File.join(File.dirname(__FILE__),'../../../spec_helper')
|
|
14
|
+
require IMW_SPEC_DIR+'/imw/model/files/archive_spec'
|
|
15
|
+
|
|
16
|
+
require 'imw/model/files/zip'
|
|
17
|
+
describe IMW::Files::Zip do
|
|
18
|
+
|
|
19
|
+
before(:all) do
|
|
20
|
+
@root_directory = ::IMW::DIRECTORIES[:dump] + "/archive_test"
|
|
21
|
+
@initial_directory = @root_directory + "/create_and_append/initial"
|
|
22
|
+
@appending_directory = @root_directory + "/create_and_append/appending"
|
|
23
|
+
@extraction_directory = ::IMW::DIRECTORIES[:dump] + "/extract"
|
|
24
|
+
@archive = IMW::Files::Zip.new(@root_directory + "/test.zip")
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it_should_behave_like "an archive of files"
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# puts "#{File.basename(__FILE__)}: No matter how many times you test the integrity of a zipper at the store before you buy something it /will/ break when you take it home!" # at bottom
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + "/../spec_helper"
|
|
2
|
+
|
|
3
|
+
describe IMW::Files do
|
|
4
|
+
|
|
5
|
+
before do
|
|
6
|
+
@csv = "foobar.csv"
|
|
7
|
+
@weird = "foobar.awefawefawe"
|
|
8
|
+
@none = "foobar"
|
|
9
|
+
|
|
10
|
+
@files = [@csv, @weird, @none]
|
|
11
|
+
|
|
12
|
+
@files.each { |f| IMWTest::Random.file f }
|
|
13
|
+
|
|
14
|
+
@new = "newguy.txt"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "chooses the correct class based upon the extension" do
|
|
18
|
+
IMW.open(@csv).class.should == IMW::Files::Csv
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "uses Text as a default class when there's a weird or no extension" do
|
|
22
|
+
IMW.open(@weird).class.should == IMW::Files::Text
|
|
23
|
+
IMW.open(@none).class.should == IMW::Files::Text
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "will use a different class if asked" do
|
|
27
|
+
IMW.open(@csv, :as => :Text).class.should == IMW::Files::Text
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "can write to a new file" do
|
|
31
|
+
f = IMW.open!(@new)
|
|
32
|
+
f.write('whatever')
|
|
33
|
+
f.close
|
|
34
|
+
open(@new).read.should == 'whatever'
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + "/../../spec_helper"
|
|
2
|
+
|
|
3
|
+
describe IMW::Packagers::Archiver do
|
|
4
|
+
before do
|
|
5
|
+
@name = 'foobar'
|
|
6
|
+
|
|
7
|
+
# regular files
|
|
8
|
+
@csv = "foobar-csv.csv"
|
|
9
|
+
@xml = "foobar-xml.xml"
|
|
10
|
+
@txt = "foobar-txt.txt"
|
|
11
|
+
@blah = "foobar"
|
|
12
|
+
|
|
13
|
+
# compressed files
|
|
14
|
+
@bz2 = "foobar-bz2.bz2"
|
|
15
|
+
|
|
16
|
+
# archives
|
|
17
|
+
@zip = "foobar-zip.zip"
|
|
18
|
+
@tarbz2 = "foobar-tarbz2.tar.bz2"
|
|
19
|
+
@rar = "foobar-rar.rar"
|
|
20
|
+
@archives = [@zip, @tarbz2]
|
|
21
|
+
|
|
22
|
+
@files = [@csv, @xml, @txt, @blah, @bz2, @zip, @tarbz2]
|
|
23
|
+
|
|
24
|
+
@files.each do |path|
|
|
25
|
+
IMWTest::Random.file path
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
describe "when preparing files" do
|
|
31
|
+
before do
|
|
32
|
+
@archiver = IMW::Packagers::Archiver.new @name, @files
|
|
33
|
+
@archiver.prepare!
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
after do
|
|
37
|
+
FileUtils.rm_rf @archiver.tmp_dir
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "should name its archive directory properly" do
|
|
41
|
+
@archiver.tmp_dir.should contain(@name)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "should copy regular files to its archive directory" do
|
|
45
|
+
@archiver.dir.should contain(@csv, @xml, @txt)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "should uncompress compressed files to its archive directory" do
|
|
49
|
+
@archiver.dir.should contain('foobar-bz2')
|
|
50
|
+
@archiver.dir.should_not contain(@bz2)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "should copy the content of archive files to its archive directory (but not the actual archives)" do
|
|
54
|
+
@archives.each do |archive|
|
|
55
|
+
@archiver.dir.should_not contain(archive)
|
|
56
|
+
@archiver.dir.should contain(*IMW.open(archive).contents)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "should not move any of the original files" do
|
|
61
|
+
IMWTest::TMP_DIR.should contain(@files)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
describe "when preparing files while renaming them" do
|
|
66
|
+
before do
|
|
67
|
+
|
|
68
|
+
# to test renaming, consider the new paths to be the old paths
|
|
69
|
+
# but with the hyphens mapped to underscores...
|
|
70
|
+
@renaming_hash = {}
|
|
71
|
+
@files.each { |f| @renaming_hash[f] = f.gsub(/-/,'_') }
|
|
72
|
+
|
|
73
|
+
@archiver = IMW::Packagers::Archiver.new @name, @renaming_hash
|
|
74
|
+
@archiver.prepare!
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
after do
|
|
78
|
+
FileUtils.rm_rf @archiver.tmp_dir
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "should copy regular files to its archive directory, renaming them" do
|
|
82
|
+
@archiver.dir.should_not contain([@csv, @xml, @txt])
|
|
83
|
+
@archiver.dir.should contain([@csv, @xml, @txt].map { |f| @renaming_hash[f] })
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it "should uncompress compressed files to its archive directory, renaming them" do
|
|
87
|
+
@archiver.dir.should contain('foobar_bz2')
|
|
88
|
+
@archiver.dir.should_not contain('foobar-bz2')
|
|
89
|
+
@archiver.dir.should_not contain(@renaming_hash[@bz2])
|
|
90
|
+
@archiver.dir.should_not contain(@bz2)
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
describe "when packaging files" do
|
|
95
|
+
before do
|
|
96
|
+
@archiver = IMW::Packagers::Archiver.new @name, @files
|
|
97
|
+
@archiver.prepare!
|
|
98
|
+
|
|
99
|
+
@package_tarbz2 = "package.tar.bz2"
|
|
100
|
+
@package_zip = "package.zip"
|
|
101
|
+
@packages = [@package_tarbz2, @package_zip]
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
after do
|
|
105
|
+
FileUtils.rm_rf @archiver.tmp_dir
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it "should create a package file containing the proper files" do
|
|
109
|
+
@packages.each do |package|
|
|
110
|
+
@archiver.package! package
|
|
111
|
+
@archiver.tmp_dir.should contain(IMW.open(package).contents)
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it "should return the package file" do
|
|
116
|
+
@packages.each do |package|
|
|
117
|
+
output = @archiver.package! package
|
|
118
|
+
output.basename.should == package
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|