<commit_before># frozen_string_literal: true

RSpec.describe RuboCop::Cop::Lint::SuppressedException, :config do
  subject(:cop) { described_class.new(config) }

  it 'registers an offense for empty rescue block' do
    expect_offense(<<~RUBY)
      begin
        something
      rescue
      ^^^^^^ Do not suppress exceptions.
        #do nothing
      end
    RUBY
  end

  it 'does not register an offense for rescue with body' do
    expect_no_offenses(<<~RUBY)
      begin
        something
        return
      rescue
        file.close
      end
    RUBY
  end

  context 'AllowComments' do
    let(:cop_config) { { 'AllowComments' => true } }

    it 'does not register an offense for empty rescue with comment' do
      expect_no_offenses(<<~RUBY)
        begin
          something
          return
        rescue
          # do nothing
        end
      RUBY
    end

    it 'registers an offense for empty rescue on single line with a comment after it' do<commit_msg>Lint/SuppressedException: Explicit AllowComments config in spec<commit_after># frozen_string_literal: true

RSpec.describe RuboCop::Cop::Lint::SuppressedException, :config do
  subject(:cop) { described_class.new(config) }

  context 'with AllowComments set to false' do
    let(:cop_config) { { 'AllowComments' => false } }

    it 'registers an offense for empty rescue block' do
      expect_offense(<<~RUBY)
        begin
          something
        rescue
        ^^^^^^ Do not suppress exceptions.
          #do nothing
        end
      RUBY
    end

    it 'does not register an offense for rescue with body' do
      expect_no_offenses(<<~RUBY)
        begin
          something
          return
        rescue
          file.close
        end
      RUBY
    end
  end

  context 'with AllowComments set to true' do
    let(:cop_config) { { 'AllowComments' => true } }

    it 'does not register an offense for empty rescue with comment' do
      expect_no_offenses(<<~RUBY)
        begin
          something
          return
        rescue
          # do nothing
        end
      RUBY
    end

    it 'registers an offense for empty rescue on single line with a comment after it' do
{'fraction_non_alphanumeric': 0.06955320128972824, 'fraction_numerical': 0.0, 'mean_word_length': 2.1661807580174925, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1364657', 'n_tokens_mistral': 631, 'n_tokens_neox': 602, 'n_words': 209}