Skip to content

Commit

Permalink
Fix leaking constant
Browse files Browse the repository at this point in the history
rubocop/rubocop#8095 allowed to dynamically
declare cops with Class.new

We don't have to bump minimally required RuboCop version since it only
affects our specs, and we always use the latest RuboCop for specs.
  • Loading branch information
pirj committed Jun 7, 2020
1 parent 97e8ebb commit f6ac99e
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions spec/rubocop/cop/rspec/cop_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

RSpec.describe RuboCop::Cop::RSpec::Cop do
subject(:cop) { fake_cop.new(config) }
subject(:cop) { RuboCop::RSpec::FakeCop.new(config) }

let(:config) do
rubocop_config =
Expand All @@ -19,21 +19,17 @@
RuboCop::Config.new(rubocop_config, 'fake_cop_config.yml')
end

let(:fake_cop) do
# rubocop:disable Style/ClassAndModuleChildren
# rubocop:disable RSpec/LeakyConstantDeclaration
class RuboCop::RSpec::FakeCop < described_class
def on_send(node)
add_offense(node, message: 'I flag everything')
end
end
# rubocop:enable Style/ClassAndModuleChildren
# rubocop:enable RSpec/LeakyConstantDeclaration
RuboCop::RSpec::FakeCop
end

let(:rspec_patterns) { ['_spec.rb$', '(?:^|/)spec/'] }

before do
stub_const('RuboCop::RSpec::FakeCop',
Class.new(described_class) do
def on_send(node)
add_offense(node, message: 'I flag everything')
end
end)
end

context 'when the source path ends with `_spec.rb`' do
it 'registers an offense' do
expect_offense(<<-RUBY, 'foo_spec.rb')
Expand Down

0 comments on commit f6ac99e

Please sign in to comment.