Skip to content

Commit 3303775

Browse files
Updated rspec
1 parent 43c7f8d commit 3303775

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

lib/rubocop/cop/bugcrowd/prevent_bugsnag_usage.rb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,12 @@ module RuboCop
44
module Cop
55
module Bugcrowd
66
class PreventBugsnagUsage < RuboCop::Cop::Base
7-
extend RuboCop::Cop::AutoCorrector
8-
97
MSG = 'Avoid using Bugsnag in the codebase. ' \
108
'It has been replaced with ErrorNotifierService for error ' \
119
'notification handling. Please use ErrorNotifierService instead.'
1210

13-
def_node_matcher :bugsnag_usage?, <<~PATTERN
14-
(send (const nil? :Bugsnag) ...)
15-
PATTERN
16-
1711
def on_send(node)
18-
return unless bugsnag_usage?(node)
19-
20-
add_offense(node, message: MSG)
12+
add_offense(node, message: MSG) if node.receiver&.const_name == 'Bugsnag'
2113
end
2214
end
2315
end

spec/rubocop/cop/bugcrowd/prevent_bugsnag_usage_spec.rb

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,48 @@
33
RSpec.describe RuboCop::Cop::Bugcrowd::PreventBugsnagUsage, :config do
44
subject(:cop) { described_class.new(config) }
55

6-
it 'registers an offense when Bugsnag is used as a constant' do
7-
expect_offense(<<~RUBY)
6+
let(:message) do
7+
'Avoid using Bugsnag in the codebase. ' \
8+
'It has been replaced with ErrorNotifierService for error ' \
9+
'notification handling. Please use ErrorNotifierService instead.'
10+
end
11+
12+
it 'registers an offense when Bugsnag is used' do
13+
expect_offense(<<~RUBY, message:)
814
Bugsnag.error('Error')
9-
^^^^^^^^^^^^^^^^^^^^^^ Avoid using Bugsnag in the codebase. It has been replaced with ErrorNotifierService for error notification handling. Please use ErrorNotifierService instead.
15+
^^^^^^^^^^^^^^^^^^^^^^ %{message}
1016
RUBY
1117
end
1218

1319
it 'registers an offense when Bugsnag.notify is used' do
14-
expect_offense(<<~RUBY)
20+
expect_offense(<<~RUBY, message:)
1521
Bugsnag.notify('Error')
16-
^^^^^^^^^^^^^^^^^^^^^^^ Avoid using Bugsnag in the codebase. It has been replaced with ErrorNotifierService for error notification handling. Please use ErrorNotifierService instead.
22+
^^^^^^^^^^^^^^^^^^^^^^^ %{message}
1723
RUBY
1824
end
1925

20-
it 'does not register an offense when ErrorNotifierService is used' do
26+
it 'does not register an offense for ErrorNotifierService' do
2127
expect_no_offenses(<<~RUBY)
2228
ErrorNotifierService.notify('Error')
2329
RUBY
2430
end
31+
32+
it 'does not register an offense for unrelated constants' do
33+
expect_no_offenses(<<~RUBY)
34+
SomeOtherService.notify('Error')
35+
RUBY
36+
end
37+
38+
it 'does not register an offense for lowercase bugsnag' do
39+
expect_no_offenses(<<~RUBY)
40+
bugsnag.error('Error')
41+
RUBY
42+
end
43+
44+
it 'does not register an offense for local variable named Bugsnag' do
45+
expect_no_offenses(<<~RUBY)
46+
bugsnag = SomeService.new
47+
bugsnag.error('Error')
48+
RUBY
49+
end
2550
end

0 commit comments

Comments
 (0)