https://github.com/thoughtbot/factory_bot/pull/1135 deprecated static attributes, and I plan to remove them in factory_bot 5. This Cop allows you to automatically update your code to use dynamic attributes instead of static attributes. Once that PR gets merged, I would like to make sure we document the Cop in an obvious place: either in the README, an upgrade guide, or maybe in the deprecation warning itself.
Get the latest version of rubocop-rspec and run:
rubocop \
--require rubocop-rspec \
--only FactoryBot/AttributeDefinedStatically \
--auto-correct
rubocop \
--require rubocop-rspec \
--only FactoryBot/AttributeDefinedStatically \
--auto-correct
Inspecting 223 files
0 files inspected, no offenses detected
Unrecognized cop or department: FactoryBot/AttributeDefinedStatically.
Anything i need to do to get this working? I have the latest rubocop-rspec
Hm, I have definitely seen this work. Can you double check the rubocop-rspec version in your gemfile.lock? It should be 1.28
Hey
I was just about to delete my comment. For some reason, we had rubocop locked to an old version, which prevented rubocop-rspec from installing the newer version.
780 files inspected, no offenses detected
rubocop (0.59.0)
rubocop-rspec (1.29.1)
I've got deprecations all throughout the logs but when running the suggested rubocop command I also get nothing updated/no offenses...
Is it possible you are running into this issue: https://github.com/thoughtbot/factory_bot/issues/1173?
I think if your factories are anywhere besides spec/factories you need to add configuration to a .rubocop.yml. If that is what you are running into, I can help get you the correct configuration later today.
Definitely @composerinteralia - thanks.
@composerinteralia also running into the same issue (factories aren't in spec/factories so the script doesn't work) - how would I configure that?
Edit: For anyone also having this issue, I just changed the name of the folder that the factories were in to spec, then ran the script, then changed the folder name back before pushing my code
Here are the steps to get the autocorrect working if you're using Minitest:
gem install rubocop-rspecAllCops:
RSpec:
Patterns:
- _test.rb
- "(?:^|/)test/"
RSpec/FactoryBot:
Patterns:
- test/factories/**/*.rb
rubocop --require rubocop-rspec --only FactoryBot/AttributeDefinedStatically --auto-correctRuboCop configuration: https://github.com/thoughtbot/factory_bot/issues/1173#issuecomment-421410343
$ gem list | grep cop
rubocop (0.52.1)
rubocop-rspec (1.29.1)
rubycop (1.0.1)
$ rubocop --require rubocop-rspec --only FactoryBot/AttributeDefinedStatically --auto-correct
cannot load such file -- rubocop-rspec
/Users/makk/.rvm/gems/ruby-2.5.1@gdeslon5/gems/rubocop-0.52.1/lib/rubocop/options.rb:63:in `require
This doesn't work in the latest version but does if I lock my Gemfile to the ones noted above i.e. rubocop (0.59.0) + rubocop-rspec (1.29.1). Obviously I've sorted it now but thought I'd leave a note for the next person!
Thanks @sbleon, great fix!
Most helpful comment
Anything i need to do to get this working? I have the latest rubocop-rspec