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

43 lines
1.1 KiB
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 'rubocop'
require 'rubocop/rspec/support'
require_relative '../../../../rubocop/cop/gitlab/rails_logger'
2020-07-28 23:09:34 +05:30
RSpec.describe RuboCop::Cop::Gitlab::RailsLogger, type: :rubocop do
2019-09-30 21:07:59 +05:30
include CopHelper
subject(:cop) { described_class.new }
it 'flags the use of Rails.logger.error with a constant receiver' do
inspect_source("Rails.logger.error('some error')")
expect(cop.offenses.size).to eq(1)
end
it 'flags the use of Rails.logger.info with a constant receiver' do
inspect_source("Rails.logger.info('some info')")
expect(cop.offenses.size).to eq(1)
end
it 'flags the use of Rails.logger.warn with a constant receiver' do
inspect_source("Rails.logger.warn('some warning')")
expect(cop.offenses.size).to eq(1)
end
it 'does not flag the use of Rails.logger with a constant that is not Rails' do
inspect_source("AppLogger.error('some error')")
expect(cop.offenses.size).to eq(0)
end
it 'does not flag the use of logger with a send receiver' do
inspect_source("file_logger.info('important info')")
expect(cop.offenses.size).to eq(0)
end
end