Skip to content

Fix RuboCop offenses in error tracking project setting specs

What does this MR do and why?

This MR fixes some 👮 offenses in error tracking project settings specs.

Note that using verified doubles uncovered two spec bugs.

Screenshots or screen recordings

n/a

How to set up and validate locally

Before

$ REVEAL_RUBOCOP_TODO=1 be rubocop spec/models/error_tracking/project_error_tracking_setting_spec.rb
Inspecting 1 file
C

Offenses:

spec/models/error_tracking/project_error_tracking_setting_spec.rb:51:13: C: RSpec/ContextWording: Start context description with 'when', 'with', or 'without'.
    context 'presence validations' do
            ^^^^^^^^^^^^^^^^^^^^^^
spec/models/error_tracking/project_error_tracking_setting_spec.rb:86:15: C: RSpec/ContextWording: Start context description with 'when', 'with', or 'without'.
      context 'no client key yet' do
              ^^^^^^^^^^^^^^^^^^^
spec/models/error_tracking/project_error_tracking_setting_spec.rb:91:17: C: RSpec/ContextWording: Start context description with 'when', 'with', or 'without'.
        context 'sentry backend' do
                ^^^^^^^^^^^^^^^^
spec/models/error_tracking/project_error_tracking_setting_spec.rb:101:17: C: RSpec/ContextWording: Start context description with 'when', 'with', or 'without'.
        context 'feature disabled' do
                ^^^^^^^^^^^^^^^^^^
spec/models/error_tracking/project_error_tracking_setting_spec.rb:112:15: C: RSpec/ContextWording: Start context description with 'when', 'with', or 'without'.
      context 'client key already exists' do
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/error_tracking/project_error_tracking_setting_spec.rb:172:29: C: RSpec/VerifiedDoubles: Prefer using verifying doubles over normal doubles.
      let(:sentry_client) { spy(:sentry_client) }
                            ^^^^^^^^^^^^^^^^^^^
spec/models/error_tracking/project_error_tracking_setting_spec.rb:178:9: C: RSpec/ExpectInHook: Do not use expect in before hook
        expect(subject).to receive(:sentry_client).and_return(sentry_client)
        ^^^^^^
spec/models/error_tracking/project_error_tracking_setting_spec.rb:198:29: C: RSpec/VerifiedDoubles: Prefer using verifying doubles over normal doubles.
      let(:sentry_client) { spy(:sentry_client) }
                            ^^^^^^^^^^^^^^^^^^^
spec/models/error_tracking/project_error_tracking_setting_spec.rb:217:29: C: RSpec/VerifiedDoubles: Prefer using verifying doubles over normal doubles.
      let(:sentry_client) { spy(:sentry_client) }
                            ^^^^^^^^^^^^^^^^^^^
spec/models/error_tracking/project_error_tracking_setting_spec.rb:224:121: C: Layout/LineLength: Line is too long. [127/120]
          .and_raise(ErrorTracking::SentryClient::MissingKeysError, 'Sentry API response is missing keys. key not found: "id"')
                                                                                                                        ^^^^^^^
spec/models/error_tracking/project_error_tracking_setting_spec.rb:236:29: C: RSpec/VerifiedDoubles: Prefer using verifying doubles over normal doubles.
      let(:sentry_client) { spy(:sentry_client) }
                            ^^^^^^^^^^^^^^^^^^^
spec/models/error_tracking/project_error_tracking_setting_spec.rb:237:24: C: Layout/SpaceInsideBlockBraces: Space missing inside {.
      let(:error_msg) {"Sentry API response is too big. Limit is #{Gitlab::Utils::DeepSize.human_default_max_size}."}
                       ^
spec/models/error_tracking/project_error_tracking_setting_spec.rb:237:117: C: Layout/SpaceInsideBlockBraces: Space missing inside }.
      let(:error_msg) {"Sentry API response is too big. Limit is #{Gitlab::Utils::DeepSize.human_default_max_size}."}
                                                                                                                    ^
spec/models/error_tracking/project_error_tracking_setting_spec.rb:256:29: C: RSpec/VerifiedDoubles: Prefer using verifying doubles over normal doubles.
      let(:sentry_client) { spy(:sentry_client) }
                            ^^^^^^^^^^^^^^^^^^^
spec/models/error_tracking/project_error_tracking_setting_spec.rb:273:27: C: RSpec/VerifiedDoubles: Prefer using verifying doubles over normal doubles.
    let(:sentry_client) { spy(:sentry_client) }
                          ^^^^^^^^^^^^^^^^^^^
spec/models/error_tracking/project_error_tracking_setting_spec.rb:287:27: C: RSpec/VerifiedDoubles: Prefer using verifying doubles over normal doubles.
    let(:sentry_client) { double('sentry_client', issue_details: issue) }
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/error_tracking/project_error_tracking_setting_spec.rb:299:9: C: RSpec/ExpectInHook: Do not use expect in before hook
        expect(subject).to receive(:sentry_client).and_return(sentry_client)
        ^^^^^^
spec/models/error_tracking/project_error_tracking_setting_spec.rb:317:24: C: RSpec/VerifiedDoubles: Prefer using verifying doubles over normal doubles.
        let(:commit) { double('commit', id: commit_id) }
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/error_tracking/project_error_tracking_setting_spec.rb:318:28: C: RSpec/VerifiedDoubles: Prefer using verifying doubles over normal doubles.
        let(:repository) { double('repository', commit: commit) }
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/error_tracking/project_error_tracking_setting_spec.rb:321:11: C: RSpec/ExpectInHook: Do not use expect in before hook
          expect(project).to receive(:repository).and_return(repository)
          ^^^^^^
spec/models/error_tracking/project_error_tracking_setting_spec.rb:325:121: C: Layout/LineLength: Line is too long. [130/120]
        it { expect(result[:issue].gitlab_commit_path).to eq("/#{project.namespace.path}/#{project.path}/-/commit/#{commit_id}") }
                                                                                                                        ^^^^^^^^^^
spec/models/error_tracking/project_error_tracking_setting_spec.rb:344:27: C: RSpec/VerifiedDoubles: Prefer using verifying doubles over normal doubles.
    let(:sentry_client) { spy(:sentry_client) }
                          ^^^^^^^^^^^^^^^^^^^
spec/models/error_tracking/project_error_tracking_setting_spec.rb:346:13: C: RSpec/ContextWording: Start context description with 'when', 'with', or 'without'.
    context 'successful call to sentry' do
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/error_tracking/project_error_tracking_setting_spec.rb:357:13: C: RSpec/ContextWording: Start context description with 'when', 'with', or 'without'.
    context 'sentry raises an error' do
            ^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/error_tracking/project_error_tracking_setting_spec.rb:369:11: C: RSpec/ContextWording: Start context description with 'when', 'with', or 'without'.
  context 'slugs' do
          ^^^^^^^
spec/models/error_tracking/project_error_tracking_setting_spec.rb:396:11: C: RSpec/ContextWording: Start context description with 'when', 'with', or 'without'.
  context 'names from api_url' do
          ^^^^^^^^^^^^^^^^^^^^
spec/models/error_tracking/project_error_tracking_setting_spec.rb:398:15: C: RSpec/ContextWording: Start context description with 'when', 'with', or 'without'.
      context 'name is present in DB' do
              ^^^^^^^^^^^^^^^^^^^^^^^
spec/models/error_tracking/project_error_tracking_setting_spec.rb:407:15: C: RSpec/ContextWording: Start context description with 'when', 'with', or 'without'.
      context 'name is null in DB' do
              ^^^^^^^^^^^^^^^^^^^^

1 file inspected, 28 offenses detected, 4 offenses auto-correctable

After

$ REVEAL_RUBOCOP_TODO=1 be rubocop spec/models/error_tracking/project_error_tracking_setting_spec.rb
Inspecting 1 file
.

1 file inspected, no offenses detected

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Peter Leitzen

Merge request reports