ruby on rails - How to test log content with RSpec? -
for example, generated log(my_work.log) content as:
i, [2015-05-14t00:00:00.000000 #5590] info -- : work started.
i want test if my_work.log has content work started.
, how do?
i don't want match line include datetime, because contains #5590
, can't stub it.
you can pass in instance of stringio when initializing logger capture output , match on expected content:
require 'logger' describe "log" let(:log) { stringio.new } let(:logger) { logger.new(log) } let(:expected) { "work started" } "should add expected content log" logger.info(expected) log.rewind expect(log.read).to match(/.+#{expected}$/) end end
Comments
Post a Comment