-
-
Notifications
You must be signed in to change notification settings - Fork 248
/
eager_evaluation_log_message_spec.rb
37 lines (32 loc) · 1.2 KB
/
eager_evaluation_log_message_spec.rb
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
32
33
34
35
36
37
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::Rails::EagerEvaluationLogMessage, :config do
it 'registers an offense when passing an interpolated string to Rails.logger.debug' do
expect_offense(<<~'RUBY')
Rails.logger.debug "The time is #{Time.now}"
^^^^^^^^^^^^^^^^^^^^^^^^^ Pass a block to `Rails.logger.debug`.
RUBY
expect_correction(<<~'RUBY')
Rails.logger.debug { "The time is #{Time.now}" }
RUBY
end
it 'does not register an offense when passing an interpolated string to Rails.logger.info' do
expect_no_offenses(<<~'RUBY')
Rails.logger.info("The time is #{Time.now}")
Rails.logger.info "The time is #{Time.now}"
RUBY
end
it 'does not register an offense when passing a string to Rails.logger.debug' do
expect_no_offenses(<<~RUBY)
Rails.logger.debug('A log message')
Rails.logger.debug 'A log message'
RUBY
end
it 'does not register an offense when passing an interpolated string in a block to Rails.logger.debug' do
expect_no_offenses(<<~'RUBY')
Rails.logger.debug { "The time is #{Time.now}" }
Rails.logger.debug do
"The time is #{Time.now}"
end
RUBY
end
end