Skip to content

Commit 43c7f8d

Browse files
Updated rspec
1 parent 38a2f01 commit 43c7f8d

File tree

2 files changed

+15
-33
lines changed

2 files changed

+15
-33
lines changed

lib/rubocop/cop/bugcrowd/prevent_bugsnag_usage.rb

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,21 @@
33
module RuboCop
44
module Cop
55
module Bugcrowd
6-
class PreventBugsnagUsage < Cop
6+
class PreventBugsnagUsage < RuboCop::Cop::Base
7+
extend RuboCop::Cop::AutoCorrector
8+
79
MSG = 'Avoid using Bugsnag in the codebase. ' \
810
'It has been replaced with ErrorNotifierService for error ' \
9-
'notification handling. Please use ErrorNotifierService' \
10-
'instead.'
11-
12-
def_node_matcher :bugsnag_usage?, <<-PATTERN
13-
(send
14-
(const nil? :Bugsnag) :notify ...)
15-
PATTERN
11+
'notification handling. Please use ErrorNotifierService instead.'
1612

17-
def_node_matcher :bugsnag_constant?, <<-PATTERN
18-
(const nil? :Bugsnag)
13+
def_node_matcher :bugsnag_usage?, <<~PATTERN
14+
(send (const nil? :Bugsnag) ...)
1915
PATTERN
2016

2117
def on_send(node)
22-
if bugsnag_usage?(node)
23-
add_offense(node, message: MSG)
24-
end
25-
end
18+
return unless bugsnag_usage?(node)
2619

27-
def on_const(node)
28-
if bugsnag_constant?(node)
29-
add_offense(node, message: MSG)
30-
end
20+
add_offense(node, message: MSG)
3121
end
3222
end
3323
end
Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
# frozen_string_literal: true
22

3-
RSpec.describe RuboCop::Cop::Bugcrowd::PreventBugsnagUsage do
3+
RSpec.describe RuboCop::Cop::Bugcrowd::PreventBugsnagUsage, :config do
44
subject(:cop) { described_class.new(config) }
5-
let(:config) { RuboCop::Config.new }
65

7-
it 'registers an offense when Bugsnag.notify is used' do
6+
it 'registers an offense when Bugsnag is used as a constant' do
87
expect_offense(<<~RUBY)
9-
Bugsnag.notify('Error')
10-
^^^^^^^ Bugcrowd/PreventBugsnagUsage: Avoid using Bugsnag in the codebase. It has been replaced with ErrorNotifierService for error notification handling. Please use ErrorNotifierServiceinstead.
11-
^^^^^^^^^^^^^^^^^^^^^^^ Bugcrowd/PreventBugsnagUsage: Avoid using Bugsnag in the codebase. It has been replaced with ErrorNotifierService for error notification handling. Please use ErrorNotifierServiceinstead.
8+
Bugsnag.error('Error')
9+
^^^^^^^^^^^^^^^^^^^^^^ Avoid using Bugsnag in the codebase. It has been replaced with ErrorNotifierService for error notification handling. Please use ErrorNotifierService instead.
1210
RUBY
1311
end
1412

15-
it 'registers an offense when Bugsnag is used as a constant' do
13+
it 'registers an offense when Bugsnag.notify is used' do
1614
expect_offense(<<~RUBY)
17-
Bugsnag.error('Error')
18-
^^^^^^^ Bugcrowd/PreventBugsnagUsage: Avoid using Bugsnag in the codebase. It has been replaced with ErrorNotifierService for error notification handling. Please use ErrorNotifierServiceinstead.
15+
Bugsnag.notify('Error')
16+
^^^^^^^^^^^^^^^^^^^^^^^ Avoid using Bugsnag in the codebase. It has been replaced with ErrorNotifierService for error notification handling. Please use ErrorNotifierService instead.
1917
RUBY
2018
end
2119

@@ -24,10 +22,4 @@
2422
ErrorNotifierService.notify('Error')
2523
RUBY
2624
end
27-
28-
it 'does not register an offense when no Bugsnag is used' do
29-
expect_no_offenses(<<~RUBY)
30-
SomeOtherService.notify('Error')
31-
RUBY
32-
end
3325
end

0 commit comments

Comments
 (0)