GithubHelp home page GithubHelp logo

Comments (14)

qrush avatar qrush commented on July 20, 2024

+1 to this.

from fakefs.

jmhodges avatar jmhodges commented on July 20, 2024

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.

jmhodges avatar jmhodges commented on July 20, 2024

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.

jmhodges avatar jmhodges commented on July 20, 2024

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.

Narnach avatar Narnach commented on July 20, 2024

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.

jmhodges avatar jmhodges commented on July 20, 2024

Cool. I've got some tests here that are failing that I'll push up.

from fakefs.

Narnach avatar Narnach commented on July 20, 2024

Great. I'll keep an eye out for them. Thanks!

from fakefs.

jmhodges avatar jmhodges commented on July 20, 2024

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.

jmhodges avatar jmhodges commented on July 20, 2024

(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.

Narnach avatar Narnach commented on July 20, 2024

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.

Narnach avatar Narnach commented on July 20, 2024

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.

smtlaissezfaire avatar smtlaissezfaire commented on July 20, 2024

Files modes are respected properly in this branch:

http://github.com/smtlaissezfaire/fakefs/tree/file_modes

from fakefs.

Narnach avatar Narnach commented on July 20, 2024

Those changes look good!

from fakefs.

defunkt avatar defunkt commented on July 20, 2024

Merged, thanks Scott!

from fakefs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.