thoughtbot / factory_bot

A library for setting up Ruby objects as test data.
https://thoughtbot.com
MIT License
7.91k stars 2.6k forks source link

Rubocop (`Rails/SaveBang`) linters `create(my_dynamic_string.to_sym)` when using with dynamic first param #1620

Open MarionCrp opened 8 months ago

MarionCrp commented 8 months ago

Description

I apologies first if I'm not in the right place to ask/report.

I got the Rubocop Rails/SaveBang error triggered when I want to create FactoryBot object, using a dynamic value as first parameter. See the Rubocop linter in the following image

✅ Using with trait create(document_type, :my_trait) ✅ Using with public_send FactoryBot.public_send(:create, document_type) ❌ Using only the dynamic first param create(document_type)

Is it like Rubocop think I'm working with ActiveRecord object 😅

Thank you very much in advance for your help 🙏🏼

Reproduction Steps

Written script :

let(:instance_set_with_dynamic_class) { create(document_type) }
let(:instance_set_with_symbol) { create(:invoice) }
let(:instance_set_with_dynamic_class_with_trait) { create(document_type, :my_trait) }
let(:instance_set_with_symbol2) { FactoryBot.public_send(:create, document_type) }

Expected behavior

I would like Rubocop to not treat this as an ActiveRecord object (user.create(...) VS FactoryBot create(:user)) And not linter my line.

System configuration

factory_bot version: 6.4.5 rails version: 7.0.8 ruby version: 3.2.2