| CARVIEW |
defunkt / fakefs
- Source
- Commits
- Network (30)
- Issues (10)
- Graphs
-
Branch:
master
click here to add a description
click here to add a homepage
-
While working on #6 I discovered that File.expand_path is not faked by FakeFS. This causes problems when using paths that rely on the current working directory:
irb(main):001:0> require 'fakefs' => true irb(main):002:0> Dir.glob '/*' => [] irb(main):003:0> Dir.pwd => "" irb(main):004:0> File.expand_path 'test.txt' => "/Users/narnach/Projects/WesOldenbeuving/fakefs/test.txt" irb(main):005:0> Dir.chdir '/' => nil irb(main):006:0> File.expand_path 'test.txt' => "/Users/narnach/Projects/WesOldenbeuving/fakefs/test.txt" irb(main):007:0>I'm not very familiar with the internals of FakeFS::FileSystem, so it will take me a while to figure out how to make this work. I'll look into this when I have the time for it, but if someone sees an obvious way to implement it, please do :-)
Comments
Please log in to comment. -
1 comment Created 3 months ago by jyurekTempfile fails with FakeFS installed: Directory not foundbugxAttempting to create a Tempfile when I have the FS faked gives me an error, because Tempfile is trying to make the lockfile in the current directory, which hasn't been created in the fake filesystem. I'm not sure what can be done about this, except maybe to have FakeFS redefine Dir::tmpdir and automatically create it. I'm working on a patch, but wanted this documented.
Comments
Please log in to comment.There's a load order issue at work here. Requiring Tempfile after FakeFS means Tempfile's extension to Dir gets loaded onto the Fake Dir, not RealDir. Deactivating FakeFS then breaks Tempfile completely. I don't know of a way around that except to make sure FakeFS gets loaded after Tempfile. The /tmp directory itself should simply be created by a test helper or something.
-
Function 'open' is not faked.
For example
#!/usr/bin/ruby require "rubygems" require "fakefs" FileUtils.touch("fileutils") open("kernel", "a"){}This code does not create a file 'fileutils', but do create 'kernel'.
Comments
Please log in to comment. -
Please add support for File.utime, which updates the atime and mtime of a file.
I have a patch (with tests) on my topic branch:
https://github.com/ktheory/fakefs/tree/file_utime
The rdoc for the real File.utime is:
> File.utime(atime, mtime, file_name,...) => integer > Sets the access and modification times of each named file to the first two arguments. Returns the number of file names in the argument list.See https://ruby-doc.org/core/classes/File.html#M002527
Note that my FakeFS implementation ignores the atime value, since FakeFS doesn't implement atime.
Comments
Please log in to comment. -
Please add support for File.rename, which is a primitive of FileUtils.mv.
I have a patch (with tests) on my topic branch:
https://github.com/ktheory/fakefs/tree/file_rename
See File.rename's rdoc: https://ruby-doc.org/core/classes/File.html#M002537
File.rename and FileUtils.mv are similar. FileUtils.mv calls File.rename internally. FWIW, the differences are:
File.rename("my_file", "my_directory") raises Errno::EISDIR; whereas FileUtils.mv("my_file", "my_directory") moves my_file to my_directory/my_file.
File.rename takes only a single path as the source. FileUtils.mv can take an array of source paths and move then to a destination directory.
File.rename("/mnt/disk1/file", "/mnt/disk2/file") raises an Errno::EXDEV. FileUtils.mv rescues Errno::EXDEV, copies the source to the dest, and removes source. (This is not implemented in FakeFS, since there's no notion of partitions AFAIK.)
Comments
Please log in to comment. -
Recursive Globbing Doesn't Behave like Standard Lib Dir
0 comments Created about 1 month ago by logicaltextThe recursive globbing behavior for patterns ending in wildcards (introduced at 1c6825fb9b4d5c8c73fee01a8fbd328cea2b78f) differs from the standard library
Dirbehavior by only returning files rather than files and directories. For example, given:File.open('/one/two/three/four.rb', 'w') File.open('/one/five.rb', 'w')FakeFSdoes this:Dir['/one/**/*'] #=> ['/one/five.rb', '/one/two/three/four.rb'] Dir['/one/**'] #=> ['/one/five.rb', '/one/two/three/four.rb']Whereas the standard lib
Dirdoes this:Dir['/one/**/*'] #=> ['/one/five.rb', '/one/two', '/one/two/three', '/one/two/three/four.rb'] Dir['/one/**'] #=> ['/one/five.rb', '/one/two']This commit on this branch aims to help
FakeFSmore accurately mimic the standardDirclass.Comments
Please log in to comment. -
File.join should squash duplicate slashes.
0 comments Created about 1 month ago by ktheoryThe current fake implementation of File.join is incorrect for arguments like
File.join("a/", "/b") # => "a///b" RealFile.join("a/", "/b") # => "a/bI have a patch (with tests) on my topic branch:
https://github.com/ktheory/fakefs/tree/fix_file_join
My patch simply delegates FakeFS::File.join to RealFile.join. IMHO, this is correct because RealFile.join manipulates strings in memory and doesn't touch the filesystem.
I also include some tests flexing RealFile.join's slash-squashing muscles.
Comments
Please log in to comment. -
FakeFS usage with Cucumber interferes with presence of lib-based classes.
0 comments Created 13 days ago by elliotcmThis is not an issue with FakeFS directly (as far as I can tell), I'm more looking for a best-practice method of using FakeFS with Cucumber since the most logical method seems to cause problems.
Namely, using the pre/post hook method of JIT-invoking FakeFS before step execution seems to "hide" classes that reside in RAILS_ROOT/lib.
Within the hook just before the
FakeFS.activate!, the lib classes exist and are visible. Immediately after the method call, they're gone, so it doesn't seem to be a timing issue wrt the hooks (which Aslak assures me fire off well after the Rails environment is done loading).Any ideas?
Comments
Please log in to comment. -
Hi,
it would be nice to also mock Kernel#require and Kernel#load. Is it possible or are these two too complicated?
Best regards,
LarsComments
I can't think of a use case for this. Do you have one?
It may be useful, but maybe not for this library. It'd be a nice to have a mechanism for faking dependencies for libraries that manage dependencies.
I imagine something like this: https://gist.github.com/297952
The #require mock is only activated if required (= needed).The usecase i encountered yesterday is a class loading modules by configuration. I could still use Object.eval, but then I would align my codebase to my testing code. https://github.com/lgierth/pakada/blob/master/lib/pakada.rb#L43
I'll see if I can send a patch/pull request during the next days.
Best regards,
LarsPlease log in to comment.Voila: https://github.com/lgierth/fakefs/tree/topic/fake-require
You have to explicitly say that you want to fake Kernel#require, either by loading it before FakeFS.activate! or by loading it and calling FakeFS::Require.activate!.
Best regards,
Lars



