test/functional/formatting.rb in chalk-log-0.1.2 vs test/functional/formatting.rb in chalk-log-0.1.3

- old
+ new

@@ -3,31 +3,44 @@ require 'chalk-log' module Critic::Functional class LogTest < Test def enable_timestamp - configatron.chalk.log.stubs(:timestamp).returns(true) + configatron.unlock! do + configatron.chalk.log.timestamp = true + end end def disable_timestamp - configatron.chalk.log.stubs(:timestamp).returns(false) + configatron.unlock! do + configatron.chalk.log.timestamp = false + end end def disable_pid - configatron.chalk.log.stubs(:pid).returns(false) + configatron.unlock! do + configatron.chalk.log.pid = false + end end def disable_tagging - configatron.chalk.log.stubs(:tagging).returns(false) + configatron.unlock! do + configatron.chalk.log.tagging = false + end end before do Chalk::Log.init Process.stubs(:pid).returns(9973) + configatron.temp_start disable_timestamp end + after do + configatron.temp_end + end + class MyClass include Chalk::Log end describe 'when called without arguments' do @@ -131,9 +144,37 @@ disable_tagging LSpace.with(action_id: 'action') do rendered = layout(data: [{:key1 => "ValueOne", :key2 => "Value Two"}]) assert_equal(%Q{key1=ValueOne key2="Value Two"}, rendered) + end + end + + it 'logs spans correctly' do + enable_timestamp + TestSpan = Struct.new(:action_id, :span_id, :parent_id) do + def to_s + sprintf("%s %s>%s", + action_id, + parent_id.to_s(16).rjust(16,'0'), + span_id.to_s(16).rjust(16,'0')) + end + end + LSpace.with(span: TestSpan.new("action", 0, 0)) do + rendered = layout(data: ["llamas"]) + assert_equal('[1979-04-09 00:00:00.000000] [9973|action 0000000000000000>0000000000000000] llamas', rendered) + end + LSpace.with(span: TestSpan.new("action", 2, 0)) do + rendered = layout(data: ["llamas"]) + assert_equal('[1979-04-09 00:00:00.000000] [9973|action 0000000000000000>0000000000000002] llamas', rendered) + end + LSpace.with(span: TestSpan.new("action", 0, 123)) do + rendered = layout(data: ["llamas"]) + assert_equal('[1979-04-09 00:00:00.000000] [9973|action 000000000000007b>0000000000000000] llamas', rendered) + end + LSpace.with(span: TestSpan.new("action", 2, 123)) do + rendered = layout(data: ["llamas"]) + assert_equal('[1979-04-09 00:00:00.000000] [9973|action 000000000000007b>0000000000000002] llamas', rendered) end end describe 'faults' do it 'shows an appropriate error if the invalid arguments are provided' do