Skip to content

FactoryBot/AttributeDefinedStatically doesn't work well  #1044

@chubchenko

Description

@chubchenko

When processing the following code:

# spec/lib/application/configuration_spec.rb

describe '.ignore' do
  context 'when the block is given' do
    it 'changes the count of the registered regex' do
      expect do
        described_class.ignore do |ignore|
          ignore << /(a|b)/
          ignore.push(/.*/)
        end
      end.to change(described_class.ignore, :count).by(2)
    end
  end
end

I have the next recommendation:

spec/lib/application/configuration_spec.rb:33:13: C: FactoryBot/AttributeDefinedStatically: Use a block to declare attribute values.
            ignore.push(/.*/)
            ^^^^^^^^^^^^

Also, I have the same recommendation in another file:

# spec/dummy/config/initializers/seo.rb

config.ignore do |ignore|
  ignore.push(%r{\A/admin.*}.freeze)
  ignore.push(%r{\A/\z}.freeze)
end
spec/dummy/config/initializers/seo.rb:28:5: C: FactoryBot/AttributeDefinedStatically: Use a block to declare attribute values.
    ignore.push(%r{\A/admin.*}.freeze)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/dummy/config/initializers/seo.rb:29:5: C: FactoryBot/AttributeDefinedStatically: Use a block to declare attribute values.
    ignore.push(%r{\A/\z}.freeze)
    ^^^^^^^^^^^^^^^^^^^^^^
rubocop -V
0.93.1 (using Parser 2.7.2.0, rubocop-ast 0.8.0, running on ruby 2.6.5 x86_64-darwin20)

bundle info rubocop-rspec

* rubocop-rspec (1.43.2)
	Summary: Code style checking for RSpec files
	Homepage: https://github.com/rubocop-hq/rubocop-rspec
	Path: /Users/chubchenko/.rvm/gems/ruby-2.6.5/gems/rubocop-rspec-1.43.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions