Sha256: 00d052602369fa3f424bfe3b14216341dcffa9f62c6ddcd8a0353a7aed71d02e

Contents?: true

Size: 1.72 KB

Versions: 3

Compression:

Stored size: 1.72 KB

Contents

# encoding: utf-8

require File.dirname(__FILE__) + '/spec_helper'
require 'timecop'

describe Backup::Logger do
  before do
    Timecop.freeze( Time.now )
  end

  context 'when logging regular messages' do
    it do
      Backup::Logger.expects(:puts).with("[#{ Time.now.strftime("%Y/%m/%d %H:%M:%S") }][\e[32mmessage\e[0m] This has been logged.")
      File.expects(:open).with(File.join(Backup::LOG_PATH, 'backup.log'), 'a')

      Backup::Logger.message "This has been logged."
    end
  end

  context 'when logging error messages' do
    it do
      Backup::Logger.expects(:puts).with("[#{ Time.now.strftime("%Y/%m/%d %H:%M:%S") }][\e[31merror\e[0m] This has been logged.")
      File.expects(:open).with(File.join(Backup::LOG_PATH, 'backup.log'), 'a')

      Backup::Logger.error "This has been logged."
    end
  end

  context 'when logging warn messages' do
    it do
      Backup::Logger.expects(:puts).with("[#{ Time.now.strftime("%Y/%m/%d %H:%M:%S") }][\e[33mwarning\e[0m] This has been logged.")
      File.expects(:open).with(File.join(Backup::LOG_PATH, 'backup.log'), 'a')

      Backup::Logger.warn "This has been logged."
    end
  end

  context 'when logging silent messages' do
    it do
      Backup::Logger.expects(:puts).never
      File.expects(:open).with(File.join(Backup::LOG_PATH, 'backup.log'), 'a')

      Backup::Logger.silent "This has been logged."
    end
  end

  context 'when quieted' do
    it do
      Backup::Logger.send(:const_set, :QUIET, true)
      Backup::Logger.expects(:puts).never

      Backup::Logger.message "This has been logged."
      Backup::Logger.error   "This has been logged."
      Backup::Logger.warn    "This has been logged."
      Backup::Logger.normal  "This has been logged."
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
interu-backup-3.0.16 spec/logger_spec.rb
backup-3.0.16 spec/logger_spec.rb
backup-3.0.15 spec/logger_spec.rb