Skip to content
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

FactoryBot incompatibility - consider renaming code on main object #58

Open
mculp opened this issue Jun 18, 2024 · 0 comments
Open

FactoryBot incompatibility - consider renaming code on main object #58

mculp opened this issue Jun 18, 2024 · 0 comments

Comments

@mculp
Copy link

mculp commented Jun 18, 2024

I’m running into an incompatibility issue with irbtools because of the way FactoryBot uses method_missing.

When you define a factory with an attribute code, it tries to call the code defined on the main object by irbtools.

I realize that’s not exactly the fault of irbtools, but it seems like in order to maintain compatibility with application code, that any method defined on the main object should have a pretty unique name.

None of the methods defined would be 100% compatible in all use cases, but I guess the point I’m trying to make is that code is a very, very common attribute name. Similar to defining a top-level method called name or id.

Pry uses show-source (not exactly sure how they use a -) for a similar feature.

Something like show_code would be less likely to be incompatible.

Here’s the relevant part of the stacktrace:

~/.gem/ruby/3.2.2/gems/irbtools-4.0.9/lib/irbtools/libraries.rb:59:in `code': wrong number of arguments (given 0, expected 1..2) (ArgumentError)
        from ~/app/lib/factories/address_factory.rb:11:in `block (2 levels) in <main>'
        from ~/.gem/ruby/3.2.2/gems/factory_bot-6.2.1/lib/factory_bot/syntax/default.rb:18:in `instance_eval'

With a standard defined factory:

FactoryBot.define do
  factory :address do
    code { "123" }
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant