Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
8 changes: 7 additions & 1 deletion lib/rubocop/rspec/factory_bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines -7 to +13
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding :traits_for_enum caused a Layout/LineLength offense, so I turned the horizontal list into a vertical list. I also alphabetized the list to align with what was done with the other constants below.


UNPROXIED_METHODS = %i[
__send__
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down