fakefs 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/fakefs.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "fakefs"
8
- s.version = "0.4.1"
8
+ s.version = "0.4.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 = "2012-11-14"
12
+ s.date = "2012-11-24"
13
13
  s.description = "A fake filesystem. Use it in your tests."
14
14
  s.email = "chris@ozmm.org"
15
15
  s.extra_rdoc_files = [
data/lib/fakefs/file.rb CHANGED
@@ -238,10 +238,14 @@ module FakeFS
238
238
 
239
239
  def self.chown(owner_int, group_int, filename)
240
240
  file = FileSystem.find(filename)
241
- owner_int.is_a?(Fixnum) or raise TypeError, "can't convert String into Integer"
242
- group_int.is_a?(Fixnum) or raise TypeError, "can't convert String into Integer"
243
- file.uid = owner_int
244
- file.gid = group_int
241
+ if owner_int && owner_int != -1
242
+ owner_int.is_a?(Fixnum) or raise TypeError, "can't convert String into Integer"
243
+ file.uid = owner_int
244
+ end
245
+ if group_int && group_int != -1
246
+ group_int.is_a?(Fixnum) or raise TypeError, "can't convert String into Integer"
247
+ file.gid = group_int
248
+ end
245
249
  end
246
250
 
247
251
  def self.umask
@@ -403,10 +407,14 @@ module FakeFS
403
407
  end
404
408
 
405
409
  def chown(owner_int, group_int)
406
- owner_int.is_a?(Fixnum) or raise TypeError, "can't convert String into Integer"
407
- group_int.is_a?(Fixnum) or raise TypeError, "can't convert String into Integer"
408
- @file.uid = owner_int
409
- @file.gid = group_int
410
+ if owner_int && owner_int != -1
411
+ owner_int.is_a?(Fixnum) or raise TypeError, "can't convert String into Integer"
412
+ @file.uid = owner_int
413
+ end
414
+ if group_int && group_int != -1
415
+ group_int.is_a?(Fixnum) or raise TypeError, "can't convert String into Integer"
416
+ @file.gid = group_int
417
+ end
410
418
  end
411
419
 
412
420
  if RUBY_VERSION >= "1.9"
@@ -115,6 +115,7 @@ module FakeFS
115
115
  Array(src).each do |path|
116
116
  if target = FileSystem.find(path)
117
117
  dest_path = File.directory?(dest) ? File.join(dest, File.basename(path)) : dest
118
+ FileSystem.delete(dest_path)
118
119
  FileSystem.add(dest_path, target.entry.clone)
119
120
  FileSystem.delete(path)
120
121
  else
@@ -127,8 +128,16 @@ module FakeFS
127
128
  list = Array(list)
128
129
  list.each do |f|
129
130
  if File.exists?(f)
130
- uid = (user.to_s.match(/[0-9]+/) ? user.to_i : Etc.getpwnam(user).uid)
131
- gid = (group.to_s.match(/[0-9]+/) ? group.to_i : Etc.getgrnam(group).gid)
131
+ uid = if user
132
+ user.to_s.match(/[0-9]+/) ? user.to_i : Etc.getpwnam(user).uid
133
+ else
134
+ nil
135
+ end
136
+ gid = if group
137
+ group.to_s.match(/[0-9]+/) ? group.to_i : Etc.getgrnam(group).gid
138
+ else
139
+ nil
140
+ end
132
141
  File.chown(uid, gid, f)
133
142
  else
134
143
  raise Errno::ENOENT, f
@@ -1,6 +1,6 @@
1
1
  module FakeFS
2
2
  module Version
3
- VERSION = "0.4.1"
3
+ VERSION = "0.4.2"
4
4
 
5
5
  def self.to_s
6
6
  VERSION
data/test/fakefs_test.rb CHANGED
@@ -752,6 +752,17 @@ class FakeFSTest < Test::Unit::TestCase
752
752
  assert_raises(Errno::ENOENT) do
753
753
  FileUtils.chown(username, groupname, [good, bad])
754
754
  end
755
+
756
+ # FileUtils.chown with nil user and nil group should not change anything
757
+ FileUtils.chown(username, groupname, good)
758
+ assert_equal File.stat(good).uid, Process.uid
759
+ assert_equal File.stat(good).gid, Process.gid
760
+ assert_equal [good], FileUtils.chown(nil, nil, [good])
761
+ assert_equal File.stat(good).uid, Process.uid
762
+ assert_equal File.stat(good).gid, Process.gid
763
+ assert_raises(Errno::ENOENT) do
764
+ FileUtils.chown(nil, nil, [good, bad])
765
+ end
755
766
  end
756
767
 
757
768
  def test_can_chown_R_files
@@ -1093,6 +1104,13 @@ class FakeFSTest < Test::Unit::TestCase
1093
1104
  assert_equal 'bar', File.open('baz') { |f| f.read }
1094
1105
  end
1095
1106
 
1107
+ def test_mv_overwrites_existing_files
1108
+ File.open('foo', 'w') { |f| f.write 'bar' }
1109
+ File.open('baz', 'w') { |f| f.write 'qux' }
1110
+ FileUtils.mv 'foo', 'baz'
1111
+ assert_equal 'bar', File.read('baz')
1112
+ end
1113
+
1096
1114
  def test_mv_works_with_options
1097
1115
  File.open('foo', 'w') {|f| f.write 'bar'}
1098
1116
  FileUtils.mv 'foo', 'baz', :force => true
@@ -2043,6 +2061,46 @@ class FakeFSTest < Test::Unit::TestCase
2043
2061
  assert_equal File.stat("bar").gid, 1338
2044
2062
  end
2045
2063
 
2064
+ def test_file_chown_of_file_nil_user_group
2065
+ FileUtils.touch "foo"
2066
+ File.chown 1337, 1338, "foo"
2067
+ File.chown nil, nil, "foo"
2068
+ assert_equal File.stat("foo").uid, 1337
2069
+ assert_equal File.stat("foo").gid, 1338
2070
+ end
2071
+
2072
+ def test_file_chown_of_file_negative_user_group
2073
+ FileUtils.touch "foo"
2074
+ File.chown 1337, 1338, "foo"
2075
+ File.chown -1, -1, "foo"
2076
+ assert_equal File.stat("foo").uid, 1337
2077
+ assert_equal File.stat("foo").gid, 1338
2078
+ end
2079
+
2080
+ def test_file_instance_chown_nil_user_group
2081
+ FileUtils.touch('foo')
2082
+ File.chown(1337, 1338, 'foo')
2083
+ assert_equal File.stat('foo').uid, 1337
2084
+ assert_equal File.stat('foo').gid, 1338
2085
+ file = File.open('foo')
2086
+ file.chown nil, nil
2087
+ assert_equal File.stat('foo').uid, 1337
2088
+ assert_equal File.stat('foo').gid, 1338
2089
+ end
2090
+
2091
+ def test_file_instance_chown_negative_user_group
2092
+ FileUtils.touch('foo')
2093
+ File.chown(1337, 1338, 'foo')
2094
+ assert_equal File.stat('foo').uid, 1337
2095
+ assert_equal File.stat('foo').gid, 1338
2096
+ file = File.new('foo')
2097
+ file.chown -1, -1
2098
+ file.close
2099
+ assert_equal File.stat('foo').uid, 1337
2100
+ assert_equal File.stat('foo').gid, 1338
2101
+ end
2102
+
2103
+
2046
2104
  def test_file_umask
2047
2105
  assert_equal File.umask, RealFile.umask
2048
2106
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fakefs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2012-11-14 00:00:00.000000000 Z
15
+ date: 2012-11-24 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rspec
@@ -123,7 +123,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
123
123
  version: '0'
124
124
  segments:
125
125
  - 0
126
- hash: 4221533071311333318
126
+ hash: 4092255673165272959
127
127
  required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  none: false
129
129
  requirements: