imw 0.1.1 → 0.2.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.
Files changed (143) hide show
  1. data/.gitignore +4 -1
  2. data/Rakefile +10 -0
  3. data/TODO +18 -0
  4. data/VERSION +1 -1
  5. data/bin/imw +1 -1
  6. data/etc/imwrc.rb +0 -50
  7. data/examples/dataset.rb +12 -0
  8. data/lib/imw/boot.rb +55 -9
  9. data/lib/imw/dataset/paths.rb +15 -24
  10. data/lib/imw/dataset/workflow.rb +131 -72
  11. data/lib/imw/dataset.rb +94 -186
  12. data/lib/imw/parsers/html_parser.rb +1 -1
  13. data/lib/imw/parsers.rb +1 -1
  14. data/lib/imw/repository.rb +3 -27
  15. data/lib/imw/resource.rb +190 -0
  16. data/lib/imw/resources/archive.rb +97 -0
  17. data/lib/imw/resources/archives_and_compressed/bz2.rb +18 -0
  18. data/lib/imw/resources/archives_and_compressed/gz.rb +18 -0
  19. data/lib/imw/resources/archives_and_compressed/rar.rb +23 -0
  20. data/lib/imw/resources/archives_and_compressed/tar.rb +23 -0
  21. data/lib/imw/resources/archives_and_compressed/tarbz2.rb +78 -0
  22. data/lib/imw/resources/archives_and_compressed/targz.rb +78 -0
  23. data/lib/imw/resources/archives_and_compressed/zip.rb +57 -0
  24. data/lib/imw/resources/archives_and_compressed.rb +32 -0
  25. data/lib/imw/resources/compressed_file.rb +89 -0
  26. data/lib/imw/resources/compressible.rb +77 -0
  27. data/lib/imw/resources/formats/delimited.rb +92 -0
  28. data/lib/imw/resources/formats/excel.rb +125 -0
  29. data/lib/imw/resources/formats/json.rb +53 -0
  30. data/lib/imw/resources/formats/sgml.rb +72 -0
  31. data/lib/imw/resources/formats/yaml.rb +53 -0
  32. data/lib/imw/resources/formats.rb +32 -0
  33. data/lib/imw/resources/local.rb +198 -0
  34. data/lib/imw/resources/remote.rb +110 -0
  35. data/lib/imw/resources/schemes/hdfs.rb +242 -0
  36. data/lib/imw/resources/schemes/http.rb +161 -0
  37. data/lib/imw/resources/schemes/s3.rb +137 -0
  38. data/lib/imw/resources/schemes.rb +19 -0
  39. data/lib/imw/resources.rb +118 -0
  40. data/lib/imw/runner.rb +5 -4
  41. data/lib/imw/transforms/archiver.rb +215 -0
  42. data/lib/imw/transforms/transferer.rb +103 -0
  43. data/lib/imw/transforms.rb +8 -0
  44. data/lib/imw/utils/error.rb +26 -30
  45. data/lib/imw/utils/extensions/array.rb +5 -15
  46. data/lib/imw/utils/extensions/hash.rb +6 -16
  47. data/lib/imw/utils/extensions/hpricot.rb +0 -14
  48. data/lib/imw/utils/extensions/string.rb +5 -15
  49. data/lib/imw/utils/extensions/symbol.rb +0 -13
  50. data/lib/imw/utils/extensions.rb +65 -0
  51. data/lib/imw/utils/log.rb +14 -13
  52. data/lib/imw/utils/misc.rb +0 -6
  53. data/lib/imw/utils/paths.rb +101 -42
  54. data/lib/imw/utils/version.rb +8 -9
  55. data/lib/imw/utils.rb +2 -18
  56. data/lib/imw.rb +92 -17
  57. data/spec/data/sample.csv +1 -1
  58. data/spec/data/sample.json +1 -0
  59. data/spec/data/sample.tsv +1 -1
  60. data/spec/data/sample.txt +1 -1
  61. data/spec/data/sample.xml +1 -1
  62. data/spec/data/sample.yaml +1 -1
  63. data/spec/imw/dataset/paths_spec.rb +32 -0
  64. data/spec/imw/dataset/workflow_spec.rb +41 -0
  65. data/spec/imw/resource_spec.rb +79 -0
  66. data/spec/imw/resources/archive_spec.rb +69 -0
  67. data/spec/imw/resources/archives_and_compressed/bz2_spec.rb +15 -0
  68. data/spec/imw/resources/archives_and_compressed/gz_spec.rb +15 -0
  69. data/spec/imw/resources/archives_and_compressed/rar_spec.rb +16 -0
  70. data/spec/imw/resources/archives_and_compressed/tar_spec.rb +16 -0
  71. data/spec/imw/resources/archives_and_compressed/tarbz2_spec.rb +24 -0
  72. data/spec/imw/resources/archives_and_compressed/targz_spec.rb +21 -0
  73. data/spec/imw/resources/archives_and_compressed/zip_spec.rb +16 -0
  74. data/spec/imw/resources/compressed_file_spec.rb +48 -0
  75. data/spec/imw/resources/compressible_spec.rb +36 -0
  76. data/spec/imw/resources/formats/delimited_spec.rb +33 -0
  77. data/spec/imw/resources/formats/json_spec.rb +32 -0
  78. data/spec/imw/resources/formats/sgml_spec.rb +24 -0
  79. data/spec/imw/resources/formats/yaml_spec.rb +41 -0
  80. data/spec/imw/resources/local_spec.rb +98 -0
  81. data/spec/imw/resources/remote_spec.rb +35 -0
  82. data/spec/imw/resources/schemes/hdfs_spec.rb +61 -0
  83. data/spec/imw/resources/schemes/http_spec.rb +19 -0
  84. data/spec/imw/resources/schemes/s3_spec.rb +19 -0
  85. data/spec/imw/transforms/archiver_spec.rb +120 -0
  86. data/spec/imw/transforms/transferer_spec.rb +113 -0
  87. data/spec/imw/utils/paths_spec.rb +5 -33
  88. data/spec/imw/utils/shared_paths_spec.rb +29 -0
  89. data/spec/spec_helper.rb +5 -5
  90. data/spec/support/paths_matcher.rb +67 -0
  91. data/spec/support/random.rb +39 -36
  92. metadata +88 -75
  93. data/lib/imw/dataset/task.rb +0 -41
  94. data/lib/imw/files/archive.rb +0 -113
  95. data/lib/imw/files/basicfile.rb +0 -122
  96. data/lib/imw/files/binary.rb +0 -28
  97. data/lib/imw/files/compressed_file.rb +0 -93
  98. data/lib/imw/files/compressed_files_and_archives.rb +0 -334
  99. data/lib/imw/files/compressible.rb +0 -103
  100. data/lib/imw/files/csv.rb +0 -113
  101. data/lib/imw/files/directory.rb +0 -62
  102. data/lib/imw/files/excel.rb +0 -84
  103. data/lib/imw/files/json.rb +0 -41
  104. data/lib/imw/files/sgml.rb +0 -46
  105. data/lib/imw/files/text.rb +0 -68
  106. data/lib/imw/files/yaml.rb +0 -46
  107. data/lib/imw/files.rb +0 -125
  108. data/lib/imw/packagers/archiver.rb +0 -126
  109. data/lib/imw/packagers/s3_mover.rb +0 -36
  110. data/lib/imw/packagers.rb +0 -8
  111. data/lib/imw/utils/components.rb +0 -61
  112. data/lib/imw/utils/config.rb +0 -46
  113. data/lib/imw/utils/extensions/class/attribute_accessors.rb +0 -8
  114. data/lib/imw/utils/extensions/core.rb +0 -27
  115. data/lib/imw/utils/extensions/dir.rb +0 -24
  116. data/lib/imw/utils/extensions/file_core.rb +0 -64
  117. data/lib/imw/utils/extensions/typed_struct.rb +0 -22
  118. data/lib/imw/utils/extensions/uri.rb +0 -59
  119. data/lib/imw/utils/view/dump_csv.rb +0 -112
  120. data/lib/imw/utils/view/dump_csv_older.rb +0 -117
  121. data/lib/imw/utils/view.rb +0 -113
  122. data/spec/imw/dataset/datamapper/uri_spec.rb +0 -43
  123. data/spec/imw/dataset/datamapper_spec_helper.rb +0 -11
  124. data/spec/imw/files/archive_spec.rb +0 -118
  125. data/spec/imw/files/basicfile_spec.rb +0 -121
  126. data/spec/imw/files/bz2_spec.rb +0 -32
  127. data/spec/imw/files/compressed_file_spec.rb +0 -96
  128. data/spec/imw/files/compressible_spec.rb +0 -100
  129. data/spec/imw/files/file_spec.rb +0 -144
  130. data/spec/imw/files/gz_spec.rb +0 -32
  131. data/spec/imw/files/rar_spec.rb +0 -33
  132. data/spec/imw/files/tar_spec.rb +0 -31
  133. data/spec/imw/files/text_spec.rb +0 -23
  134. data/spec/imw/files/zip_spec.rb +0 -31
  135. data/spec/imw/files_spec.rb +0 -38
  136. data/spec/imw/packagers/archiver_spec.rb +0 -125
  137. data/spec/imw/packagers/s3_mover_spec.rb +0 -7
  138. data/spec/imw/utils/extensions/file_core_spec.rb +0 -72
  139. data/spec/imw/utils/extensions/find_spec.rb +0 -113
  140. data/spec/imw/workflow/rip/local_spec.rb +0 -89
  141. data/spec/imw/workflow/rip_spec.rb +0 -27
  142. data/spec/support/archive_contents_matcher.rb +0 -94
  143. data/spec/support/directory_contents_matcher.rb +0 -61
@@ -1,121 +0,0 @@
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
-
@@ -1,32 +0,0 @@
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
-
@@ -1,96 +0,0 @@
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
@@ -1,100 +0,0 @@
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
@@ -1,144 +0,0 @@
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
@@ -1,32 +0,0 @@
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
@@ -1,33 +0,0 @@
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
@@ -1,31 +0,0 @@
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
@@ -1,23 +0,0 @@
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
@@ -1,31 +0,0 @@
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
@@ -1,38 +0,0 @@
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
-