class Testify::Tracker::LogTracer

Overview

A simple Tracer implementation that logs calls. By default it logs the number of calls of the #add method but it is possible to specify a different message to the #add method.

class ExampleTest < Testify::Test
  include Testify::Tracker

  def initialize
    @tracer = LogTracer.new
    log_trace(:initialize)
    log_trace(:key_is_a_symbol_or_string)
    log_trace("foo", "bar")
    log_trace("foo", "another trace for foo")
  end

  def log_trace(name : String | Symbol, message : String? = nil) : Nil
    @tracer.add(name, message)
  end

  def tracer_size(name : String | Symbol) : Int32
    @tracer.size(name)
  end

  def tracer : LogTracer
    @tracer
  end

  def test_example_tracer
    tracer_size("foo").should eq 2

    # debug
    pp tracer.get("foo")
  end
end

Defined in:

tracer/log_tracer.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new #

[View source]

Instance Method Detail

def add(name : String | Symbol, message : String | Nil = nil) #

Creates a trace referenced to the name namespace. The default message is the increment number of the current call (#1, #2, #3, ...). See Tracer#add.


[View source]
def size(name : String | Symbol) : Int32 #

Returns the number of traces performed. See Tracer#size.


[View source]
def tracer : Tracer(String) #

Returns the Tracer instance used by the LogTracer instance.


[View source]
def traces #

Returns all traces. See Tracer#traces.


[View source]