thoughtbot / thoughtbot/factory_bot

singleton_method_added is being forwarded by FactoryBot::Evaluator

Open
#1,472 1 comment 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.