1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
require 'test_helper'
# Define a custom outputter that allows arrays in configuration hash
module Log4r
class TestYamlOutputter < Outputter
# expose array parameter
attr_reader :array_param
def initialize(name, hash = {})
@array_param = hash['array_param']
end
end
end
class TestYaml < TestCase
include Log4r
def setup
@cfg = YamlConfigurator # shorthand
@cfg['CUSTOM_DOMAIN'] = 'bar.com'
end
def test_injection
assert_nothing_raised("Exception injected") do
@cfg.load_yaml_file(File.join(File.dirname(__FILE__),'testyaml_injection.yaml'))
end
end
def test_arrays
assert_nothing_raised("Parser couldn't handle arrays in YAML") do
@cfg.load_yaml_file(File.join(File.dirname(__FILE__),'testyaml_arrays.yaml'))
end
log = Logger['mylogger']
assert_instance_of(Array, log.outputters.first.array_param, 'Array not loaded properly from YAML')
assert_equal('wilma@bar.com', log.outputters.first.array_param[2], '#{}-style parameter interpolation doesn\'t work properly in arrays')
end
end
|