Factorybot 查找 class 已弃用

Factorybot looking up by class deprecated

我正在尝试在 rails 应用程序中创建 shared_example。它正在工作,但我收到弃用错误。我可以重构代码来解决这个问题吗?

错误

Looking up factories by class is deprecated and will be removed in 5.0. Use symbols instead and set FactoryBot.allow_class_lookup = false.

来源

shared_examples 'a sanatized_record' do
  subject { build(described_class) }

  describe 'stripped_attributes' do
    described_class::STRIPPED_ATTRIBUTES.each do |attr|
      it "strips whitespaces from #{attr}" do
        original = subject[attr]
        subject[attr] = " #{original} "
        subject.validate
        expect(subject[attr]).to eq original
      end
    end
  end
end

相关 post 主题:

从 link -- 更新工厂到 factory :foo_bar, class: 'foo/bar' do; end 应该工作因为 key.to_s.underscore.to_sym in this class