thoughtbot / thoughtbot/factory_bot
singleton_method_added is being forwarded by FactoryBot::Evaluator
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 8.2k
- Forks
- 2.6k
- PR merge metrics
- No merged PRs in 30d
Description
Due to https://github.com/thoughtbot/factory_bot/blob/b223c275191985f776ff294825660fce98b3c0cc/lib/factory_bot/evaluator.rb#L10
methods like singleton_method_added (coming from BasicObject) are undefined.
And then https://github.com/thoughtbot/factory_bot/blob/b223c275191985f776ff294825660fce98b3c0cc/lib/factory_bot/evaluator.rb#L81 will actually call singleton_method_added, and since the method is not there, will end up in method_missing:
https://github.com/thoughtbot/factory_bot/blob/b223c275191985f776ff294825660fce98b3c0cc/lib/factory_bot/evaluator.rb#L47-L51
which will forward it to SyntaxRunner.new.
singleton_method_added does nothing by default so that's probably why this was never noticed.
It's not necessarily a problem, but it also seems surprising.
Maybe FactoryBot::Evaluator should inherit from BasicObject, rather than undefine many methods, some of them which might have quite subtle effects like this?
I noticed this while investigating https://github.com/oracle/truffleruby/issues/2258.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read lib/factory_bot/evaluator.rb at the referenced lines 10, 47-51, and 81 to trace how singleton_method_added reaches method_missing and SyntaxRunner. Compare the current method-undefinition approach with the proposed BasicObject inheritance, then verify the chosen behavior with regression coverage and the existing test suite.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100