Add and apply ConstantDefinitionInBlock rule

This rule was added in Rubocop 0.91.0. A similar rule named
LeakyConstantDeclaration was added in rubocop-rspec 1.34.0.

Note using the FILENAMES constant did not result in an offense using the
ConstantDefinitionInBlock rule but did result in an offense using the
LeakyConstantDeclaration rule. I've simplified the code to get rid of
the constant; not sure why we were adding a constant with `||=` in the
middle of a spec.
This commit is contained in:
Javi Martín
2020-10-14 12:03:26 +02:00
parent eb02bc756a
commit b27d0a8e92
5 changed files with 31 additions and 17 deletions

View File

@@ -1,10 +1,14 @@
require "rails_helper"
describe ConsulFormBuilder do
class DummyModel
include ActiveModel::Model
OPTIONS = %w[Good Bad Ugly].freeze
attr_accessor :title, :quality
before do
dummy_model = Class.new do
include ActiveModel::Model
attr_accessor :title, :quality
end
stub_const("DummyModel", dummy_model)
stub_const("DummyModel::OPTIONS", %w[Good Bad Ugly].freeze)
end
let(:builder) { ConsulFormBuilder.new(:dummy, DummyModel.new, ActionView::Base.new, {}) }