Sha256: b7c5002a234550b196a4eab56c439d133aac7e13600074e8f482d414d1a73559
Contents?: true
Size: 1.92 KB
Versions: 2
Compression:
Stored size: 1.92 KB
Contents
require 'rubygems' require 'log4r' require_relative '../lib/depengine/log/log' require 'stringio' describe "logging" do it "should log a message to STDOUT" do # redirect STDOUT sio = StringIO.new old_stdout, $stdout = $stdout, sio log = Log::DeploymentLogger.new log.writer.level = Log4r::DEBUG log.writer.debug "Logger is now setup" # restore STDOUT $stdout = old_stdout result = sio.string result.should include( "Logger is now setup" ) end it "should log a message to STDOUT with priority WARN" do # redirect STDOUT sio = StringIO.new old_stdout, $stdout = $stdout, sio log = Log::DeploymentLogger.new log.writer.level = Log4r::WARN log.writer.warn "Logger is now setup" # restore STDOUT $stdout = old_stdout result = sio.string result.should include( "Logger is now setup" ) end it "should log a message to a logfile" do FileUtils.rm_rf "spec/logs/log_spec.log" log = Log::DeploymentLogger.new log.add_outputter(Log4r::FileOutputter.new('log_warn', :filename => "./spec/logs/log_spec.log", :level => Log4r::INFO)) log.writer.info "Logger is now setup" File.open("spec/logs/log_spec.log", 'r') do |line| line.gets.should include("Logger is now setup") end FileUtils.rm_rf "spec/logs/log_spec.log" end it "should log a message to a logfile with a level set" do FileUtils.rm_rf "spec/logs/log_spec_level.log" log = Log::DeploymentLogger.new log.add_outputter(Log4r::FileOutputter.new('log_warn', :filename => "./spec/logs/log_spec_level.log"), Log4r::WARN) log.writer.info "this is an info message" log.writer.warn "this is a warn message" File.open("spec/logs/log_spec_level.log", 'r').read.should_not include("this is an info message") File.open("spec/logs/log_spec_level.log", 'r').read.should include("this is a warn message") FileUtils.rm_rf "spec/logs/log_spec_level.log" end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
depengine-3.0.1 | spec/log_spec.rb |
depengine-3.0.0 | spec/log_spec.rb |