Welcome to mirror list, hosted at ThFree Co, Russian Federation.

rails_logger_spec.rb « gitlab « cop « rubocop « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 24f49bf3044c2d8989896de6b5300b022be0df6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true

require 'fast_spec_helper'
require_relative '../../../../rubocop/cop/gitlab/rails_logger'

RSpec.describe RuboCop::Cop::Gitlab::RailsLogger do
  subject(:cop) { described_class.new }

  described_class::LOG_METHODS.each do |method|
    it "flags the use of Rails.logger.#{method} with a constant receiver" do
      node = "Rails.logger.#{method}('some error')"

      expect_offense(<<~CODE, node: node, msg: "Use a structured JSON logger instead of `Rails.logger`. [...]")
        %{node}
        ^{node} %{msg}
      CODE
    end
  end

  it 'does not flag the use of Rails.logger with a constant that is not Rails' do
    expect_no_offenses("AppLogger.error('some error')")
  end

  it 'does not flag the use of logger with a send receiver' do
    expect_no_offenses("file_logger.info('important info')")
  end

  it 'does not flag the use of Rails.logger.level' do
    expect_no_offenses("Rails.logger.level")
  end
end