Class: Startback::Support::SpyLogger

Inherits:
Logger
  • Object
show all
Defined in:
lib/startback/support/spy_logger.rb

Overview

A Logger extension that spies message for inspection during integration testing

Instance Method Summary collapse

Constructor Details

#initialize(*args, &bl) ⇒ SpyLogger

Returns a new instance of SpyLogger.



9
10
11
12
# File 'lib/startback/support/spy_logger.rb', line 9

def initialize(*args, &bl)
  super(*args, &bl)
  reset_spy_state!
end

Instance Method Details

#has?(severity, match = {}) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/startback/support/spy_logger.rb', line 18

def has?(severity, match = {})
  @state[severity] && @state[severity].find{|x|
    match.each_pair.all?{|(k,v)| x[k] == v }
  }
end

#reset_spy_state!Object



14
15
16
# File 'lib/startback/support/spy_logger.rb', line 14

def reset_spy_state!
  @state = Hash.new
end

#spy(severity, args) ⇒ Object



24
25
26
27
# File 'lib/startback/support/spy_logger.rb', line 24

def spy(severity, args)
  @state[severity] ||= []
  @state[severity] << args[0]
end