Skip to content
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

File System Mocking library #102

Open
HCLarsen opened this issue Apr 10, 2019 · 4 comments
Open

File System Mocking library #102

HCLarsen opened this issue Apr 10, 2019 · 4 comments

Comments

@HCLarsen
Copy link

Something like webmock.cr, but for the local file system. It would be very useful for testing. Ruby has something called FakeFS, so it should be entirely possible.

@bew
Copy link

bew commented May 6, 2019

There is another gem called memfs: https://github.com/simonc/memfs

Both are different from how webmock work though, because with webmock you say what you expect, and then you do a web request, and if it doesn't match the expectations it fails.
But the fs gems allows you to do some fs manipulations (in memory) and then you have to check the result is what you expected.

Are you looking for an in memory fs (like fakefs/memfs) or a expect-then-do style of spec system for filesystems?


I'd say both would be great, but just an in memory fs is enough for a start!

@HCLarsen
Copy link
Author

HCLarsen commented May 7, 2019

For my current use case, an expect-then-do style of system would work. This program that I'm writing will use a config file, so being able to "read" that file and getting a known response regardless of what's on my hard drive, that's basically what I need for now.

I'm sure in the long run, someone will need an entire in memory fs, but for now, the other would work for me.

@bew
Copy link

bew commented May 7, 2019

https://forum.crystal-lang.org/t/poc-pluggable-crystal-system-backends/735
I've made a successful POC at changing the implementation of the used system functions, in this case I can do an in memory environment on demand.. And still use ENV.
The same would be possible for File and Dir to create an in-memory filesystem, or intercept all FS calls (and install expectations /..).. I think it's the base building block for this kind of stuff, raise your voice if you have suggestions ;)

@HCLarsen
Copy link
Author

HCLarsen commented May 8, 2019

I don't understand your POC as I'm not familiar with OS back end stuff.

I thought that doing something like this would work the same way as webmock and timecop, where you overwrite the methods like File#read and File#write so that your calls to those methods give a controlled response, instead of actually touching the filesystem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants