diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cda0d7ae..4ce00fd95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Master (Unreleased) * Extend the list of Rails spec types for `RSpec/DescribeClass`. ([@pirj][]) +* Fix `FactoryBot/AttributeDefinedStatically` to allow `#traits_for_enum` without a block. ([@harrylewis][]) ## 1.40.0 (2020-06-11) @@ -520,3 +521,4 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features. [@robotdana]: https://github.com/robotdana [@rolfschmidt]: https://github.com/rolfschmidt [@andrykonchin]: https://github.com/andrykonchin +[@harrylewis]: https://github.com/harrylewis diff --git a/lib/rubocop/rspec/factory_bot.rb b/lib/rubocop/rspec/factory_bot.rb index 539bcf70c..9fbda437f 100644 --- a/lib/rubocop/rspec/factory_bot.rb +++ b/lib/rubocop/rspec/factory_bot.rb @@ -4,7 +4,13 @@ module RuboCop module RSpec # RuboCop FactoryBot project namespace module FactoryBot - ATTRIBUTE_DEFINING_METHODS = %i[factory trait transient ignore].freeze + ATTRIBUTE_DEFINING_METHODS = %i[ + factory + ignore + trait + traits_for_enum + transient + ].freeze UNPROXIED_METHODS = %i[ __send__ diff --git a/spec/rubocop/cop/rspec/factory_bot/attribute_defined_statically_spec.rb b/spec/rubocop/cop/rspec/factory_bot/attribute_defined_statically_spec.rb index 2e44e5a04..4caba3915 100644 --- a/spec/rubocop/cop/rspec/factory_bot/attribute_defined_statically_spec.rb +++ b/spec/rubocop/cop/rspec/factory_bot/attribute_defined_statically_spec.rb @@ -154,6 +154,16 @@ RUBY end + it 'accepts valid traits_for_enum definition' do + expect_no_offenses(<<-RUBY) + FactoryBot.define do + factory :post do + traits_for_enum :status, [:draft, :published] + end + end + RUBY + end + bad = <<-RUBY FactoryBot.define do factory :post do