Closed thsur closed 7 years ago
Hi @thsur and thanks a lot for this cool idea!
I think the halt
mechanism could be implemented calling deactivate
and activate
instead of copying the code, that would prevent any error if the activation code changes in the future ☺️
It would also require tests before being merged :wink:
Hi @simonc,
I think the halt mechanism could be implemented calling deactivate and activate instead of copying the code
yep, you're right - I didn't focus enough on my problem, which was not so much switching between file systems, but to keep the state of the faked one.
So I've rewritten the code and also wrote a spec for .halt
- since I've no experience with RSpec, you might want to review the latter...
Hi @thsur. I think we have several options here:
clear: true
argument to activate!
that way we can disable MemFs and keep the stateFileSystem
to dump/restore the current stateI would vote for the :clear
option, it's the simplest one.
Hi @simonc,
sorry, took me a while to come back to the issue. I wanted to introduce some sort of parameter for activate!
myself, but didn't want to clutter your method signatures. But you're right, it's the easiest one, so it's in.
Hey @thsur. That's pretty cool. Two small things though:
before
blockensure
that tests that halt
re-actives MemFs in case an exception happensAfter this, it's a GO! :shipit:
Hey @simonc, thanks for your comments!
What is the purpose of this before block?
Hm. Good question. Maybe it's purpose was to illustrate my lack of talent when coding by copy & paste...
I think we should have a spec regarding the ensure that tests that halt re-actives MemFs in case an exception happens
Absolutely. It's in now.
Merged! 🎉 Thanks a lot! ☺️
Thank you! :beers:
Somewhat related to #23 & #7 - I needed to read from the original file system, and this is what I came up with to switch between both file systems.
Background story: I'm testing a command line app lazy-loading subcommands via some loader class that
require
s the appropriate files. With the switch implemented, mocking the loader was easy as saying:So this is might be a valid use case, or it might be not, or it might be a stupid implementation, but I thought to give it a try.