spec/roqua/support/logwrapper_spec.rb in roqua-support-0.1.34 vs spec/roqua/support/logwrapper_spec.rb in roqua-support-0.3.0

- old
+ new

@@ -2,11 +2,11 @@ require 'logger' require 'stringio' module Roqua describe LogWrapper do - before { Roqua.stub(appname: 'roqua-support-testsuite') } + before { allow(Roqua).to receive(:appname).and_return('roqua-support-testsuite') } let(:logstream) { StringIO.new } let(:logger) { Logger.new(logstream) } let(:logwrapper) { LogWrapper.new(logger) } @@ -15,47 +15,47 @@ end describe '#add' do it 'writes event name to log' do logwrapper.add :info, "testevent" - log.should include("testevent {}\n") + expect(log).to include("testevent {}\n") end it 'writes given parameters as json hash' do logwrapper.add :info, "testevent", extra: 'params', go: 'here' - log.should include('testevent {"extra":"params","go":"here"}' + "\n") + expect(log).to include('testevent {"extra":"params","go":"here"}' + "\n") end it 'escapes newline characters in params' do logwrapper.add :info, "testevent", param: "this\nshould not have newlines" - log.should include('testevent {"param":"this\nshould not have newlines"') + expect(log).to include('testevent {"param":"this\nshould not have newlines"') end end describe '#lifecycle' do it 'logs the start and finish lifecycle of a block' do logwrapper.lifecycle 'testevent', extra: 'params' do 1 + 1 end - log.should include('testevent:started {"extra":"params"}') - log.should match(/testevent:finished.*"extra":"params"/) + expect(log).to include('testevent:started {"extra":"params"}') + expect(log).to match(/testevent:finished.*"extra":"params"/) end it 'logs the duration of the block with the finished event' do logwrapper.lifecycle('testevent') { 1 + 1 } - log.should match(/testevent:finished.*"duration":/) + expect(log).to match(/testevent:finished.*"duration":/) end it 'returns the value returned by the block' do - logwrapper.lifecycle('testevent') { 1 + 1 }.should == 2 + expect(logwrapper.lifecycle('testevent') { 1 + 1 }).to eq 2 end it 'logs the start and failure of a block if it raises' do logwrapper.lifecycle 'testevent' do raise StandardError, "Foo" end rescue nil - log.should include('testevent:started') - log.should include('testevent:failed {"exception":"StandardError","message":"Foo"}') + expect(log).to include('testevent:started') + expect(log).to include('testevent:failed {"exception":"StandardError","message":"Foo"}') end it 'reraises the exception' do expect { logwrapper.lifecycle 'testevent' do