fakefs 0.2.1 → 0.3.2

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/.autotest ADDED
@@ -0,0 +1,5 @@
1
+ Autotest.add_hook :initialize do |at|
2
+ at.add_mapping(%r%^test/.+_test.rb$%) do |filename, _|
3
+ filename
4
+ end
5
+ end
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/CONTRIBUTORS CHANGED
@@ -1,12 +1,30 @@
1
- * Chris Wanstrath
2
- * Jeff Hodges
3
- * Scott Taylor
4
- * Pat Nakajima
5
- * Myles Eftos
6
- * Matt Freels
7
- * Nick Quaranto
8
- * Tymon Tobolski
9
- * msassak
10
- * Rob Sanheim
11
- * Jon Yurek
12
- * David Reese
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
data/Gemfile.lock ADDED
@@ -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/README.markdown CHANGED
@@ -37,11 +37,11 @@ Don't Fake the FS Immediately
37
37
  -----------------------------
38
38
 
39
39
  require 'fakefs/safe'
40
-
40
+
41
41
  FakeFS.activate!
42
42
  # your code
43
43
  FakeFS.deactivate!
44
-
44
+
45
45
  # or
46
46
  FakeFS do
47
47
  # your code
@@ -49,10 +49,18 @@ Don't Fake the FS Immediately
49
49
 
50
50
 
51
51
  RSpec
52
- -----------------------------
53
- The above approach works with RSpec as well. In addition to this you may use the
54
- 'use_fakefs' macro to turn FakeFS on and off in a given example group. See
55
- lib/spec_helpers for more details on it's usage.
52
+ -----
53
+
54
+ The above approach works with RSpec as well. In addition you may include
55
+ FakeFS::SpecHelpers to turn FakeFS on and off in a given example group:
56
+
57
+ require 'fakefs/spec_helpers'
58
+
59
+ describe "my spec" do
60
+ include FakeFS::SpecHelpers
61
+ end
62
+
63
+ See `lib/fakefs/spec_helpers.rb` for more info.
56
64
 
57
65
 
58
66
  How is this different than MockFS?
@@ -73,6 +81,7 @@ on FakeFS' own require.
73
81
 
74
82
  Speed?
75
83
  ------
84
+
76
85
  <http://gist.github.com/156091>
77
86
 
78
87
 
@@ -88,6 +97,17 @@ Installation
88
97
  $ rip install git://github.com/defunkt/fakefs.git
89
98
 
90
99
 
100
+ Contributing
101
+ ------------
102
+
103
+ Once you've made your great commits:
104
+
105
+ 1. [Fork][0] FakeFS
106
+ 2. Create a topic branch - `git checkout -b my_branch`
107
+ 3. Push to your branch - `git push origin my_branch`
108
+ 4. Create an [Issue][1] with a link to your branch
109
+ 5. That's it!
110
+
91
111
  Meta
92
112
  ----
93
113
 
@@ -98,4 +118,6 @@ Meta
98
118
  * List: <http://groups.google.com/group/fakefs>
99
119
  * Test: <http://runcoderun.com/defunkt/fakefs>
100
120
  * Gems: <http://gemcutter.org/gems/fakefs>
101
- * Boss: Chris Wanstrath :: <http://github.com/defunkt>
121
+
122
+ [0]: http://help.github.com/forking/
123
+ [1]: http://github.com/defunkt/fakefs/issues
data/Rakefile CHANGED
@@ -1,9 +1,16 @@
1
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'test')
3
+
1
4
  desc "Run tests"
2
5
  task :test do
3
6
  Dir['test/**/*_test.rb'].each { |file| require file }
4
7
  end
5
8
 
6
- task :default => :test
9
+ task :default => [:test, :spec]
10
+
11
+ require 'rspec/core/rake_task'
12
+ desc "Run specs"
13
+ RSpec::Core::RakeTask.new
7
14
 
8
15
  begin
9
16
  require 'jeweler'
@@ -12,14 +19,14 @@ begin
12
19
  require 'fakefs/version'
13
20
 
14
21
  Jeweler::Tasks.new do |gemspec|
15
- gemspec.name = "fakefs"
16
- gemspec.summary = "A fake filesystem. Use it in your tests."
17
- gemspec.email = "chris@ozmm.org"
18
- gemspec.homepage = "http://github.com/defunkt/fakefs"
22
+ gemspec.name = "fakefs"
23
+ gemspec.summary = "A fake filesystem. Use it in your tests."
24
+ gemspec.email = "chris@ozmm.org"
25
+ gemspec.homepage = "http://github.com/defunkt/fakefs"
19
26
  gemspec.description = "A fake filesystem. Use it in your tests."
20
- gemspec.authors = ["Chris Wanstrath"]
21
- gemspec.has_rdoc = false
22
- gemspec.version = FakeFS::Version.to_s
27
+ gemspec.authors = ["Chris Wanstrath", "Scott Taylor", "Jeff Hodges", "Pat Nakajima"]
28
+ gemspec.has_rdoc = false
29
+ gemspec.version = FakeFS::Version.to_s
23
30
  end
24
31
  rescue LoadError
25
32
  puts "Jeweler not available."
@@ -45,3 +52,8 @@ task :publish => [ :gemspec, :build ] do
45
52
  system "git clean -fd"
46
53
  exec "rake pages"
47
54
  end
55
+
56
+ desc "Update contributors"
57
+ task :update_contributors do
58
+ sh "git-rank-contributors > CONTRIBUTORS"
59
+ end
data/fakefs.gemspec ADDED
@@ -0,0 +1,84 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{fakefs}
8
+ s.version = "0.3.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Chris Wanstrath", "Scott Taylor", "Jeff Hodges", "Pat Nakajima"]
12
+ s.date = %q{2011-05-02}
13
+ s.description = %q{A fake filesystem. Use it in your tests.}
14
+ s.email = %q{chris@ozmm.org}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.markdown"
18
+ ]
19
+ s.files = [
20
+ ".autotest",
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"
57
+ ]
58
+ s.homepage = %q{http://github.com/defunkt/fakefs}
59
+ s.require_paths = ["lib"]
60
+ s.rubygems_version = %q{1.6.2}
61
+ s.summary = %q{A fake filesystem. Use it in your tests.}
62
+
63
+ if s.respond_to? :specification_version then
64
+ s.specification_version = 3
65
+
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"])
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"])
76
+ end
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"])
82
+ end
83
+ end
84
+
data/lib/fakefs/base.rb CHANGED
@@ -1,30 +1,37 @@
1
- RealFile = File
2
- RealFileUtils = FileUtils
3
- RealDir = Dir
4
- RealFileUtils::Dir = RealDir
5
- RealFileUtils::File = RealFile
1
+ RealFile = File
2
+ RealFileTest = FileTest
3
+ RealFileUtils = FileUtils
4
+ RealDir = Dir
6
5
 
7
6
  module FakeFS
8
7
  def self.activate!
9
8
  Object.class_eval do
10
9
  remove_const(:Dir)
11
10
  remove_const(:File)
11
+ remove_const(:FileTest)
12
12
  remove_const(:FileUtils)
13
- const_set(:Dir, FakeFS::Dir)
14
- const_set(:File, FakeFS::File)
13
+
14
+ const_set(:Dir, FakeFS::Dir)
15
+ const_set(:File, FakeFS::File)
15
16
  const_set(:FileUtils, FakeFS::FileUtils)
17
+ const_set(:FileTest, FakeFS::FileTest)
16
18
  end
19
+ true
17
20
  end
18
21
 
19
22
  def self.deactivate!
20
23
  Object.class_eval do
21
24
  remove_const(:Dir)
22
25
  remove_const(:File)
26
+ remove_const(:FileTest)
23
27
  remove_const(:FileUtils)
24
- const_set(:Dir, RealDir)
25
- const_set(:File, RealFile)
28
+
29
+ const_set(:Dir, RealDir)
30
+ const_set(:File, RealFile)
31
+ const_set(:FileTest, RealFileTest)
26
32
  const_set(:FileUtils, RealFileUtils)
27
33
  end
34
+ true
28
35
  end
29
36
  end
30
37
 
data/lib/fakefs/dir.rb CHANGED
@@ -78,14 +78,16 @@ 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)
86
87
  parent = string.split('/')
87
88
  parent.pop
88
89
  raise Errno::ENOENT, "No such file or directory - #{string}" unless parent.join == "" || FileSystem.find(parent.join('/'))
90
+ raise Errno::EEXIST, "File exists - #{string}" if File.exists?(string)
89
91
  FileUtils.mkdir_p(string)
90
92
  end
91
93
 
@@ -105,6 +107,52 @@ module FakeFS
105
107
  FileSystem.current_dir.to_s
106
108
  end
107
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
+
108
156
  class << self
109
157
  alias_method :getwd, :pwd
110
158
  alias_method :rmdir, :delete
@@ -1,10 +1,13 @@
1
1
  module FakeFS
2
2
  class FakeDir < Hash
3
3
  attr_accessor :name, :parent
4
+ attr_reader :ctime, :mtime
4
5
 
5
6
  def initialize(name = nil, parent = nil)
6
- @name = name
7
+ @name = name
7
8
  @parent = parent
9
+ @ctime = Time.now
10
+ @mtime = @ctime
8
11
  end
9
12
 
10
13
  def entry
@@ -1,6 +1,7 @@
1
1
  module FakeFS
2
2
  class FakeFile
3
3
  attr_accessor :name, :parent, :content, :mtime
4
+ attr_reader :ctime
4
5
 
5
6
  class Inode
6
7
  def initialize(file_owner)
@@ -31,7 +32,8 @@ module FakeFS
31
32
  @name = name
32
33
  @parent = parent
33
34
  @inode = Inode.new(self)
34
- @mtime = Time.now
35
+ @ctime = Time.now
36
+ @mtime = @ctime
35
37
  end
36
38
 
37
39
  attr_accessor :inode
@@ -24,7 +24,7 @@ module FakeFS
24
24
  end
25
25
 
26
26
  private
27
-
27
+
28
28
  def method_missing(*args, &block)
29
29
  entry.send(*args, &block)
30
30
  end