Comments (14)
+1 to this.
from fakefs.
The functionality is absolutely needed. I'm not too terribly inclined with this patch.
Checking the mode and clearing the file out if it exists belongs in File#initialize.
You can see this behavior with the normal File class:
irb(main):001:0> Dir['']
=> ["lib", "LICENSE", "pkg", "Rakefile", "README.markdown", "subdir", "test", "tmp"]
irb(main):002:0> File.new('foo', 'w')
=> #File:foo
irb(main):003:0> Dir['']
=> ["foo", "lib", "LICENSE", "pkg", "Rakefile", "README.markdown", "subdir", "test", "tmp"]
from fakefs.
Obviously, what is also not captured in your tests is that the file should be created if it does not exist but the directory above it does.
from fakefs.
That last bit is also not captured, iirc. Expected behavior:
irb(main):002:0> File.new('bar/foo', 'w')
Errno::ENOENT: No such file or directory - bar/foo
from (irb):2:in `initialize'
from (irb):2:in `new'
from (irb):2
from :0
from fakefs.
Looks like I'll have to add more tests to check the edge cases.
Clearing the file in File#initialize does make more sense.
I'll look into it today and see if I can improve it on my topic branch.
from fakefs.
Cool. I've got some tests here that are failing that I'll push up.
from fakefs.
Great. I'll keep an eye out for them. Thanks!
from fakefs.
Hm, okay, so these are an okay start.
A bunch of tests will fail if you actually implemented the code for test_File_new_errors_if_directory_above_it_does_not_exist
because many tests rely on being able to write directly to /path/to
without creating it first.
I'd hack this out more, but I broke some stuff w.r.t. File.open
with my current implementation and it is way, way too late for hacking. (I think the initial values of FileSystem.dir_levels
and FileSystem.fs
need to change but that's just a gut feeling and I've thought that and been wrong before.)
from fakefs.
(Oh, and if those values do have to change, pay attention to line 94 in fileutils.rb. Ugh, I hate that I wrote that.)
from fakefs.
Thanks for the warning that tests will fail due to the /path/to thing. IRB confirms you get an error, so fakefs should act the same. There's fixing to be done :)
from fakefs.
Because File.expand_path is not yet faked, there are 9 tests that break because file path expansion (for directory existence checking) does not operate within the faked FS but still relies on the current working directory outside of FakeFS.
The upside is that the tests you gisted now pass :)
I've pushed the changes (with those 9 failing tests) to my topic branch.
Faking File.expand_path will likely require mucking around in the FileSystem internals as you predicted :)
from fakefs.
Files modes are respected properly in this branch:
http://github.com/smtlaissezfaire/fakefs/tree/file_modes
from fakefs.
Those changes look good!
from fakefs.
Merged, thanks Scott!
from fakefs.
Related Issues (20)
- make a 1.0.0 release? HOT 1
- please add ruby2.7 support HOT 3
- tests for the verbose option in cp and mv fail randomly under ruby 2.7 HOT 1
- Regression: FakeFS::File became non-IO HOT 2
- inconsitencies with some methods when passed an empty path HOT 1
- Dir.open() { |foo| ... } differs from standard Dir.open HOT 2
- Dir.glob fails if chdir to a directory that contains plus signs '+' HOT 4
- `File.readlines(path, chomp: true)` isn't supported (standard) HOT 1
- How do I simulate an ELOOP? HOT 4
- IO not mocked (specifically, IO.read not mocked) HOT 1
- How to use with byebug? HOT 2
- Mocking isolated directories HOT 1
- Pathname#glob HOT 3
- Using requests with fakefs HOT 2
- git head testsuite fails with ruby3.2dev for some unavailable method HOT 3
- File system and objects are not auto loaded on Ruby 3.0.4 HOT 5
- Can't use IRB when FakeFS is activated HOT 1
- Pathname's #realdirpath and #realpath do not work (as intended) HOT 1
- Ruby3 Kernel.open() handling of kwargs fails after fakefs deactivation HOT 3
- Calling FileUtils.touch on a symlink with a missing target throws an exception instead of creating the file HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fakefs.