Module: Hubbado::Log::Logger::Substitute

Defined in:
lib/hubbado/log/logger/substitute.rb

Overview

What a logger was told rather than what it wrote. Extended onto a mimic of Logger, so a class under test is handed something that answers as a logger and keeps what it was given.

Defined Under Namespace

Classes: Entry

Instance Method Summary collapse

Instance Method Details

#logged(severity = nil, message: nil, tags: nil) ⇒ Object

Everything about what a class said, in order, narrowed by whichever criteria a spec names. Named together, because a run writes several lines and a message and a tag list asserted apart can each be true of a different one.



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/hubbado/log/logger/substitute.rb', line 28

def logged(severity = nil, message: nil, tags: nil)
  entries = invocations.map { |invocation| entry(invocation) }

  named = symbols(tags)

  entries = entries.select { |entry| entry.at?(severity) } unless severity.nil?
  entries = entries.select { |entry| entry.says?(message) } unless message.nil?
  entries = entries.select { |entry| entry.tagged?(named) } unless tags.nil?

  entries
end

#logged?Boolean

Whether, where the two above ask what. Named nothing, whether anything was written.

Returns:

  • (Boolean)


44
# File 'lib/hubbado/log/logger/substitute.rb', line 44

def logged?(...) = !logged(...).empty?

#messagesObject

What a class said, where #logged is everything about it.



41
# File 'lib/hubbado/log/logger/substitute.rb', line 41

def messages(...) = logged(...).map(&:message)