Skip to content

Commit 8eb550e

Browse files
authored
Merge pull request #924 from rubocop-hq/fix-leaky-constant-declarations
Fix leaky constant declaration in specs
2 parents 97e8ebb + f6ac99e commit 8eb550e

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

spec/rubocop/cop/rspec/cop_spec.rb

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
RSpec.describe RuboCop::Cop::RSpec::Cop do
4-
subject(:cop) { fake_cop.new(config) }
4+
subject(:cop) { RuboCop::RSpec::FakeCop.new(config) }
55

66
let(:config) do
77
rubocop_config =
@@ -19,21 +19,17 @@
1919
RuboCop::Config.new(rubocop_config, 'fake_cop_config.yml')
2020
end
2121

22-
let(:fake_cop) do
23-
# rubocop:disable Style/ClassAndModuleChildren
24-
# rubocop:disable RSpec/LeakyConstantDeclaration
25-
class RuboCop::RSpec::FakeCop < described_class
26-
def on_send(node)
27-
add_offense(node, message: 'I flag everything')
28-
end
29-
end
30-
# rubocop:enable Style/ClassAndModuleChildren
31-
# rubocop:enable RSpec/LeakyConstantDeclaration
32-
RuboCop::RSpec::FakeCop
33-
end
34-
3522
let(:rspec_patterns) { ['_spec.rb$', '(?:^|/)spec/'] }
3623

24+
before do
25+
stub_const('RuboCop::RSpec::FakeCop',
26+
Class.new(described_class) do
27+
def on_send(node)
28+
add_offense(node, message: 'I flag everything')
29+
end
30+
end)
31+
end
32+
3733
context 'when the source path ends with `_spec.rb`' do
3834
it 'registers an offense' do
3935
expect_offense(<<-RUBY, 'foo_spec.rb')

0 commit comments

Comments
 (0)