-
Notifications
You must be signed in to change notification settings - Fork 27
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
NoMethodError: undefined method `write' for MemFs::File:Class #20
Conversation
Hi @rmm5t ! :) Thank you for your interest in the project. It's definitely a thing that should be addressed. And a basic implementation that covers some options is still better than none. If you want to give a shot at a PR I would gladly help you. As a matter of documentation, I'll indicate here that the implementation should take place in the |
|
||
context 'when +offset+ is provided' do | ||
it 'starts writing from the offset' do | ||
pending("Offsets not yet implemented, because Content#write always appends.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [87/80]
@simonc I gave this a quick shot and converted this issue into a pull-request. Please review.
|
Heh. I tried to match the project's coding conventions even though the warnings from houndci better match my own preferred conventions better. Oh well. I tried. |
@rmm5t Thanks :) I will review this and we'll go forward. Don't worry about HoundCI, I just haven't found the time to set it up according to the project. But I think I used rubocop for this one :) |
Well it seems I forgot to bind a specific version of Rubocop to the project so now it's all warnings and all. I'll have some cleanup to do in the codebase :) |
@rmm5t I think the method args handling could be lighter. By explicitly naming the arguments like the ones of Would you be ok with trying with |
Oh and I try to keep the methods organized by alphabetical order. There are so many of them, it's easier to find your way :D |
options = { mode: File::WRONLY, encoding: nil, open_args: nil }.merge(open_args) | ||
|
||
if offset > 0 | ||
fail NotImplementedError, "MemFs::IO.write with offset not yet supported." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [84/80]
It still doesn't support offsets, but it supports the most basic case of writing a plain string to a file. e.g.: File.write "myfile.txt", "my contents"
Closing and re-opening PR to trigger new Travis build. It looks like that last one borked out for bundler/rubygems reasons. |
Hrm. I don't know why the build is now failing during the |
That's weird. I just pushed to master and I have the same issue, I'll look into it. |
I'm trying to fix this Travis issue. I created a branch reverting all changes since the last successful build. If it doesn't work I guess I'll try to contact them or simply change CI… I'll keep you posted. |
end | ||
|
||
file = open(path, *open_args) | ||
file.seek(offset || 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not completely comfortable with this line since passing false
should result in no implicit conversion from boolean (TypeError)
an here it would end up being zero.
By the way I'm in touch with Travis' support, it's a problem with the new platform they deployed. I have a workaround for know. |
@simonc I added implicit type conversion support to IO.write to cover your previous concerns |
Merged! Thank you! 😄 |
I know that the lack of a
IO.write
implementation is a known issue in the README still, but the more basic usage of it, typically written asFile.write(filename, string)
, is something that compliments the typicalFile.read(filename)
quite nicely.In my test suite, for now, I'm just manually adding a
MemFs::File.write
method to cover the usage I was using in my project.I just wanted to open up a discussion about potentially implementing this in memfs. I understand that this is not a complete implementation. I also understand the complexities involved with fully implementing
offset
andopen_args
support.Right now, I'm at a cross-roads, because I ran into some semi-serious troubles with FakeFS and open-uri. I decided to try MemFs. It seems to work great so far, but I ran into this
File.write
hurdle. I'm now considering dropping a fake filesystem from my test suite altogether, but if I decide to keep MemFs around, I'd be willing to look deeper into a full PR here.If this isn't worth doing, feel free to close this issue, but I wanted document this, open a discussion, and share (in case any one else might benefit from this).