FactoryBot 0.4.11 で closed_at 1.day.from_now といった FactoryBot のコードに対して以下のような警告が出るようになった。
DEPRECATION WARNING: Static attributes will be removed in FactoryBot 5.0. Please use dynamic
attributes instead by wrapping the attribute value in a block:
closed_at { 1.day.from_now }
To automatically update from static attributes to dynamic ones,
install rubocop-rspec and run:
rubocop \
--require rubocop-rspec \
--only FactoryBot/AttributeDefinedStatically \
--auto-correct
この警告に記されているとおり、RuboCop RSpec の FactoryBot/AttributeDefinedStatically cop が auto-correct を備えているので、そのとおりのコマンドを叩くと警告を抑制する形に変更できる。
RuboCop RSpec を梱包していて、依存が緩められている OnkCop 0.53.0.1 以降だと以下で良い。
% bundle exec rubocop --only FactoryBot/AttributeDefinedStatically -a
余談だけれど、この FactoryBot の警告へ対策として FactoryBot/AttributeDefinedStatically cop の提案と実装をしたダニエルが FactoryBot のコミッターになってリリースされたのがこの 0.4.11 ということで、おめでたい話だった。