fun_with_files 0.0.15 → 0.0.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.markdown +15 -3
  3. data/Gemfile +17 -7
  4. data/{README.rdoc → README.markdown} +11 -10
  5. data/VERSION +1 -1
  6. data/lib/fun_with/files/bootstrapper.rb +87 -0
  7. data/lib/fun_with/files/digest_methods.rb +30 -16
  8. data/lib/fun_with/files/directory_builder.rb +4 -0
  9. data/lib/fun_with/files/downloader.rb +3 -19
  10. data/lib/fun_with/files/errors.rb +9 -1
  11. data/lib/fun_with/files/file_manipulation_methods.rb +25 -15
  12. data/lib/fun_with/files/file_path.rb +147 -150
  13. data/lib/fun_with/files/file_path_class_methods.rb +23 -2
  14. data/lib/fun_with/files/file_permission_methods.rb +18 -7
  15. data/lib/fun_with/files/file_requirements.rb +63 -7
  16. data/lib/fun_with/files/requirements/manager.rb +104 -0
  17. data/lib/fun_with/files/root_path.rb +3 -3
  18. data/lib/fun_with/files/stat_methods.rb +33 -0
  19. data/lib/fun_with/files/string_behavior.rb +6 -2
  20. data/lib/fun_with/files/utils/byte_size.rb +143 -0
  21. data/lib/fun_with/files/utils/opts.rb +26 -0
  22. data/lib/fun_with/files/utils/succession.rb +47 -0
  23. data/lib/fun_with/files/utils/timestamp.rb +47 -0
  24. data/lib/fun_with/files/utils/timestamp_format.rb +31 -0
  25. data/lib/fun_with/files/watcher.rb +157 -0
  26. data/lib/fun_with/files/watchers/directory_watcher.rb +67 -0
  27. data/lib/fun_with/files/watchers/file_watcher.rb +45 -0
  28. data/lib/fun_with/files/watchers/missing_watcher.rb +23 -0
  29. data/lib/fun_with/files/watchers/node_watcher.rb +44 -0
  30. data/lib/fun_with/testing/assertions/fun_with_files.rb +91 -0
  31. data/lib/fun_with/testing/test_case_extensions.rb +12 -0
  32. data/lib/fun_with_files.rb +5 -75
  33. data/test/helper.rb +13 -5
  34. data/test/test_core_extensions.rb +5 -0
  35. data/test/test_directory_builder.rb +29 -10
  36. data/test/test_extension_methods.rb +62 -0
  37. data/test/test_file_manipulation.rb +2 -2
  38. data/test/test_file_path.rb +18 -39
  39. data/test/test_file_requirements.rb +36 -0
  40. data/test/test_fun_with_files.rb +1 -1
  41. data/test/test_fwf_assertions.rb +62 -0
  42. data/test/test_moving_files.rb +111 -0
  43. data/test/test_permission_methods.rb +22 -0
  44. data/test/test_root_path.rb +9 -0
  45. data/test/test_stat_methods.rb +17 -0
  46. data/test/test_timestamping.rb +74 -0
  47. data/test/test_utils_bytesize.rb +71 -0
  48. data/test/test_utils_succession.rb +30 -0
  49. data/test/test_watchers.rb +196 -0
  50. metadata +54 -16
@@ -0,0 +1,45 @@
1
+
2
+ module FunWith
3
+ module Files
4
+ module Watchers
5
+ class FileWatcher < NodeWatcher
6
+ attr_accessor :last_modified
7
+
8
+ def initialize( path )
9
+ set_path( path )
10
+ refresh_last_modified
11
+ end
12
+
13
+ def refresh_last_modified
14
+ self.last_modified = self.path.stat.mtime if self.path.exist?
15
+ end
16
+
17
+ def modified?
18
+ self.path.exist? && self.last_modified < self.path.stat.mtime
19
+ end
20
+
21
+ def deleted?
22
+ ! self.path.exist?
23
+ end
24
+
25
+ def update
26
+ if deleted?
27
+ { self.path => :deleted }
28
+ elsif modified?
29
+ refresh_last_modified
30
+ { self.path => :modified }
31
+ else
32
+ {}
33
+ end
34
+ end
35
+
36
+ # returns all paths below it in the hierarchy, including
37
+ # the path of the node itself. In this case, there's
38
+ # only one path to return.
39
+ def all_paths
40
+ [self.path]
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,23 @@
1
+ module FunWith
2
+ module Files
3
+ module Watchers
4
+ # Watches a path where nothing currently exists, and reports a change if
5
+ # something appears there.
6
+ class MissingWatcher < NodeWatcher
7
+ def initialize( path )
8
+ set_path( path )
9
+ end
10
+
11
+ # The fact that the watcher now needs to be replaced with a File/DirectoryWatcher
12
+ # must be handled elsewhere.
13
+ def update
14
+ self.path.exist? ? {self.path => :created } : {}
15
+ end
16
+
17
+ def all_paths
18
+ []
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,44 @@
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+ module FunWith
14
+ module Files
15
+ module Watchers
16
+ class NodeWatcher
17
+ attr_accessor :path
18
+
19
+ def set_path( path )
20
+ self.path = path.fwf_filepath
21
+ end
22
+
23
+ def create_watchers( paths )
24
+ {}.tap do |watchers|
25
+ for path in paths
26
+ watchers[path.fwf_filepath] = Watcher.factory( path )
27
+ end
28
+ end
29
+ end
30
+
31
+ # sets up an object variable for changes, then clears it and returns
32
+ # the changes. I got sick of passing the changes hash around.
33
+ def new_changeset( &block )
34
+ @changes = {}
35
+ yield
36
+
37
+ changes = @changes
38
+ @changes = {}
39
+ changes
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,91 @@
1
+ module FunWith
2
+ module Testing
3
+ module Assertions
4
+ module FunWithFiles
5
+ # The object given must be an instance of class FilePath
6
+ def assert_fwf_filepath( file, msg = nil )
7
+ msg = message(msg){ "File <#{file}> should be a FunWith::Files::FilePath" }
8
+ assert_kind_of FunWith::Files::FilePath, file, msg
9
+ end
10
+
11
+ # The object given is an instance of class FilePath, and points to
12
+ # a file that exists.
13
+ def assert_file( file, msg = nil )
14
+ assert_fwf_filepath( file, message(nil){ "...is not a file." } )
15
+
16
+ msg = message(msg){ "File should exist at <#{file}>." }
17
+ assert file.file?, msg
18
+ end
19
+
20
+ # The object given is a filepath, but doesn't point to
21
+ # an existing file or directory.
22
+ def assert_no_file( file, msg = nil )
23
+ assert_fwf_filepath( file, message )
24
+ msg = message(msg){ "No file/directory should exist at <#{file}>." }
25
+ refute file.file?, msg
26
+ end
27
+
28
+ # The object given is a filepath, and points to a directory
29
+ def assert_directory( file, msg = nil )
30
+ assert_fwf_filepath( file, msg )
31
+ msg = message(msg){ "<#{file}> should be a directory." }
32
+ assert file.directory?, msg
33
+ end
34
+
35
+ # The object given is a filepath, but doesn't point to a directory.
36
+ def assert_not_directory( file, msg = nil )
37
+ assert_fwf_filepath( file, message )
38
+ msg = message(msg){ "<#{file}> shouldn't be a directory." }
39
+ refute file.directory?
40
+ end
41
+
42
+ # The object given is a filepath.
43
+ # It points to a file that exists.
44
+ # That file is empty.
45
+ def assert_empty_file( file, msg = nil )
46
+ assert_fwf_filepath( file )
47
+ msg = message(msg){ "Empty file should exist at <#{file}>." }
48
+ assert file.file? && file.empty?, msg
49
+ end
50
+
51
+ # The object given is a filepath.
52
+ # It points to a directory that exists.
53
+ # That directory is empty.
54
+ def assert_empty_directory( file, msg = nil )
55
+ assert_fwf_filepath( file )
56
+ msg = message(msg){ "Empty directory should exist at <#{file}>." }
57
+ assert file.directory? && file.empty?, msg
58
+ end
59
+
60
+
61
+ # The object given is a filepath.
62
+ # It points to a file that exists.
63
+ # That file contains content.
64
+ def assert_file_has_content( file, msg = nil )
65
+ assert_fwf_filepath( file, message )
66
+ msg = message(msg){ "File should exist at <#{file}>, and have content." }
67
+ assert file.exist?, msg.call + "(file does not exist)"
68
+ assert file.file?, msg.call + "(not a file)"
69
+ refute file.empty?, msg.call + "(file is not empty)"
70
+ end
71
+
72
+ alias :assert_file_not_empty :assert_file_has_content
73
+
74
+
75
+ def assert_file_contents( file, content, msg = nil )
76
+ assert_file( file )
77
+
78
+ case content
79
+ when String
80
+ # message = build_message( message, "File <#{file}> contents should be #{content[0..99].inspect}#{'...(truncated)' if content.length > 100}" )
81
+ assert_equal( content, file.read, msg )
82
+ when Regexp
83
+ assert_match( content, file.read, msg )
84
+ end
85
+ end
86
+
87
+
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,12 @@
1
+ # The bulk of FunWith::Testing::TestCase can be found in the fun_with_testing gem.
2
+
3
+ module FunWith
4
+ module Testing
5
+ module TestCaseExtensions
6
+ def install_fun_with_files_assertions
7
+ include FunWith::Testing::Assertions::Basics # some of the FWF assertions rely on these
8
+ include FunWith::Testing::Assertions::FunWithFiles
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,82 +1,12 @@
1
1
  require 'xdg'
2
2
  require 'digest' # stdlib
3
3
  require 'pathname' # stdlib
4
+ require 'set'
4
5
  require 'tmpdir' # Dir.tmpdir
5
6
 
7
+ require 'debug'
6
8
 
7
- # Do the bare minimum to get FilePath.requir working
8
- # file_path = File.join( "fun_with", "files", "file_path" )
9
- # string_behavior = File.join( "fun_with", "files", "string_behavior" )
10
- #
11
- #
12
- # require_relative file_path
13
- # require_relative string_behavior
14
- #
15
- # FunWith::Files::FilePath.send( :include, FunWith::Files::StringBehavior )
16
- # FunWith::Files::FilePath.new( "fun_with" ).requir
17
- #
18
- # debugger
9
+ require_relative 'fun_with/files/bootstrapper'
10
+ # sets up everything needed to load .requir(), which loads everything else
11
+ FunWith::Files::Bootstrapper.bootstrap
19
12
 
20
-
21
-
22
- core_extension_folder = File.join( "lib", "fun_with", "files", "core_extensions" )
23
-
24
- for fil in Dir.glob( File.join( core_extension_folder, "*.rb" ) )
25
- # Dir.glob targets the root directory, while require_relative is relative to lib/,
26
- # so the [4..-4] removes the leading lib/ and the trailing extension to make it
27
- # require_relative-friendly.
28
- require_path = fil[4..-4] #
29
- basename = File.basename( fil )[0..-4]
30
- # debugger if basename =~ /class/
31
-
32
- target_class_str = basename.split( "_" ).map(&:capitalize).join("")
33
- target_class = Kernel.const_get( target_class_str )
34
- mixin_class_str = "FunWith::Files::CoreExtensions::#{target_class_str}"
35
-
36
- # puts "Basename: #{basename}"
37
- # puts "Mixin: " + mixin_class_str.inspect
38
- # puts "Target: #{target_class}"
39
- # puts "requiring: #{require_path}"
40
- require_relative require_path
41
- mixin_class = Kernel.const_get( mixin_class_str )
42
- # puts mixin_class.to_s
43
-
44
- target_class.send( :include, mixin_class )
45
- end
46
-
47
-
48
-
49
- # for fil in ["string", "array", "false", "hash", "nil", "object",]
50
- # require_relative File.join( "fun_with", "files", "core_extensions", fil )
51
- # end
52
- #
53
- # for klass in ["String", "Object", "NilClass", "Hash", "FalseClass", "Array", "Set"]
54
- # puts klass
55
- # debugger if klass == "Set"
56
- # Kernel.const_get(klass).send( :include, FunWith::Files::CoreExtensions.const_get(klass))
57
- # end
58
- #
59
-
60
- for fil in ["file_path", "string_behavior", "file_manipulation_methods", "file_permission_methods", "digest_methods", "file_requirements"]
61
- require_relative File.join( "fun_with", "files", fil )
62
- end
63
-
64
-
65
- # These have some FilePath methods required by .requir()
66
- for mod in [ FunWith::Files::StringBehavior,
67
- FunWith::Files::FileManipulationMethods,
68
- FunWith::Files::FilePermissionMethods,
69
- FunWith::Files::DigestMethods,
70
- FunWith::Files::FileRequirements ]
71
- FunWith::Files::FilePath.send( :include, mod )
72
- end
73
-
74
- lib_dir = File.dirname(__FILE__).fwf_filepath( "fun_with" )
75
-
76
- # And requir() everything else
77
- lib_dir.requir
78
-
79
- FunWith::Files::RootPath.rootify( FunWith::Files, __FILE__.fwf_filepath.dirname.up )
80
- FunWith::Files::FilePath.extend( FunWith::Files::FilePathClassMethods )
81
-
82
- FunWith::Files.extend( FunWith::Files::GemAPI )
data/test/helper.rb CHANGED
@@ -21,13 +21,21 @@ require 'fun_with_files'
21
21
 
22
22
  class FunWith::Files::TestCase < FunWith::Testing::TestCase
23
23
  include FunWith::Files
24
- include FunWith::Testing::Assertions::FunWithFiles
25
- include FunWith::Testing::Assertions::Basics
24
+ include FunWith::Files::Errors
25
+
26
+
27
+ self.install_fun_with_files_assertions
28
+ # include FunWith::Testing::Assertions::FunWithFiles
29
+ # include FunWith::Testing::Assertions::Basics
26
30
 
27
31
  def tmpdir( &block )
28
- FilePath.tmpdir do |d|
29
- @tmpdir = d
30
- yield
32
+ if block_given?
33
+ FilePath.tmpdir do |d|
34
+ @tmpdir = d
35
+ yield
36
+ end
37
+ else
38
+ @tmpdir = FilePath.tmpdir # remember to remove the directory when you're done
31
39
  end
32
40
  end
33
41
 
@@ -28,5 +28,10 @@ class TestCoreExtensions < FunWith::Files::TestCase
28
28
  assert_equal true, {}.fwf_blank?
29
29
  assert_equal true, true.fwf_present?
30
30
  end
31
+
32
+ should "respond to fwf_filepath" do
33
+ assert_respond_to ".", :fwf_filepath
34
+ assert_respond_to ".".fwf_filepath, :fwf_filepath
35
+ end
31
36
  end
32
37
  end
@@ -54,7 +54,7 @@ class TestDirectoryBuilder < FunWith::Files::TestCase
54
54
  gemfile = b.current_path.join("Gemfile")
55
55
  assert gemfile.exist?
56
56
  assert !gemfile.zero?
57
- assert_equal 1, gemfile.grep( /juwelier/ ).length
57
+ assert_equal 1, gemfile.grep( /fun_with_testing/ ).length
58
58
  end
59
59
  end
60
60
 
@@ -70,18 +70,37 @@ class TestDirectoryBuilder < FunWith::Files::TestCase
70
70
  should "download random crap from all over the Internet" do
71
71
  if_internet_works do
72
72
  DirectoryBuilder.tmpdir do |b|
73
- gist_url = "http://bannedsorcery.com/downloads/testfile.txt"
74
- gist_text = "This is a file\n==============\n\n**silent**: But _bold_! [Link](http://slashdot.org)\n"
75
- b.download( gist_url, "gist.txt", :md5 => "f498e76ea5690a4c29ef97d0a1d8e58e", :sha1 => "ccabf74107cba7ad69f70e45c04c3876e7f34630" )
73
+ # The file Bryce uses on Github to prove to Keybase that he owns this Github account
74
+ # I used to host a test file on my own site, but apparently if you stop paying DigitalOcean
75
+ # for a few measly months your website goes away. Github will probably provide a more
76
+ # stable target.
77
+ url = "https://gist.githubusercontent.com/darthschmoo/ac3ca60338ed41e87b94448f9e851fd3/raw" +
78
+ "/3cba6b60b552266f4d5aa92d307ef2cda0cf228b/fun_with_files.download.txt"
79
+
80
+ dest_file = "download.01.txt"
81
+ dest_file2 = "download.02.txt"
82
+
83
+ downloaded_text = "You have successfully downloaded a file. Huzzah!"
84
+ downloaded_text_md5 = "2e9d3a924ea36c860c3dd491166ec1ce"
85
+ downloaded_text_sha1 = "d9be1d5b5c8bd1de6b1dcb99e02cab8e35ed9659"
86
+ downloaded_text_sha256 = "dc9a6e5d571b39b9754b9592a3b586db8186121d37ec72f7fcbf45241cc43aa6"
87
+
88
+ b.download( url, dest_file,
89
+ :md5 => downloaded_text_md5,
90
+ :sha1 => downloaded_text_sha1,
91
+ :sha256 => downloaded_text_sha256
92
+ )
93
+
76
94
 
77
- b.file( "gist.txt.2" ) do
78
- b.download( gist_url )
95
+ b.file( dest_file2 ) do
96
+ b.download( url )
79
97
  end
80
98
 
81
99
  assert b.current_file.nil?
82
- assert b.current_path.join("gist.txt").exist?
83
- assert b.current_path.join("gist.txt.2").exist?
84
- assert_equal gist_text, b.current_path.join("gist.txt").read
100
+ assert b.current_path.join( dest_file ).exist?
101
+ assert b.current_path.join( dest_file2 ).exist?
102
+ assert_equal downloaded_text, b.current_path.join( dest_file ).read
103
+ assert_equal downloaded_text, b.current_path.join( dest_file2 ).read
85
104
  end
86
105
  end
87
106
  end
@@ -112,7 +131,7 @@ class TestDirectoryBuilder < FunWith::Files::TestCase
112
131
  end
113
132
  end
114
133
 
115
- assert "Hello", b.current_path.join("earth", "air", "fire", "water", "hello.txt").read
134
+ assert_equal "Hello", b.current_path.join("earth", "air", "fire", "water", "hello.txt").read
116
135
 
117
136
  b.dir( "fire", "water", "earth", "air" ) do
118
137
  assert b.current_path.exist?
@@ -0,0 +1,62 @@
1
+ require 'helper'
2
+
3
+ class TestExtensionMethods < FunWith::Files::TestCase
4
+ context "Testing extension methods" do
5
+ setup do
6
+ @bash = "/bin/bash".fwf_filepath
7
+ @log = "/var/log/apache/access.log".fwf_filepath
8
+ @older_log = "/var/log/apache/access.log.9"
9
+ end
10
+
11
+ context "Testing ext?()" do
12
+ should "correctly identify the extension" do
13
+ assert_true @bash.ext?("")
14
+
15
+ assert_true @log.ext?(".log")
16
+ assert_true @log.ext?(:log)
17
+ assert_false @log.ext?(".blog")
18
+ assert_true @log.ext?(:blog, :flog, :frog, :log)
19
+ end
20
+
21
+ should "run a block if the extension matches" do
22
+ var = 5
23
+
24
+ @log.ext?(:log) do |f|
25
+ assert_equal @log, f
26
+ var = 6
27
+ end
28
+
29
+ assert_equal 6, var
30
+ end
31
+ end
32
+
33
+ context "Testing file.ext()" do
34
+
35
+ should "draw a blank on bash file" do
36
+ assert_blank @bash.ext
37
+ assert_equal "", @bash.ext
38
+ end
39
+
40
+ should "add an extension when an extension is given as an argument" do
41
+ bash2 = @bash.ext( 12 )
42
+
43
+ assert_fwf_filepath bash2
44
+ assert_equal "12", bash2.ext
45
+
46
+ for ext in [:exe, "exe"]
47
+ bash2 = @bash.ext( ext )
48
+ assert_fwf_filepath bash2
49
+ assert_equal "exe", bash2.ext
50
+ end
51
+ end
52
+
53
+ should "add multiple extensions when multiple extensions are given" do
54
+ for args in [ [:tar, :gz], ["tar", "gz"], [".tar", ".gz"] ]
55
+ bash2 = @bash.ext( *args )
56
+ assert_equal "gz", bash2.ext
57
+ assert_equal "/bin/bash.tar.gz", bash2.path
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -21,9 +21,9 @@ class TestFileManipulation < FunWith::Files::TestCase
21
21
  should "gsub copy of license.txt" do
22
22
  copied = @license.cp( "test", "tmp" )
23
23
  copied.file_gsub!( /Bryce Anderson/, "Wilford Brimley" )
24
- assert copied.size > 1000
24
+ assert copied.size > 1000, "File is too small"
25
25
 
26
- assert_file_contents copied, /Wilford Brimley/
26
+ assert_file_contents copied, /Wilford Brimley/, "Error 441: Wilford Brimley not found"
27
27
  end
28
28
 
29
29
  should "empty files and directories" do
@@ -10,17 +10,17 @@ class TestFilePath < FunWith::Files::TestCase
10
10
  end
11
11
 
12
12
  should "have location class methods available" do
13
- assert_respond_to( FunWith::Files::FilePath, :home )
14
- assert_respond_to( FunWith::Files::FilePath, :config_dir )
15
- assert_respond_to( FunWith::Files::FilePath, :root )
16
- assert_respond_to( FunWith::Files::FilePath, :data_dir )
13
+ assert_respond_to FunWith::Files::FilePath, :home
14
+ assert_respond_to FunWith::Files::FilePath, :config_dir
15
+ assert_respond_to FunWith::Files::FilePath, :root
16
+ assert_respond_to FunWith::Files::FilePath, :data_dir
17
17
  end
18
18
 
19
19
 
20
20
  should "join smoothly" do
21
21
  bin_dir = "/bin".fwf_filepath
22
- assert_equal( "/bin/bash", bin_dir.join("bash").to_s )
23
- assert_equal( "/bin/bash", bin_dir.join("bash".fwf_filepath).to_s )
22
+ assert_equal "/bin/bash", bin_dir.join("bash").to_s
23
+ assert_equal "/bin/bash", bin_dir.join("bash".fwf_filepath).to_s
24
24
  end
25
25
 
26
26
  should "go up/down when asked" do
@@ -99,17 +99,20 @@ class TestFilePath < FunWith::Files::TestCase
99
99
  should "sequence files nicely" do
100
100
  seqfile = @tmp_dir.join("sequence.txt")
101
101
 
102
+ files = [seqfile]
103
+
102
104
  10.times do |i|
103
105
  seqfile.write( i.to_s )
104
106
  seqfile = seqfile.succ
107
+ files << seqfile
105
108
  end
106
109
 
107
- assert_file @tmp_dir.join("sequence.txt")
108
- assert_file @tmp_dir.join("sequence.000000.txt")
109
- assert_file @tmp_dir.join("sequence.000008.txt")
110
+ assert_file files[0]
111
+ assert_file files[1]
112
+ assert_file files[9]
110
113
 
111
- assert_file_contents @tmp_dir.join("sequence.txt"), "0"
112
- assert_file_contents @tmp_dir.join("sequence.000008.txt"), "9"
114
+ assert_file_contents files[0], "0"
115
+ assert_file_contents files[9], "9"
113
116
  end
114
117
 
115
118
  should "sequence files with custom stamp length" do
@@ -128,35 +131,7 @@ class TestFilePath < FunWith::Files::TestCase
128
131
  assert_file_contents @tmp_dir.join("sequence.0008.txt"), "9"
129
132
  end
130
133
 
131
- should "sequence files with datestamps" do
132
- seqfile = @tmp_dir.join("sequence.txt")
133
-
134
- 10.times do |i|
135
- seqfile.write( i.to_s )
136
- seqfile = seqfile.succ( timestamp: true )
137
- sleep(0.002)
138
- end
139
-
140
- files = seqfile.succession( timestamp: true )
141
- assert files.length == 10
142
-
143
- files.each_with_index do |file, i|
144
- assert_file file
145
- assert_file_contents file, i.to_s
146
- end
147
-
148
- file_name_strings = files.map(&:to_s)
149
- assert_equal file_name_strings[1..-1], file_name_strings[1..-1].sort
150
- end
151
-
152
- should "timestamp files using the timestamp() method" do
153
- timestampable_file = @tmp_dir.join( "timestamped.dat" )
154
- timestamped_file1 = timestampable_file.timestamp
155
- timestamped_file2 = timestampable_file.timestamp("%Y")
156
134
 
157
- assert timestamped_file1 =~ /timestamped.\d{17}.dat$/
158
- assert timestamped_file2 =~ /timestamped.\d{4}.dat$/
159
- end
160
135
  end
161
136
 
162
137
 
@@ -294,4 +269,8 @@ class TestFilePath < FunWith::Files::TestCase
294
269
  assert_equal expected, result
295
270
  end
296
271
  end
272
+
273
+ context "testing block form" do
274
+
275
+ end
297
276
  end
@@ -0,0 +1,36 @@
1
+ require 'helper'
2
+
3
+ class TestFileRequirements < FunWith::Files::TestCase
4
+ context "testing FileRequirements methods" do
5
+ setup do
6
+ @tmp_dir = FunWith::Files.root("test", "tmp")
7
+ @file = @tmp_dir.join("file.txt").touch
8
+ @dir = @tmp_dir.join("dir").touch_dir
9
+ end
10
+
11
+ teardown do
12
+ empty_temp_directory
13
+ end
14
+
15
+ context "needs_to_exist()" do
16
+ should "raise an error when a file doesn't exist" do
17
+ assert_raises Errno::ENOENT do
18
+ @tmp_dir.join("missing_file.txt").needs_to_exist
19
+ end
20
+ end
21
+
22
+ should "raise an error when a file isn't empty" do
23
+ assert_raises Errors::FileNotEmpty do
24
+ @file.append("Zorpy was here")
25
+ @file.needs_to_be_empty
26
+ end
27
+ end
28
+
29
+ should "raise an error when a file oughta be a directory" do
30
+ assert_raises Errors::NotADirectory do
31
+ @file.must_be_directory
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -26,7 +26,7 @@ class TestFunWithFiles < FunWith::Files::TestCase
26
26
  assert_respond_to( FunWith::Files, :root )
27
27
  assert_respond_to( FunWith::Files, :version )
28
28
 
29
- assert_equal "0.0.14", FunWith::Files.version # Gotta change with every point release. Ick.
29
+ assert_equal "0.0.17", FunWith::Files.version # Gotta change with every point release. Ick.
30
30
  end
31
31
  end
32
32
  end