-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PATCH] File#open with write flag does not clear existing files. #6
Comments
+1 to this. |
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: |
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. |
That last bit is also not captured, iirc. Expected behavior:
|
Looks like I'll have to add more tests to check the edge cases. |
Cool. I've got some tests here that are failing that I'll push up. |
Great. I'll keep an eye out for them. Thanks! |
Hm, okay, so these are an okay start. A bunch of tests will fail if you actually implemented the code for I'd hack this out more, but I broke some stuff w.r.t. |
(Oh, and if those values do have to change, pay attention to line 94 in fileutils.rb. Ugh, I hate that I wrote that.) |
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 :) |
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 :) |
Files modes are respected properly in this branch: |
Those changes look good! |
Merged, thanks Scott! |
In regular Ruby, File#open with the 'w' write flag clears the file. FakeFS did not yet do this.
The fix with a test can be found on my topic branch: http://github.com/Narnach/fakefs/tree/file_open_with_write
The text was updated successfully, but these errors were encountered: