fakefs 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -1,21 +1,30 @@
1
- * Chris Wanstrath
2
- * Scott Taylor
3
- * Jeff Hodges
4
- * Pat Nakajima
5
- * Myles Eftos
6
- * Matt Freels
7
- * Nick Quaranto
8
- * Tymon Tobolski
9
- * Ben Mabey
10
- * Jon Yurek
11
- * Scott Barron
12
- * dmathieu
13
- * Rob Sanheim
14
- * David Reese
15
- * msassak
16
- * Sam Goldstein
17
- * jameswilding
18
- * Greg Campbell
19
- * Thiago Marano
20
- * Víctor Martínez
21
- * Victor Costan
1
+ Scott Taylor <scott@railsnewbie.com>
2
+ Pat Nakajima <patnakajima@gmail.com>
3
+ Chris Wanstrath <chris@ozmm.org>
4
+ Myles Eftos <myles@madpilot.com.au>
5
+ Jeff Hodges <jeff@somethingsimilar.com>
6
+ Matt Freels <matt@freels.name>
7
+ Víctor Martínez <knoopx@gmail.com>
8
+ Nick Quaranto <nick@quaran.to>
9
+ Aaron Suggs <aaron@ktheory.com>
10
+ Victor Costan <costan@gmail.com>
11
+ Eric MSP Veith <eveith@wwweb-library.net>
12
+ Jon Yurek <jyurek@thoughtbot.com>
13
+ Greg Campbell <gtcampbell@gmail.com>
14
+ Ben Mabey <ben@benmabey.com>
15
+ Mark <mark@amerine.net>
16
+ Sam Goldstein <sam@aboutus.org>
17
+ Noah Paessel <knowuh@gmail.com>
18
+ dmathieu <42@dmathieu.com>
19
+ Mariusz Pietrzyk <wijet@wijet.pl>
20
+ Lars Gierth <lars.gierth@gmail.com>
21
+ marano <thiagomarano@gmail.com>
22
+ jameswilding <james@jameswilding.net>
23
+ Tymon Tobolski <i@teamon.eu>
24
+ Scott Barron <scott@elitists.net>
25
+ Keita Urashima <ursm@ursm.jp>
26
+ David Reese <david@whatcould.com>
27
+ msassak <msassak@gmail.com>
28
+ timo3377 <tim.linquist@gmail.com>
29
+ Mislav Marohnić <mislav.marohnic@gmail.com>
30
+ Rob Sanheim <rsanheim@gmail.com>
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source :rubygems
2
+
3
+ group :development do
4
+ gem 'rspec'
5
+ gem 'jeweler'
6
+ gem 'sdoc-helpers'
7
+ gem 'rdiscount'
8
+ end
@@ -0,0 +1,35 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.2)
5
+ git (1.2.5)
6
+ jeweler (1.6.0)
7
+ bundler (~> 1.0.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ json (1.5.1)
11
+ rake (0.8.7)
12
+ rdiscount (1.6.8)
13
+ rdoc (2.4.3)
14
+ rspec (2.5.0)
15
+ rspec-core (~> 2.5.0)
16
+ rspec-expectations (~> 2.5.0)
17
+ rspec-mocks (~> 2.5.0)
18
+ rspec-core (2.5.1)
19
+ rspec-expectations (2.5.0)
20
+ diff-lcs (~> 1.1.2)
21
+ rspec-mocks (2.5.0)
22
+ sdoc (0.2.20)
23
+ json (>= 1.1.3)
24
+ rdoc (= 2.4.3)
25
+ sdoc-helpers (0.1.4)
26
+ sdoc (~> 0.2)
27
+
28
+ PLATFORMS
29
+ ruby
30
+
31
+ DEPENDENCIES
32
+ jeweler
33
+ rdiscount
34
+ rspec
35
+ sdoc-helpers
data/Rakefile CHANGED
@@ -8,16 +8,9 @@ end
8
8
 
9
9
  task :default => [:test, :spec]
10
10
 
11
- begin
12
- require 'spec/rake/spectask'
13
-
14
- desc "Run specs"
15
- Spec::Rake::SpecTask.new(:spec) do |t|
16
- t.spec_files = FileList["spec/**/*.rb"]
17
- end
18
- rescue LoadError
19
- puts "Spec task can't be loaded. `gem install rspec`"
20
- end
11
+ require 'rspec/core/rake_task'
12
+ desc "Run specs"
13
+ RSpec::Core::RakeTask.new
21
14
 
22
15
  begin
23
16
  require 'jeweler'
@@ -59,3 +52,8 @@ task :publish => [ :gemspec, :build ] do
59
52
  system "git clean -fd"
60
53
  exec "rake pages"
61
54
  end
55
+
56
+ desc "Update contributors"
57
+ task :update_contributors do
58
+ sh "git-rank-contributors > CONTRIBUTORS"
59
+ end
@@ -1,86 +1,84 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{fakefs}
8
- s.version = "0.3.1"
8
+ s.version = "0.3.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Chris Wanstrath", "Scott Taylor", "Jeff Hodges", "Pat Nakajima"]
12
- s.date = %q{2010-12-18}
12
+ s.date = %q{2011-05-02}
13
13
  s.description = %q{A fake filesystem. Use it in your tests.}
14
14
  s.email = %q{chris@ozmm.org}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.markdown"
17
+ "README.markdown"
18
18
  ]
19
19
  s.files = [
20
20
  ".autotest",
21
- ".gitignore",
22
- "CONTRIBUTORS",
23
- "LICENSE",
24
- "README.markdown",
25
- "Rakefile",
26
- "fakefs.gemspec",
27
- "lib/fakefs.rb",
28
- "lib/fakefs/base.rb",
29
- "lib/fakefs/dir.rb",
30
- "lib/fakefs/fake/dir.rb",
31
- "lib/fakefs/fake/file.rb",
32
- "lib/fakefs/fake/symlink.rb",
33
- "lib/fakefs/file.rb",
34
- "lib/fakefs/file_system.rb",
35
- "lib/fakefs/file_test.rb",
36
- "lib/fakefs/fileutils.rb",
37
- "lib/fakefs/safe.rb",
38
- "lib/fakefs/spec_helpers.rb",
39
- "lib/fakefs/version.rb",
40
- "spec/fakefs/spec_helpers_spec.rb",
41
- "spec/spec.opts",
42
- "spec/spec_helper.rb",
43
- "test/fake/file/lstat_test.rb",
44
- "test/fake/file/stat_test.rb",
45
- "test/fake/file/sysseek_test.rb",
46
- "test/fake/file/syswrite_test.rb",
47
- "test/fake/file_test.rb",
48
- "test/fake/symlink_test.rb",
49
- "test/fakefs_test.rb",
50
- "test/file/stat_test.rb",
51
- "test/safe_test.rb",
52
- "test/test_helper.rb",
53
- "test/verify.rb"
21
+ ".rspec",
22
+ "CONTRIBUTORS",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE",
26
+ "README.markdown",
27
+ "Rakefile",
28
+ "fakefs.gemspec",
29
+ "lib/fakefs.rb",
30
+ "lib/fakefs/base.rb",
31
+ "lib/fakefs/dir.rb",
32
+ "lib/fakefs/fake/dir.rb",
33
+ "lib/fakefs/fake/file.rb",
34
+ "lib/fakefs/fake/symlink.rb",
35
+ "lib/fakefs/file.rb",
36
+ "lib/fakefs/file_system.rb",
37
+ "lib/fakefs/file_test.rb",
38
+ "lib/fakefs/fileutils.rb",
39
+ "lib/fakefs/safe.rb",
40
+ "lib/fakefs/spec_helpers.rb",
41
+ "lib/fakefs/version.rb",
42
+ "spec/fakefs/spec_helpers_spec.rb",
43
+ "spec/spec.opts",
44
+ "spec/spec_helper.rb",
45
+ "test/fake/file/join_test.rb",
46
+ "test/fake/file/lstat_test.rb",
47
+ "test/fake/file/stat_test.rb",
48
+ "test/fake/file/sysseek_test.rb",
49
+ "test/fake/file/syswrite_test.rb",
50
+ "test/fake/file_test.rb",
51
+ "test/fake/symlink_test.rb",
52
+ "test/fakefs_test.rb",
53
+ "test/file/stat_test.rb",
54
+ "test/safe_test.rb",
55
+ "test/test_helper.rb",
56
+ "test/verify.rb"
54
57
  ]
55
58
  s.homepage = %q{http://github.com/defunkt/fakefs}
56
- s.rdoc_options = ["--charset=UTF-8"]
57
59
  s.require_paths = ["lib"]
58
- s.rubygems_version = %q{1.3.7}
60
+ s.rubygems_version = %q{1.6.2}
59
61
  s.summary = %q{A fake filesystem. Use it in your tests.}
60
- s.test_files = [
61
- "spec/fakefs/spec_helpers_spec.rb",
62
- "spec/spec_helper.rb",
63
- "test/fake/file/lstat_test.rb",
64
- "test/fake/file/stat_test.rb",
65
- "test/fake/file/sysseek_test.rb",
66
- "test/fake/file/syswrite_test.rb",
67
- "test/fake/file_test.rb",
68
- "test/fake/symlink_test.rb",
69
- "test/fakefs_test.rb",
70
- "test/file/stat_test.rb",
71
- "test/safe_test.rb",
72
- "test/test_helper.rb",
73
- "test/verify.rb"
74
- ]
75
62
 
76
63
  if s.respond_to? :specification_version then
77
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
78
64
  s.specification_version = 3
79
65
 
80
66
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
67
+ s.add_development_dependency(%q<rspec>, [">= 0"])
68
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
69
+ s.add_development_dependency(%q<sdoc-helpers>, [">= 0"])
70
+ s.add_development_dependency(%q<rdiscount>, [">= 0"])
81
71
  else
72
+ s.add_dependency(%q<rspec>, [">= 0"])
73
+ s.add_dependency(%q<jeweler>, [">= 0"])
74
+ s.add_dependency(%q<sdoc-helpers>, [">= 0"])
75
+ s.add_dependency(%q<rdiscount>, [">= 0"])
82
76
  end
83
77
  else
78
+ s.add_dependency(%q<rspec>, [">= 0"])
79
+ s.add_dependency(%q<jeweler>, [">= 0"])
80
+ s.add_dependency(%q<sdoc-helpers>, [">= 0"])
81
+ s.add_dependency(%q<rdiscount>, [">= 0"])
84
82
  end
85
83
  end
86
84
 
@@ -78,8 +78,9 @@ module FakeFS
78
78
  Dir.open(dirname) { |file| yield file }
79
79
  end
80
80
 
81
- def self.glob(pattern)
82
- [FileSystem.find(pattern) || []].flatten.map{|e| e.to_s}.sort
81
+ def self.glob(pattern, &block)
82
+ files = [FileSystem.find(pattern) || []].flatten.map(&:to_s).sort
83
+ block_given? ? files.each { |file| block.call(file) } : files
83
84
  end
84
85
 
85
86
  def self.mkdir(string, integer = 0)
@@ -106,6 +107,52 @@ module FakeFS
106
107
  FileSystem.current_dir.to_s
107
108
  end
108
109
 
110
+ # This code has been borrowed from Rubinius
111
+ def self.mktmpdir(prefix_suffix = nil, tmpdir = nil)
112
+ case prefix_suffix
113
+ when nil
114
+ prefix = "d"
115
+ suffix = ""
116
+ when String
117
+ prefix = prefix_suffix
118
+ suffix = ""
119
+ when Array
120
+ prefix = prefix_suffix[0]
121
+ suffix = prefix_suffix[1]
122
+ else
123
+ raise ArgumentError, "unexpected prefix_suffix: #{prefix_suffix.inspect}"
124
+ end
125
+
126
+ t = Time.now.strftime("%Y%m%d")
127
+ n = nil
128
+
129
+ begin
130
+ path = "#{tmpdir}/#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
131
+ path << "-#{n}" if n
132
+ path << suffix
133
+ mkdir(path, 0700)
134
+ rescue Errno::EEXIST
135
+ n ||= 0
136
+ n += 1
137
+ retry
138
+ end
139
+
140
+ if block_given?
141
+ begin
142
+ yield path
143
+ ensure
144
+ require 'fileutils'
145
+ # This here was using FileUtils.remove_entry_secure instead of just
146
+ # .rm_r. However, the security concerns that apply to
147
+ # .rm_r/.remove_entry_secure shouldn't apply to a test fake
148
+ # filesystem. :^)
149
+ FileUtils.rm_r path
150
+ end
151
+ else
152
+ path
153
+ end
154
+ end
155
+
109
156
  class << self
110
157
  alias_method :getwd, :pwd
111
158
  alias_method :rmdir, :delete
@@ -1,7 +1,7 @@
1
1
  module FakeFS
2
2
  class FakeFile
3
- attr_accessor :name, :parent, :content
4
- attr_reader :ctime, :mtime
3
+ attr_accessor :name, :parent, :content, :mtime
4
+ attr_reader :ctime
5
5
 
6
6
  class Inode
7
7
  def initialize(file_owner)
@@ -33,7 +33,7 @@ module FakeFS
33
33
  end
34
34
 
35
35
  def self.join(*parts)
36
- parts * PATH_SEPARATOR
36
+ RealFile.join(parts)
37
37
  end
38
38
 
39
39
  def self.exist?(path)
@@ -64,6 +64,18 @@ module FakeFS
64
64
  end
65
65
  end
66
66
 
67
+ def self.utime(atime, mtime, *paths)
68
+ paths.each do |path|
69
+ if exists?(path)
70
+ FileSystem.find(path).mtime = mtime
71
+ else
72
+ raise Errno::ENOENT
73
+ end
74
+ end
75
+
76
+ paths.size
77
+ end
78
+
67
79
  def self.size(path)
68
80
  read(path).length
69
81
  end
@@ -136,6 +148,23 @@ module FakeFS
136
148
  read(path).split("\n")
137
149
  end
138
150
 
151
+ def self.rename(source, dest)
152
+ if directory?(source) && file?(dest)
153
+ raise Errno::ENOTDIR, "Not a directory - #{source} or #{dest}"
154
+ elsif file?(source) && directory?(dest)
155
+ raise Errno::EISDIR, "Is a directory - #{source} or #{dest}"
156
+ end
157
+
158
+ if target = FileSystem.find(source)
159
+ FileSystem.add(dest, target.entry.clone)
160
+ FileSystem.delete(source)
161
+ else
162
+ raise Errno::ENOENT, "No such file or directory - #{source} or #{dest}"
163
+ end
164
+
165
+ 0
166
+ end
167
+
139
168
  def self.link(source, dest)
140
169
  if directory?(source)
141
170
  raise Errno::EPERM, "Operation not permitted - #{source} or #{dest}"
@@ -186,6 +215,10 @@ module FakeFS
186
215
  File::Stat.new(file, true)
187
216
  end
188
217
 
218
+ def self.split(path)
219
+ return RealFile.split(path)
220
+ end
221
+
189
222
  class Stat
190
223
  attr_reader :ctime, :mtime
191
224
 
@@ -350,9 +383,7 @@ module FakeFS
350
383
  end
351
384
 
352
385
  def check_file_existence!
353
- unless @file
354
- raise Errno::ENOENT, "No such file or directory - #{@file}"
355
- end
386
+ raise Errno::ENOENT, @path unless @file
356
387
  end
357
388
 
358
389
  def file_creation_mode?
@@ -3,5 +3,9 @@ module FakeFS
3
3
  def self.exist?(file_name)
4
4
  File.exist?(file_name)
5
5
  end
6
+
7
+ def self.directory?(file_name)
8
+ File.directory?(file_name)
9
+ end
6
10
  end
7
11
  end
@@ -6,6 +6,15 @@ module FakeFS
6
6
  FileSystem.add(path, FakeDir.new)
7
7
  end
8
8
  alias_method :mkpath, :mkdir_p
9
+ alias_method :makedirs, :mkdir_p
10
+
11
+ def mkdir(path)
12
+ parent = path.split('/')
13
+ parent.pop
14
+ raise Errno::ENOENT, "No such file or directory - #{path}" unless parent.join == "" || FileSystem.find(parent.join('/'))
15
+ raise Errno::EEXIST, "File exists - #{path}" if FileSystem.find(path)
16
+ FileSystem.add(path, FakeDir.new)
17
+ end
9
18
 
10
19
  def rmdir(list, options = {})
11
20
  list = [ list ] unless list.is_a?(Array)
@@ -87,11 +96,14 @@ module FakeFS
87
96
  end
88
97
 
89
98
  def mv(src, dest, options={})
90
- if target = FileSystem.find(src)
91
- FileSystem.add(dest, target.entry.clone)
92
- FileSystem.delete(src)
93
- else
94
- raise Errno::ENOENT, src
99
+ Array(src).each do |path|
100
+ if target = FileSystem.find(path)
101
+ dest_path = File.directory?(dest) ? File.join(dest, File.basename(path)) : dest
102
+ FileSystem.add(dest_path, target.entry.clone)
103
+ FileSystem.delete(path)
104
+ else
105
+ raise Errno::ENOENT, path
106
+ end
95
107
  end
96
108
  end
97
109
 
@@ -1,6 +1,6 @@
1
1
  module FakeFS
2
2
  module Version
3
- VERSION = "0.3.1"
3
+ VERSION = "0.3.2"
4
4
 
5
5
  def self.to_s
6
6
  VERSION
@@ -0,0 +1,19 @@
1
+ require "test_helper"
2
+
3
+ class FileJoin < Test::Unit::TestCase
4
+ def setup
5
+ FakeFS.activate!
6
+ end
7
+
8
+ def teardown
9
+ FakeFS.deactivate!
10
+ end
11
+
12
+ [
13
+ ["a", "b"], ["a/", "b"], ["a", "/b"], ["a/", "/b"], ["a", "/", "b"]
14
+ ].each_with_index do |args, i|
15
+ define_method "test_file_join_#{i}" do
16
+ assert_equal RealFile.join(args), File.join(args)
17
+ end
18
+ end
19
+ end
@@ -83,4 +83,15 @@ class FakeFileTest < Test::Unit::TestCase
83
83
  assert_equal "foo", clone.content
84
84
  assert_equal "bar", @file.content
85
85
  end
86
+
87
+ def test_raises_an_error_with_the_correct_path
88
+ path = "/some/non/existing/file"
89
+ begin
90
+ FakeFS::File.new path
91
+ msg = nil
92
+ rescue Errno::ENOENT => e
93
+ msg = e.message
94
+ end
95
+ assert_equal "No such file or directory - #{path}", msg
96
+ end
86
97
  end
@@ -23,7 +23,7 @@ class FakeFSTest < Test::Unit::TestCase
23
23
  assert_equal 1, fs.files.size
24
24
  end
25
25
 
26
- def test_can_create_directories
26
+ def test_can_create_directories_with_file_utils_mkdir_p
27
27
  FileUtils.mkdir_p("/path/to/dir")
28
28
  assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir']
29
29
  end
@@ -33,6 +33,18 @@ class FakeFSTest < Test::Unit::TestCase
33
33
  assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir']
34
34
  end
35
35
 
36
+ def test_can_create_directories_with_file_utils_mkdir
37
+ FileUtils.mkdir_p("/path/to/dir")
38
+ FileUtils.mkdir("/path/to/dir/subdir")
39
+ assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir']['subdir']
40
+ end
41
+
42
+ def test_raises_error_when_creating_a_new_dir_with_mkdir_in_non_existent_path
43
+ assert_raises Errno::ENOENT do
44
+ FileUtils.mkdir("/this/path/does/not/exists/newdir")
45
+ end
46
+ end
47
+
36
48
  def test_can_create_directories_with_mkpath
37
49
  FileUtils.mkpath("/path/to/dir")
38
50
  assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir']
@@ -43,6 +55,16 @@ class FakeFSTest < Test::Unit::TestCase
43
55
  assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir']
44
56
  end
45
57
 
58
+ def test_can_create_directories_with_mkpath
59
+ FileUtils.makedirs("/path/to/dir")
60
+ assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir']
61
+ end
62
+
63
+ def test_can_create_directories_with_mkpath_and_options
64
+ FileUtils.makedirs("/path/to/dir", :mode => 0755)
65
+ assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir']
66
+ end
67
+
46
68
  def test_can_delete_directories
47
69
  FileUtils.mkdir_p("/path/to/dir")
48
70
  FileUtils.rmdir("/path/to/dir")
@@ -83,6 +105,10 @@ class FakeFSTest < Test::Unit::TestCase
83
105
  assert File.exists?(path)
84
106
  FileUtils.mkdir_p("/path/to")
85
107
  assert File.exists?(path)
108
+ assert_raises Errno::EEXIST do
109
+ FileUtils.mkdir("/path/to")
110
+ end
111
+ assert File.exists?(path)
86
112
  end
87
113
 
88
114
  def test_can_create_symlinks
@@ -384,6 +410,32 @@ class FakeFSTest < Test::Unit::TestCase
384
410
  assert_equal File.stat("foo").mtime, File.mtime("foo")
385
411
  end
386
412
 
413
+ def test_utime_raises_error_if_path_does_not_exist
414
+ assert_raise Errno::ENOENT do
415
+ File.utime(Time.now, Time.now, '/path/to/file.txt')
416
+ end
417
+ end
418
+
419
+ def test_can_call_utime_on_an_existing_file
420
+ time = Time.now - 300 # Not now
421
+ path = '/path/to/file.txt'
422
+ File.open(path, 'w') do |f|
423
+ f << ''
424
+ end
425
+ File.utime(time, time, path)
426
+ assert_equal time, File.mtime('/path/to/file.txt')
427
+ end
428
+
429
+ def test_utime_returns_number_of_paths
430
+ path1, path2 = '/path/to/file.txt', '/path/to/another_file.txt'
431
+ [path1, path2].each do |path|
432
+ File.open(path, 'w') do |f|
433
+ f << ''
434
+ end
435
+ end
436
+ assert_equal 2, File.utime(Time.now, Time.now, path1, path2)
437
+ end
438
+
387
439
  def test_can_read_with_File_readlines
388
440
  path = '/path/to/file.txt'
389
441
  File.open(path, 'w') do |f|
@@ -516,7 +568,6 @@ class FakeFSTest < Test::Unit::TestCase
516
568
  assert_equal ['/path', '/path/bar', '/path/bar/baz', '/path/bar2', '/path/bar2/baz', '/path/foo', '/path/foobar'], Dir['/**/*']
517
569
 
518
570
  assert_equal ['/path/bar', '/path/bar/baz', '/path/bar2', '/path/bar2/baz', '/path/foo', '/path/foobar'], Dir['/path/**/*']
519
-
520
571
  assert_equal ['/path/bar/baz'], Dir['/path/bar/**/*']
521
572
 
522
573
  FileUtils.cp_r '/path', '/otherpath'
@@ -546,6 +597,16 @@ class FakeFSTest < Test::Unit::TestCase
546
597
  assert_equal ['/one/five.rb', '/one/two'], Dir['/one/**']
547
598
  end
548
599
 
600
+ def test_dir_glob_with_block
601
+ FileUtils.touch('foo')
602
+ FileUtils.touch('bar')
603
+
604
+ yielded = []
605
+ Dir.glob('*') { |file| yielded << file }
606
+
607
+ assert_equal 2, yielded.size
608
+ end
609
+
549
610
  def test_should_report_pos_as_0_when_opening
550
611
  File.open("/foo", "w") do |f|
551
612
  f << "foobar"
@@ -741,6 +802,10 @@ class FakeFSTest < Test::Unit::TestCase
741
802
  assert_raise(Errno::ENOENT) do
742
803
  FileUtils.mv 'blafgag', 'foo'
743
804
  end
805
+ exception = assert_raise(Errno::ENOENT) do
806
+ FileUtils.mv ['foo', 'bar'], 'destdir'
807
+ end
808
+ assert_equal "No such file or directory - foo", exception.message
744
809
  end
745
810
 
746
811
  def test_mv_actually_works
@@ -755,6 +820,23 @@ class FakeFSTest < Test::Unit::TestCase
755
820
  assert_equal('bar', File.open('baz') { |f| f.read })
756
821
  end
757
822
 
823
+ def test_mv_to_directory
824
+ File.open('foo', 'w') {|f| f.write 'bar'}
825
+ FileUtils.mkdir_p 'destdir'
826
+ FileUtils.mv 'foo', 'destdir'
827
+ assert_equal('bar', File.open('destdir/foo') {|f| f.read })
828
+ assert File.directory?('destdir')
829
+ end
830
+
831
+ def test_mv_array
832
+ File.open('foo', 'w') {|f| f.write 'bar' }
833
+ File.open('baz', 'w') {|f| f.write 'binky' }
834
+ FileUtils.mkdir_p 'destdir'
835
+ FileUtils.mv %w(foo baz), 'destdir'
836
+ assert_equal('bar', File.open('destdir/foo') {|f| f.read })
837
+ assert_equal('binky', File.open('destdir/baz') {|f| f.read })
838
+ end
839
+
758
840
  def test_cp_actually_works
759
841
  File.open('foo', 'w') {|f| f.write 'bar' }
760
842
  FileUtils.cp('foo', 'baz')
@@ -1241,6 +1323,60 @@ class FakeFSTest < Test::Unit::TestCase
1241
1323
  assert Dir.tmpdir == "/tmp"
1242
1324
  end
1243
1325
 
1326
+ def test_rename_renames_a_file
1327
+ FileUtils.touch("/foo")
1328
+ File.rename("/foo", "/bar")
1329
+ assert File.file?("/bar")
1330
+ end
1331
+
1332
+ def test_rename_returns
1333
+ FileUtils.touch("/foo")
1334
+ assert_equal 0, File.rename("/foo", "/bar")
1335
+ end
1336
+
1337
+ def test_rename_renames_two_files
1338
+ FileUtils.touch("/foo")
1339
+ FileUtils.touch("/bar")
1340
+ File.rename("/foo", "/bar")
1341
+ assert File.file?("/bar")
1342
+ end
1343
+
1344
+ def test_rename_renames_a_directories
1345
+ Dir.mkdir("/foo")
1346
+ File.rename("/foo", "/bar")
1347
+ assert File.directory?("/bar")
1348
+ end
1349
+
1350
+ def test_rename_renames_two_directories
1351
+ Dir.mkdir("/foo")
1352
+ Dir.mkdir("/bar")
1353
+ File.rename("/foo", "/bar")
1354
+ assert File.directory?("/bar")
1355
+ end
1356
+
1357
+ def test_rename_file_to_directory_raises_error
1358
+ FileUtils.touch("/foo")
1359
+ Dir.mkdir("/bar")
1360
+ assert_raises(Errno::EISDIR) do
1361
+ File.rename("/foo", "/bar")
1362
+ end
1363
+ end
1364
+
1365
+ def test_rename_directory_to_file_raises_error
1366
+ Dir.mkdir("/foo")
1367
+ FileUtils.touch("/bar")
1368
+ assert_raises(Errno::ENOTDIR) do
1369
+ File.rename("/foo", "/bar")
1370
+ end
1371
+ end
1372
+
1373
+
1374
+ def test_rename_with_missing_source_raises_error
1375
+ assert_raises(Errno::ENOENT) do
1376
+ File.rename("/no_such_file", "/bar")
1377
+ end
1378
+ end
1379
+
1244
1380
  def test_hard_link_creates_file
1245
1381
  FileUtils.touch("/foo")
1246
1382
 
@@ -1440,6 +1576,14 @@ class FakeFSTest < Test::Unit::TestCase
1440
1576
  assert !FileTest.exist?("/path/to/dir")
1441
1577
  end
1442
1578
 
1579
+ def test_filetest_directory_returns_correct_values
1580
+ FileUtils.mkdir_p '/path/to/somedir'
1581
+ assert FileTest.directory?('/path/to/somedir')
1582
+
1583
+ FileUtils.rm_r '/path/to/somedir'
1584
+ assert !FileTest.directory?('/path/to/somedir')
1585
+ end
1586
+
1443
1587
  def test_pathname_exists_returns_correct_value
1444
1588
  FileUtils.touch "foo"
1445
1589
  assert Pathname.new("foo").exist?
@@ -1447,6 +1591,20 @@ class FakeFSTest < Test::Unit::TestCase
1447
1591
  assert !Pathname.new("bar").exist?
1448
1592
  end
1449
1593
 
1594
+ def test_dir_mktmpdir
1595
+ FileUtils.mkdir '/tmp'
1596
+
1597
+ tmpdir = Dir.mktmpdir
1598
+ assert File.directory?(tmpdir)
1599
+ FileUtils.rm_r tmpdir
1600
+
1601
+ Dir.mktmpdir do |t|
1602
+ tmpdir = t
1603
+ assert File.directory?(t)
1604
+ end
1605
+ assert !File.directory?(tmpdir)
1606
+ end
1607
+
1450
1608
  def test_activating_returns_true
1451
1609
  FakeFS.deactivate!
1452
1610
  assert_equal true, FakeFS.activate!
@@ -1456,6 +1614,15 @@ class FakeFSTest < Test::Unit::TestCase
1456
1614
  assert_equal true, FakeFS.deactivate!
1457
1615
  end
1458
1616
 
1617
+ def test_split
1618
+ assert File.respond_to? :split
1619
+ filename = "/this/is/what/we/expect.txt"
1620
+ path,filename = File.split(filename)
1621
+ assert_equal path, "/this/is/what/we"
1622
+ assert_equal filename, "expect.txt"
1623
+ end
1624
+
1625
+
1459
1626
  def here(fname)
1460
1627
  RealFile.expand_path(File.join(RealFile.dirname(__FILE__), fname))
1461
1628
  end
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fakefs
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 3
9
- - 1
10
- version: 0.3.1
4
+ prerelease:
5
+ version: 0.3.2
11
6
  platform: ruby
12
7
  authors:
13
8
  - Chris Wanstrath
@@ -18,10 +13,53 @@ autorequire:
18
13
  bindir: bin
19
14
  cert_chain: []
20
15
 
21
- date: 2010-12-18 00:00:00 -05:00
16
+ date: 2011-05-02 00:00:00 -04:00
22
17
  default_executable:
23
- dependencies: []
24
-
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: rspec
21
+ requirement: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: "0"
27
+ type: :development
28
+ prerelease: false
29
+ version_requirements: *id001
30
+ - !ruby/object:Gem::Dependency
31
+ name: jeweler
32
+ requirement: &id002 !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: "0"
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: *id002
41
+ - !ruby/object:Gem::Dependency
42
+ name: sdoc-helpers
43
+ requirement: &id003 !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: *id003
52
+ - !ruby/object:Gem::Dependency
53
+ name: rdiscount
54
+ requirement: &id004 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: *id004
25
63
  description: A fake filesystem. Use it in your tests.
26
64
  email: chris@ozmm.org
27
65
  executables: []
@@ -33,8 +71,10 @@ extra_rdoc_files:
33
71
  - README.markdown
34
72
  files:
35
73
  - .autotest
36
- - .gitignore
74
+ - .rspec
37
75
  - CONTRIBUTORS
76
+ - Gemfile
77
+ - Gemfile.lock
38
78
  - LICENSE
39
79
  - README.markdown
40
80
  - Rakefile
@@ -55,6 +95,7 @@ files:
55
95
  - spec/fakefs/spec_helpers_spec.rb
56
96
  - spec/spec.opts
57
97
  - spec/spec_helper.rb
98
+ - test/fake/file/join_test.rb
58
99
  - test/fake/file/lstat_test.rb
59
100
  - test/fake/file/stat_test.rb
60
101
  - test/fake/file/sysseek_test.rb
@@ -71,8 +112,8 @@ homepage: http://github.com/defunkt/fakefs
71
112
  licenses: []
72
113
 
73
114
  post_install_message:
74
- rdoc_options:
75
- - --charset=UTF-8
115
+ rdoc_options: []
116
+
76
117
  require_paths:
77
118
  - lib
78
119
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -80,37 +121,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
80
121
  requirements:
81
122
  - - ">="
82
123
  - !ruby/object:Gem::Version
83
- hash: 3
84
- segments:
85
- - 0
86
124
  version: "0"
87
125
  required_rubygems_version: !ruby/object:Gem::Requirement
88
126
  none: false
89
127
  requirements:
90
128
  - - ">="
91
129
  - !ruby/object:Gem::Version
92
- hash: 3
93
- segments:
94
- - 0
95
130
  version: "0"
96
131
  requirements: []
97
132
 
98
133
  rubyforge_project:
99
- rubygems_version: 1.3.7
134
+ rubygems_version: 1.6.2
100
135
  signing_key:
101
136
  specification_version: 3
102
137
  summary: A fake filesystem. Use it in your tests.
103
- test_files:
104
- - spec/fakefs/spec_helpers_spec.rb
105
- - spec/spec_helper.rb
106
- - test/fake/file/lstat_test.rb
107
- - test/fake/file/stat_test.rb
108
- - test/fake/file/sysseek_test.rb
109
- - test/fake/file/syswrite_test.rb
110
- - test/fake/file_test.rb
111
- - test/fake/symlink_test.rb
112
- - test/fakefs_test.rb
113
- - test/file/stat_test.rb
114
- - test/safe_test.rb
115
- - test/test_helper.rb
116
- - test/verify.rb
138
+ test_files: []
139
+
data/.gitignore DELETED
@@ -1,3 +0,0 @@
1
- *.sw?
2
- pkg
3
-