-
Notifications
You must be signed in to change notification settings - Fork 47
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
Handle gracefully fixtures that only exist for tests in TestHelper.unload_fixture
#72
Handle gracefully fixtures that only exist for tests in TestHelper.unload_fixture
#72
Conversation
lib/frozen_record/test_helper.rb
Outdated
begin | ||
model_class.load_records(force: true) | ||
rescue | ||
nil |
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.
Rather than swallow the error it should be re-raised.
Passing a wrong path shouldn't silently fail.
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.
That's the point: there isn't a "wrong" path.
Look, the fixture and frozen record only exists for the test, and can hence not be forcefully loaded on 'unload'
"Nothing to go back to" in that case
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.
Ah I see. Sorry I misunderstood your PR description.
Then this should be detected as part of load and registered somewhere so unload
knows not to call load_records
.
Rescueing an exception like this could hide a legitimate issue.
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.
k, something like:
during load_fixture
if the model exists under the alternate path but not under the original/configured path => store it a bit differently (or just not putting it into the @cache)?
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.
if the model exists under the alternate path but not under the original/configured path => store it a bit differently (or just not putting it into the @cache)?
Yes. e.g. store false
or some other token value you can check in unload
.
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.
voted for putting nil
into the cache and only force-loading the original backend file when the cache has a non nil value. I think that expresses the idea quite well - there isn't a basepath to go back to, so it's nil. okay?
324e3f9
to
fcf1814
Compare
fcf1814
to
8e15b87
Compare
Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
TIL 3.2 got rid of |
Description
When using the test helper with fixtures that only exist under their name in tests, then
unload_fixture
was bailing as it tried to force load those model classes from their "original" path.What approach
Just rescue from any StandardError (load records throws Errno::ENOENT) on
load_records
in theunload_fixture
implementation.What else was considered
Leaving all test frozenrecords with names that also exist in the normal path and splitting them by different path names.
That was a bit unwieldy to have so many directories names like tests which all contained the same file name.
Questions
Errno::ENOENT
specifically?