Created
August 5, 2015 18:37
-
-
Save ddavison/b35a46980530d3e9eb2f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Author
ddavison
commented
Aug 5, 2015

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