Pathname#write does not work
Pathname is implemented in C and does not reflect MemFS filesystem.
Hi @mikz, thanks for your feedback. Could you provide a code example that could help reproduce your issue? I know it's a large issue but having a starting point would be cool :)
require 'memfs'
MemFs.activate!
path = Pathname('folder/file')
MemFs.touch(path)
File.exist?(path.to_s) or raise 'fail'
path.write('test')
also there is another bug with Pathname, and it is:
require 'memfs'
path = Pathname('folder/file')
File.exist?(path.to_s) == File.exist?(path) or raise 'failed'
MemFs.activate!
File.exist?(path.to_s) == File.exist?(path) or raise 'failed'
It raises ArgumentError: wrong number of arguments (2 for 0)
from /Users/mikz/.rvm/gems/ruby-2.1.2/gems/memfs-0.4.1/lib/memfs/fake/directory.rb:23:in `split'
because it tries to call split('/', 2) on Pathname which does not accept params and splits to dirname and basename.
Thank you ! I'll try to work on this issue in the coming days ;)
Ok I started to look into it and it will probably take time since I'll have to literally replace Pathname, or at least an important part of it.
I'll focus on the completion of the File class for now and come back to afterward. I already have the switching process in a branch though ;)
Hey @simonc, I am curious about the status of this issue, as there are other Pathname functions that don't work, for example:
require 'pathname'
Dir.mkdir("/directory")
File.directory?("/directory")
# => true
Pathname.new("/directory").directory?
# => false
I'd be happy to help with a PR for this, somehow, although I'm afraid I'm not sure how one would go about implementing C classes in MemFs.
It could be that we just need to tack on a .map(&:to_s) somewhere like in @craigw's PR, maybe in File::Stat#directory?. I hope?!
Hey @awolfson.
Sadly I ended up not having enough time to dig the subject. The only thing I can think of, regarding Pathname is to rewrite the entire class the same way File and Dir are rewritten in MemFs. I guess some parts of it can be delegated to the original class but every method interacting with the file system would have to be rewritten.
Regarding the .map(&:to_s) technique it may work for certain situations but not for others.
Anyway, I pushed what I had started on the pathname-support branch if anyone is interested in taking a stab at it 😁