Fix issue introduced by YARD's global #log method #1734
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The YARD gem adds a global
#log
method, which becomes a problem if a Factory needs to declare alog
attribute.Ex:
This commit adds
FactoryBot::DefinitionProxy#log
to ensure that if defining alog
attribute, it'll correctly get passed to the necessary methods throughmethod_missing
, and therefore added as an attribute to the factory.I realize that this is a bit of a workaround for something that
FactoryBot
has no control over. And it feels a little off (as other gems could technically pollute the global namespace in the same way). But given the ubiquitous usage of YARD - thought this solution may be an easy fix.Let me know if you'd prefer me to reach out to the YARD team to see if they can make an adjustment on their end.
Additionally - this was a gnarly thing to track down. We've been using the Lookbook gem, and adding that gem caused our specs to fail, because the
log
attribute in on the record was always being assignednil
in the Factory. It took quite a bit of digging to find that the issue was actually YARD, and that it was their log method.We have a workaround in place - but certainly didn't want someone else to have to wrestle through figuring out what happened.
At the very least - this PR can serve as a discoverable piece of information.
Thanks for all your hard work on this amazing gem/resource! 👏