我正在尝试在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
答案 0 :(得分:2)
有关该主题的相关文章:FactoryBot namespaced models without class_name
从链接-将工厂更新为
由于factory :foo_bar, class: 'foo/bar' do; end
in this class
key.to_s.underscore.to_sym
应该可以工作