|
3 | 3 | RSpec.describe RuboCop::Cop::Bugcrowd::PreventBugsnagUsage, :config do |
4 | 4 | subject(:cop) { described_class.new(config) } |
5 | 5 |
|
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:) |
8 | 14 | 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} |
10 | 16 | RUBY |
11 | 17 | end |
12 | 18 |
|
13 | 19 | it 'registers an offense when Bugsnag.notify is used' do |
14 | | - expect_offense(<<~RUBY) |
| 20 | + expect_offense(<<~RUBY, message:) |
15 | 21 | 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} |
17 | 23 | RUBY |
18 | 24 | end |
19 | 25 |
|
20 | | - it 'does not register an offense when ErrorNotifierService is used' do |
| 26 | + it 'does not register an offense for ErrorNotifierService' do |
21 | 27 | expect_no_offenses(<<~RUBY) |
22 | 28 | ErrorNotifierService.notify('Error') |
23 | 29 | RUBY |
24 | 30 | 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 |
25 | 50 | end |
0 commit comments