debian-mirror-gitlab/spec/rubocop/cop/gitlab/rails_logger_spec.rb

32 lines
955 B
Ruby
Raw Normal View History

2019-09-30 21:07:59 +05:30
# frozen_string_literal: true
2020-07-28 23:09:34 +05:30
require 'fast_spec_helper'
2019-09-30 21:07:59 +05:30
require_relative '../../../../rubocop/cop/gitlab/rails_logger'
2021-03-08 18:12:59 +05:30
RSpec.describe RuboCop::Cop::Gitlab::RailsLogger do
2019-09-30 21:07:59 +05:30
subject(:cop) { described_class.new }
2020-11-24 15:15:51 +05:30
described_class::LOG_METHODS.each do |method|
it "flags the use of Rails.logger.#{method} with a constant receiver" do
2021-03-11 19:13:27 +05:30
node = "Rails.logger.#{method}('some error')"
2019-09-30 21:07:59 +05:30
2021-03-11 19:13:27 +05:30
expect_offense(<<~CODE, node: node, msg: "Use a structured JSON logger instead of `Rails.logger`. [...]")
%{node}
^{node} %{msg}
CODE
2020-11-24 15:15:51 +05:30
end
2019-09-30 21:07:59 +05:30
end
it 'does not flag the use of Rails.logger with a constant that is not Rails' do
2021-03-11 19:13:27 +05:30
expect_no_offenses("AppLogger.error('some error')")
2019-09-30 21:07:59 +05:30
end
it 'does not flag the use of logger with a send receiver' do
2021-03-11 19:13:27 +05:30
expect_no_offenses("file_logger.info('important info')")
2019-09-30 21:07:59 +05:30
end
2020-11-24 15:15:51 +05:30
it 'does not flag the use of Rails.logger.level' do
2021-03-11 19:13:27 +05:30
expect_no_offenses("Rails.logger.level")
2020-11-24 15:15:51 +05:30
end
2019-09-30 21:07:59 +05:30
end