File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ def initialize(opts = {})
1111 end
1212
1313 def to_s
14- output = [ message ]
14+ output = [ " #{ timestamp . iso8601 ( 3 ) } #{ message } " ]
1515 if exception
1616 output . push exception . to_s
1717 output . push exception . backtrace . join ( "\n " )
Original file line number Diff line number Diff line change 7272 context 'get request' do
7373 it 'logs the request' do
7474 get '/ok' , username : 'yoshi'
75- expect ( last_log_entry ) . to eq ( "GET /ok?username=yoshi 200 in 0ms\n " )
75+ expect ( last_log_entry )
76+ . to eq ( "#{ time_anchor . iso8601 ( 3 ) } GET /ok?username=yoshi 200 in 0ms\n " )
7677 end
7778 end
7879
7980 context 'request with redirect' do
8081 it 'specifies the original path' do
8182 get '/new'
82- expect ( last_log_entry ) . to eql ( "GET /new 302 in 0ms\n " )
83+ expect ( last_log_entry ) . to eql ( "#{ time_anchor . iso8601 ( 3 ) } GET /new 302 in 0ms\n " )
8384 end
8485 end
8586
Original file line number Diff line number Diff line change 11require 'spec_helper'
22
3- RSpec . describe Loga ::Event do
3+ RSpec . describe Loga ::Event , timecop : true do
44 describe 'initialize' do
55 context 'no message is passed' do
66 it 'sets message to an empty string' do
1919 end
2020
2121 describe '#to_s' do
22- let ( :opts ) { { message : 'Hello World' } }
22+ let ( :opts ) { { message : 'Hello World' , timestamp : Time . now } }
2323 subject { described_class . new ( opts ) }
2424
2525 context 'when exception' do
2828 end
2929 let ( :opts ) { super ( ) . merge ( exception : exception ) }
3030 it 'outputs the message with exception' do
31- expect ( subject . to_s ) . to eql ( "Hello World\n Some Message\n file" )
31+ expect ( subject . to_s )
32+ . to eql ( "#{ time_anchor . iso8601 ( 3 ) } Hello World\n Some Message\n file" )
3233 end
3334 end
3435
3536 context 'when no exception' do
3637 it 'outputs the message' do
37- expect ( subject . to_s ) . to eql ( ' Hello World' )
38+ expect ( subject . to_s ) . to eql ( " #{ time_anchor . iso8601 ( 3 ) } Hello World" )
3839 end
3940 end
4041 end
4142
4243 describe '#inspect' do
43- subject { described_class . new message : 'Hey Siri' }
44+ subject { described_class . new message : 'Hey Siri' , timestamp : Time . now }
4445
4546 it 'aliases to to_s' do
4647 expect ( subject . to_s ) . to eql ( subject . inspect )
You can’t perform that action at this time.
0 commit comments