Skip to content

Instantly share code, notes, and snippets.

@ddavison
Created August 5, 2015 18:37
Show Gist options
  • Select an option

  • Save ddavison/b35a46980530d3e9eb2f to your computer and use it in GitHub Desktop.

Select an option

Save ddavison/b35a46980530d3e9eb2f to your computer and use it in GitHub Desktop.
require 'rails_helper'
LOG_NAME = 'spec'
LOG_FILE = "#{Rails.root}/log/spec.log"
describe 'DashboardLogger' do
let(:logger) { DashboardLogger.new LOG_NAME }
before(:each) {
begin
File.delete LOG_FILE
rescue #ignore
end
}
it 'should be able to create a log if not exists' do
logger.log 'something'
expect(File).to exist(LOG_FILE)
end
it 'should log the level correctly' do
logger.log 'info'
expect(open(LOG_FILE, 'r').readlines[0]).to include('0;')
logger.warn 'warn'
expect(open(LOG_FILE, 'r').readlines[1]).to include('1;')
logger.err 'error'
expect(open(LOG_FILE, 'r').readlines[2]).to include('2;')
end
it 'should be able to log the info correctly' do
logger.log 'the_message'
expect(open(LOG_FILE, 'r').read).to include('the_message')
end
it 'should be able to append to a log that already exists' do
open(LOG_FILE, 'w') {|f| f << 'something'}
logger.log 'else'
expect(open(LOG_FILE, 'r').read).to include('else')
end
it 'should append a log each line at a time for each write' do
logger.log 'first'
logger.err 'second'
lines = open(LOG_FILE, 'r').readlines
expect(lines[0]).to include('first')
expect(lines[1]).to include('second')
end
end
@ddavison
Copy link
Copy Markdown
Author

ddavison commented Aug 5, 2015

screen shot 2015-08-05 at 14 37 49

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment