Use standard log utility

This commit is contained in:
Michael Miller 2020-10-17 11:46:21 -06:00
parent e6d78345c4
commit 9c1fd6fb5a
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
3 changed files with 12 additions and 23 deletions

View file

@ -28,7 +28,7 @@ module Spectator
# Returns the result of the execution.
# The result will also be stored in `#result`.
def run : Result
Spectator.debug("Running example #{self}")
Log.debug { "Running example #{self}" }
@delegate.call(self)
raise NotImplementedError.new("#run")
end

View file

@ -8,6 +8,8 @@ module Spectator
# A stack is used to track the current example group.
# Adding an example or group will nest it under the group at the top of the stack.
class SpecBuilder
Log = ::Spectator::Log.for(self)
# Stack tracking the current group.
# The bottom of the stack (first element) is the root group.
# The root group should never be removed.
@ -36,7 +38,7 @@ module Spectator
# The newly created group is returned.
# It shouldn't be used outside of this class until a matching `#end_group` is called.
def start_group(name, source = nil) : ExampleGroup
Spectator.debug("Start group: #{name.inspect} @ #{source}")
Log.trace { "Start group: #{name.inspect} @ #{source}" }
ExampleGroup.new(name, source, current_group).tap do |group|
@group_stack << group
end
@ -49,7 +51,7 @@ module Spectator
# At this point, it is safe to use the group.
# All of its examples and sub-groups have been populated.
def end_group : ExampleGroup
Spectator.debug("End group: #{current_group}")
Log.trace { "End group: #{current_group}" }
raise "Can't pop root group" if root?
@group_stack.pop
@ -74,7 +76,7 @@ module Spectator
#
# The newly created example is returned.
def add_example(name, source, context, &block : Example, Context ->) : Example
Spectator.debug("Add example: #{name} @ #{source}")
Log.trace { "Add example: #{name} @ #{source}" }
delegate = ExampleContextDelegate.new(context, block)
Example.new(delegate, name, source, current_group)
# The example is added to the current group by `Example` initializer.