fakefs / fakefs

A fake filesystem. Use it in your tests.
MIT License
1.05k stars 188 forks source link

Fix irregularity with File.rename #452

Closed ronanduddy closed 3 years ago

ronanduddy commented 3 years ago

When passing the same path for the source and dest e.g. FakeFS::File.rename('/file', '/file'), the file will get deleted by FileSystem.delete(source) then a 0 will get returned.

This is erroneous behaviour, the file '/file' should still exist and the 0 returned. See the example below comparing FakeFS::File.rename with File.rename:

irb(main):001:0> require 'fakefs'
=> true
irb(main):002:0> app_path = '/usr/src/app'
=> "/usr/src/app"
irb(main):003:0> FakeFS.activate!
=> true
irb(main):004:0> FakeFS::FileSystem.clone app_path
=> ["/usr/src/app/test"]
irb(main):005:0> file_path = "#{app_path}/test"
=> "/usr/src/app/test"
irb(main):006:0> FakeFS::File.exist? file_path
=> true
irb(main):007:0> FakeFS::File.rename file_path, file_path
=> 0
irb(main):008:0> FakeFS::File.exist? file_path
=> false
irb(main):009:0> FakeFS.deactivate!
=> true
irb(main):010:0> FakeFS.clear!
=> nil
irb(main):011:0> File.exist? file_path
=> true
irb(main):012:0> File.rename file_path, file_path
=> 0
irb(main):013:0> File.exist? file_path
=> true
grosser commented 3 years ago

thx! v1.2.3