Ruby on Rails: test logs output presence within Rails.logger (through Minitest too)
require 'test_helper'
class MyTest < ActionDispatch::IntegrationTest
def with_logger_introspection(&block)
orig_logger = Rails.logger.dup
@logger_output = StringIO.new
begin
Rails.logger = ActiveSupport::Logger.new(@logger_output)
block.call(@logger_output)
ensure
Rails.logger = orig_logger
end
end
test "Something is logged" do
with_logger_introspection do |logger_output|
# do something
assert logger_output.string.include? "Something"
end
end
end
Written by coconup
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#