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,43 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__),'../../../spec_helper')
|
|
2
|
+
require File.join(File.dirname(__FILE__),'../datamapper_spec_helper')
|
|
3
|
+
include IMW
|
|
4
|
+
require 'imw/dataset/datamapper/uri'
|
|
5
|
+
|
|
6
|
+
if IMW::SpecConfig::TEST_WITH_DATAMAPPER
|
|
7
|
+
IMW::SpecConfig.setup_datamapper_test_db
|
|
8
|
+
describe IMW do
|
|
9
|
+
|
|
10
|
+
before(:each) do
|
|
11
|
+
DM_URI.all.each do |u| u.destroy end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "makes a URI from a barely complete string" do
|
|
15
|
+
DM_URI.find_or_create_from_url('google.com')
|
|
16
|
+
u = DM_URI.first
|
|
17
|
+
u.should_not be_nil
|
|
18
|
+
u.host.should == 'google.com'
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "behaves as normalized" do
|
|
22
|
+
DM_URI.find_or_create_from_url('google.com')
|
|
23
|
+
u = DM_URI.first
|
|
24
|
+
u.path.should == '/'
|
|
25
|
+
u.scheme.should == 'http'
|
|
26
|
+
u.port.should be_nil
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "makes a complicated URI from a complicated string" do
|
|
30
|
+
DM_URI.find_or_create_from_url('http://me:and@your.mom.com:69/what?orly=yarly&ok=then')
|
|
31
|
+
dm_uri = DM_URI.first({
|
|
32
|
+
:scheme => 'http', :host => 'your.mom.com', :port => '69',
|
|
33
|
+
:query => 'what?orly=yarly&ok=then'
|
|
34
|
+
})
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# it converts to a file path
|
|
38
|
+
# it doesn't leave a trailing / on the file path
|
|
39
|
+
# it escapes unicode URLs
|
|
40
|
+
# it escapes non-URL chars in URL
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'imw/dataset/datamapper'
|
|
2
|
+
|
|
3
|
+
module IMW::SpecConfig
|
|
4
|
+
|
|
5
|
+
def self.setup_datamapper_test_db
|
|
6
|
+
IMW::Dataset.setup_remote_connection IMW::DEFAULT_DATABASE_CONNECTION_PARAMS.merge({
|
|
7
|
+
:dbname => 'imw_dataset_datamapper_test' })
|
|
8
|
+
DataMapper.auto_migrate!
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
end
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
#
|
|
2
|
+
# h2. spec/imw/model/files/archive_spec.rb -- module for use in testing various archive formats
|
|
3
|
+
#
|
|
4
|
+
# == About
|
|
5
|
+
#
|
|
6
|
+
# The <tt>IMW::Files::Archive</tt> module doesn't implement any
|
|
7
|
+
# functionality of its own but merely adds methods to an including
|
|
8
|
+
# class. Appropriately, this spec file implements a shared example
|
|
9
|
+
# group ("an archive of files") which can be including
|
|
10
|
+
# by the spec of an archive class. This spec must also define the
|
|
11
|
+
# following instance variables:
|
|
12
|
+
#
|
|
13
|
+
# <tt>@archive</tt>:: a subclass of <tt>IMW::Files::BasicFile</tt> which
|
|
14
|
+
# has the <tt>IMW::Files::Archive</tt> module mixed in.
|
|
15
|
+
#
|
|
16
|
+
# <tt>@root_directory</tt>: a string specifying the path where all the
|
|
17
|
+
# files will be created
|
|
18
|
+
#
|
|
19
|
+
# <tt>@initial_directory</tt>: a string specifying the path where some
|
|
20
|
+
# files for the initial creation of the archive will be created.
|
|
21
|
+
#
|
|
22
|
+
# <tt>@appending_directory</tt>: a string specifying the path where
|
|
23
|
+
# all some files for appending to the archive will be created.
|
|
24
|
+
#
|
|
25
|
+
# <tt>@extraction_directory</tt>: a string specifying the path where
|
|
26
|
+
# the archive's files will be extracted.
|
|
27
|
+
#
|
|
28
|
+
# Author:: (Philip flip Kromer, Dhruv Bansal) for Infinite Monkeywrench Project (mailto:coders@infochimps.org)
|
|
29
|
+
# Copyright:: Copyright (c) 2008 infochimps.org
|
|
30
|
+
# License:: GPL 3.0
|
|
31
|
+
# Website:: http://infinitemonkeywrench.org/
|
|
32
|
+
#
|
|
33
|
+
require File.join(File.dirname(__FILE__),'../../../spec_helper')
|
|
34
|
+
require IMW_SPEC_DIR+'/imw/matchers/archive_contents_matcher'
|
|
35
|
+
require IMW_SPEC_DIR+'/imw/matchers/directory_contents_matcher'
|
|
36
|
+
|
|
37
|
+
require 'imw/utils/random'
|
|
38
|
+
require 'imw/utils/extensions/find'
|
|
39
|
+
share_examples_for "an archive of files" do
|
|
40
|
+
include Spec::Matchers::IMW
|
|
41
|
+
|
|
42
|
+
def create_random_files
|
|
43
|
+
IMW::Random.directory_with_files(@initial_directory)
|
|
44
|
+
IMW::Random.directory_with_files(@appending_directory)
|
|
45
|
+
FileUtils.mkdir(@extraction_directory)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def delete_random_files
|
|
49
|
+
FileUtils.rm_rf [@root_directory,@extraction_directory]
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
before(:each) do
|
|
53
|
+
create_random_files
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
after(:each) do
|
|
57
|
+
delete_random_files
|
|
58
|
+
FileUtils.rm(@archive.path) if @archive.exist?
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
describe "(listing)" do
|
|
62
|
+
it "should raise an error when listing a non-existent archive" do
|
|
63
|
+
lambda { @archive.contents }.should raise_error(IMW::Error)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
describe "(creation)" do
|
|
68
|
+
|
|
69
|
+
it "should be able to create archives which match a directory's structure" do
|
|
70
|
+
@archive.create(@initial_directory + "/*")
|
|
71
|
+
@archive.should contain_paths_like(@initial_directory, :relative_to => @root_directory)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "should raise an error if trying to overwrite an archive without the :force option" do
|
|
75
|
+
@archive.create(@initial_directory + "/*")
|
|
76
|
+
lambda { @archive.create(@initial_directory + "/*") }.should raise_error(IMW::Error)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "should overwrite an archive if the :force option is given" do
|
|
80
|
+
@archive.create(@initial_directory + "/*")
|
|
81
|
+
@archive.create(@initial_directory + "/*", :force => true)
|
|
82
|
+
@archive.should contain_paths_like(@initial_directory, :relative_to => @root_directory)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
describe "(appending)" do
|
|
87
|
+
|
|
88
|
+
it "should append to an archive which already exists" do
|
|
89
|
+
@archive.create(@initial_directory + "/*")
|
|
90
|
+
@archive.append(@appending_directory + "/*")
|
|
91
|
+
@archive.should contain_paths_like([@initial_directory,@appending_directory], :relative_to => @root_directory)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it "should append to an archive which doesn't already exist" do
|
|
95
|
+
@archive.append(@appending_directory + "/*")
|
|
96
|
+
@archive.should contain_paths_like(@appending_directory, :relative_to => @root_directory)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
describe "(extracting)" do
|
|
102
|
+
|
|
103
|
+
it "should raise an error when trying to extract from a non-existing archive" do
|
|
104
|
+
lambda { @archive.extract }.should raise_error(IMW::Error)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it "should extract files which match the original ones it archived" do
|
|
108
|
+
@archive.create(@initial_directory + "/*")
|
|
109
|
+
@archive.append(@appending_directory + "/*")
|
|
110
|
+
new_archive = @archive.cp(@extraction_directory + '/' + @archive.basename)
|
|
111
|
+
new_archive.extract
|
|
112
|
+
@extraction_directory.should contain_files_matching_directory(@root_directory)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
end
|
|
116
|
+
end unless defined? IMW_FILES_ARCHIVE_SHARED_SPEC
|
|
117
|
+
|
|
118
|
+
# puts "#{File.basename(__FILE__)}: How many drunken frat boys can fit in an Internet kiosk?" # at bottom
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + "/../../spec_helper"
|
|
2
|
+
|
|
3
|
+
require "imw"
|
|
4
|
+
|
|
5
|
+
describe IMW::Files::BasicFile do
|
|
6
|
+
|
|
7
|
+
describe "a local file" do
|
|
8
|
+
before do
|
|
9
|
+
@path = "foobar.txt"
|
|
10
|
+
IMWTest::Random.file @path
|
|
11
|
+
@file = IMW.open(@path)
|
|
12
|
+
|
|
13
|
+
@new_path = "foobar2.txt"
|
|
14
|
+
|
|
15
|
+
@new_dir = "bazbaz"
|
|
16
|
+
FileUtils.mkdir_p(@new_dir)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "should now that it's local" do
|
|
20
|
+
@file.local?.should be_true
|
|
21
|
+
@file.remote?.should be_false
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "knows the parts of its URI" do
|
|
25
|
+
@file.host.should == nil
|
|
26
|
+
@file.path.should == File.join(IMWTest::TMP_DIR, @path)
|
|
27
|
+
@file.dirname.should == IMWTest::TMP_DIR
|
|
28
|
+
@file.basename.should == @path
|
|
29
|
+
@file.extname.should == ".txt"
|
|
30
|
+
@file.name.should == "foobar"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "can copy a file" do
|
|
34
|
+
@file.cp(@new_path)
|
|
35
|
+
@path.should exist
|
|
36
|
+
@new_path.should exist
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "can move a file" do
|
|
40
|
+
@file.mv(@new_path)
|
|
41
|
+
@path.should_not exist
|
|
42
|
+
@new_path.should exist
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "can delete a file" do
|
|
46
|
+
@file.rm!
|
|
47
|
+
@path.should_not exist
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "can copy to a directory" do
|
|
51
|
+
@file.cp_to_dir(@new_dir)
|
|
52
|
+
@new_dir.should contain(@path)
|
|
53
|
+
@path.should exist
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "can move to a directory" do
|
|
57
|
+
@file.mv_to_dir(@new_dir)
|
|
58
|
+
@new_dir.should contain(@path)
|
|
59
|
+
@path.should_not exist
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
[:executable?, :executable_real?, :file?, :directory?, :ftype, :owned?, :pipe?, :readable?, :readable_real?, :setgid?, :setuid?, :size, :size?, :socket?, :split, :stat, :sticky?, :writable?, :writable_real?, :zero?].each do |method|
|
|
63
|
+
it "should respond to #{method}" do
|
|
64
|
+
@file.send(method).should == File.send(method, @file.path)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
describe "a remote file" do
|
|
71
|
+
before do
|
|
72
|
+
@path = "http://www.google.com"
|
|
73
|
+
@file = IMW.open(@path)
|
|
74
|
+
|
|
75
|
+
@new_path = "foobar2.txt"
|
|
76
|
+
|
|
77
|
+
@new_dir = "bazbaz"
|
|
78
|
+
FileUtils.mkdir_p(@new_dir)
|
|
79
|
+
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it "should know that it's remote" do
|
|
83
|
+
@file.local?.should be_false
|
|
84
|
+
@file.remote?.should be_true
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it "knows the parts of its URI" do
|
|
88
|
+
@file.host.should == "www.google.com"
|
|
89
|
+
@file.path.should == ''
|
|
90
|
+
@file.dirname.should == '.'
|
|
91
|
+
@file.basename.should == ''
|
|
92
|
+
@file.extname.should == ''
|
|
93
|
+
@file.name.should == ''
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it "can open the file" do
|
|
97
|
+
@file.should be
|
|
98
|
+
@file.class.should == IMW::Files::Text
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it "should raise an error when trying to write" do
|
|
102
|
+
lambda { IMW.open!(@path) }.should raise_error
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it "can copy a file" do
|
|
106
|
+
@file.cp(@new_path)
|
|
107
|
+
@new_path.should exist
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it "can move a file" do
|
|
111
|
+
@file.mv(@new_path)
|
|
112
|
+
@new_path.should exist
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it "should raise an error when trying to remove" do
|
|
116
|
+
lambda { @file.rm }.should raise_error
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#
|
|
2
|
+
# h2. spec/imw/model/files/bz2_spec.rb -- spec for bz2 files
|
|
3
|
+
#
|
|
4
|
+
# == About
|
|
5
|
+
#
|
|
6
|
+
# RSpec code for <tt>IMW::Files::Bz2</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/model/files/bz2'
|
|
17
|
+
describe IMW::Files::Bz2 do
|
|
18
|
+
|
|
19
|
+
before(:all) do
|
|
20
|
+
@root_directory = IMW::DIRECTORIES[:dump] + "/bz2_spec"
|
|
21
|
+
|
|
22
|
+
@path = @root_directory + "/file.txt.bz2"
|
|
23
|
+
@file = IMW::Files::Bz2.new(@path)
|
|
24
|
+
|
|
25
|
+
@copy_of_original_path = @root_directory + "/file_copy.txt.bz2"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it_should_behave_like "a compressed file"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# puts "#{File.basename(__FILE__)}: You squeeze yourself and your Monkeywrench through a narrow opening, twice." # at bottom
|
|
32
|
+
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#
|
|
2
|
+
# h2. spec/imw/model/files/compressed_file_spec.rb -- shared specs for compressed files
|
|
3
|
+
#
|
|
4
|
+
# == About
|
|
5
|
+
#
|
|
6
|
+
# Defines a shared spec ("a compressed file") for inclusion in specs
|
|
7
|
+
# for classes which subclass <tt>IMW::Files::CompressedFile</tt>.
|
|
8
|
+
#
|
|
9
|
+
# An including spec must define the following instance variables:
|
|
10
|
+
#
|
|
11
|
+
# <tt>@root_directory</tt>:: directory inside which all files will be
|
|
12
|
+
# created
|
|
13
|
+
#
|
|
14
|
+
# <tt>@file</tt>:: the file to be decompressed
|
|
15
|
+
#
|
|
16
|
+
# <tt>@copy_of_original_path</tt>:: path where a copy of
|
|
17
|
+
# <tt>@file</tt> can be put during testing
|
|
18
|
+
#
|
|
19
|
+
# An including spec can also optionally redefine the
|
|
20
|
+
# +create_compressed_file+ method to create the proper file during
|
|
21
|
+
# each example.
|
|
22
|
+
#
|
|
23
|
+
# Author:: (Philip flip Kromer, Dhruv Bansal) for Infinite Monkeywrench Project (mailto:coders@infochimps.org)
|
|
24
|
+
# Copyright:: Copyright (c) 2008 infochimps.org
|
|
25
|
+
# License:: GPL 3.0
|
|
26
|
+
# Website:: http://infinitemonkeywrench.org/
|
|
27
|
+
#
|
|
28
|
+
require File.join(File.dirname(__FILE__),'../../../spec_helper')
|
|
29
|
+
require IMW_SPEC_DIR+'/imw/matchers/file_contents_matcher'
|
|
30
|
+
|
|
31
|
+
require 'imw/utils/random'
|
|
32
|
+
require 'imw/model/files/text'
|
|
33
|
+
share_examples_for "a compressed file" do
|
|
34
|
+
|
|
35
|
+
include Spec::Matchers::IMW
|
|
36
|
+
|
|
37
|
+
def create_compressed_file
|
|
38
|
+
text_file_path = @root_directory + "/sample.txt"
|
|
39
|
+
IMW::Random.file text_file_path
|
|
40
|
+
text_file = IMW::Files::Text.new(text_file_path)
|
|
41
|
+
compressed_text_file = text_file.compress! @file.compression[:program]
|
|
42
|
+
compressed_text_file.mv @file.path
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
describe "when decompressing" do
|
|
46
|
+
|
|
47
|
+
before(:each) do
|
|
48
|
+
FileUtils.mkdir_p @root_directory
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
after(:each) do
|
|
52
|
+
FileUtils.rm_rf @root_directory
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
describe "and discarding original file" do
|
|
56
|
+
|
|
57
|
+
it "should raise an error if the compressed file doesn't exist" do
|
|
58
|
+
lambda {@file.decompress! }.should raise_error(IMW::PathError)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "should decompress a compressed file which exists" do
|
|
62
|
+
create_compressed_file
|
|
63
|
+
decompressed_file = @file.decompress!
|
|
64
|
+
decompressed_file.exist?.should eql(true)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it "should not exist after decompression" do
|
|
68
|
+
create_compressed_file
|
|
69
|
+
decompressed_file = @file.decompress!
|
|
70
|
+
@file.exist?.should eql(false)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
describe "and keeping original file" do
|
|
75
|
+
|
|
76
|
+
it "should raise an error if the compressed file doesn't exist" do
|
|
77
|
+
lambda {@file.decompress }.should raise_error(IMW::PathError)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it "should decompress a compressed file which exists" do
|
|
81
|
+
create_compressed_file
|
|
82
|
+
decompressed_file = @file.decompress
|
|
83
|
+
decompressed_file.exist?.should eql(true)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it "should be identical to how it was before decompression" do
|
|
87
|
+
create_compressed_file
|
|
88
|
+
@file.cp @copy_of_original_path
|
|
89
|
+
decompressed_file = @file.decompress
|
|
90
|
+
@copy_of_original_path.should have_contents_matching_those_of(@file.path)
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end unless defined? IMW_FILES_COMPRESSEDFILE_SHARED_SPEC
|
|
95
|
+
|
|
96
|
+
# puts "#{File.basename(__FILE__)}: You whack the cabinet with your Monkeywrench sending files and papers everywhere. You smile." # at bottom
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#
|
|
2
|
+
# h2. spec/imw/model/files/compressible_spec.rb -- spec for compressible module
|
|
3
|
+
#
|
|
4
|
+
# == About
|
|
5
|
+
#
|
|
6
|
+
# Defines shared example groups ("a file compressible by bzip2", "a
|
|
7
|
+
# file compressible by gzip") for the
|
|
8
|
+
# <tt>IMW::Files::Compressible</tt> module to be included in specs for
|
|
9
|
+
# classes which mixin the <tt>IMW::Files::Compressible</tt> module.
|
|
10
|
+
# The specs for these classes should define, for each example, the
|
|
11
|
+
# following instance variables:
|
|
12
|
+
#
|
|
13
|
+
# <tt>@file</tt>:: an object to be compressed which is a subclass of
|
|
14
|
+
# <tt>IMW::Files::BasicFile</tt>.
|
|
15
|
+
#
|
|
16
|
+
# <tt>@copy_of_original_path</tt>:: a string giving a path where a
|
|
17
|
+
# copy of <tt>@file</tt> can be made for comparison purposes.
|
|
18
|
+
#
|
|
19
|
+
# The including spec should also define a method +create_file+ for
|
|
20
|
+
# creating a real file at the path corresponding to <tt>@file</tt>.
|
|
21
|
+
#
|
|
22
|
+
# The including spec must handle the +before+ and +after+ clauses for
|
|
23
|
+
# the creation and removal of files and directories; this spec doesn't
|
|
24
|
+
# handle those details.
|
|
25
|
+
#
|
|
26
|
+
# Author:: (Philip flip Kromer, Dhruv Bansal) for Infinite Monkeywrench Project (mailto:coders@infochimps.org)
|
|
27
|
+
# Copyright:: Copyright (c) 2008 infochimps.org
|
|
28
|
+
# License:: GPL 3.0
|
|
29
|
+
# Website:: http://infinitemonkeywrench.org/
|
|
30
|
+
#
|
|
31
|
+
require File.join(File.dirname(__FILE__),'../../../spec_helper')
|
|
32
|
+
require IMW_SPEC_DIR+'/imw/matchers/directory_contents_matcher'
|
|
33
|
+
require IMW_SPEC_DIR+'/imw/matchers/file_contents_matcher'
|
|
34
|
+
require 'imw/utils/random'
|
|
35
|
+
|
|
36
|
+
share_examples_for "a file compressible by bzip2" do
|
|
37
|
+
|
|
38
|
+
describe "when compressing with bzip2" do
|
|
39
|
+
before(:each) do
|
|
40
|
+
@program = :bzip2
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it_should_behave_like "a file compressible by a given program"
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
share_examples_for "a file compressible by gzip" do
|
|
48
|
+
describe "when compressing with gzip" do
|
|
49
|
+
before(:each) do
|
|
50
|
+
@program = :gzip
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it_should_behave_like "a file compressible by a given program"
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
share_examples_for "a file compressible by a given program" do
|
|
58
|
+
|
|
59
|
+
include Spec::Matchers::IMW
|
|
60
|
+
|
|
61
|
+
describe "and discarding original file" do
|
|
62
|
+
|
|
63
|
+
it "should raise an error when compressing a non-existing file" do
|
|
64
|
+
lambda { @file.compress! @program }.should raise_error(IMW::PathError)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it "should compress itself to the correct path" do
|
|
68
|
+
create_file
|
|
69
|
+
compressed_file = @file.compress! @program
|
|
70
|
+
compressed_file.exist?.should eql(true)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it "should not exist after compressing itself" do
|
|
74
|
+
create_file
|
|
75
|
+
compressed_file = @file.compress! @program
|
|
76
|
+
@file.exist?.should eql(false)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
describe "and keeping original file" do
|
|
81
|
+
it "should raise an error when compressing a non-existing file" do
|
|
82
|
+
lambda { @file.compress @program }.should raise_error(IMW::PathError)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it "should compress itself to the correct path" do
|
|
86
|
+
create_file
|
|
87
|
+
compressed_file = @file.compress @program
|
|
88
|
+
compressed_file.exist?.should eql(true)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it "should be identical to the way it was before it was compressed" do
|
|
92
|
+
create_file
|
|
93
|
+
@file.cp @copy_of_original_path
|
|
94
|
+
compressed_file = @file.compress @program
|
|
95
|
+
@file.path.should have_contents_matching_those_of(@copy_of_original_path)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# puts "#{File.basename(__FILE__)}: Is it squishy? Give it a squeeze and see!" # at bottom
|