File: fake_logger.rb

package info (click to toggle)
ruby-mocha 3.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,656 kB
  • sloc: ruby: 12,304; javascript: 499; makefile: 14
file content (36 lines) | stat: -rw-r--r-- 668 bytes parent folder | download
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
# frozen_string_literal: true

require 'mocha/logger'

class FakeLogger
  def initialize
    @warnings_by_category = Hash.new { |h, k| h[k] = [] }
  end

  def warning(message, category: nil)
    @warnings_by_category[category] << message
  end

  def warnings(category: nil)
    @warnings_by_category[category]
  end

  def deprecation_warnings
    @warnings_by_category[:deprecation]
  end

  module TestHelper
    def self.setup
      @original_logger = Mocha::Logger.logger
      Mocha::Logger.logger = FakeLogger.new
    end

    def self.teardown
      Mocha::Logger.logger = @original_logger
    end

    def logger
      Mocha::Logger.logger
    end
  end
end