test/helper.rb in chupa-text-1.1.5 vs test/helper.rb in chupa-text-1.1.6
- old
+ new
@@ -1,6 +1,6 @@
-# Copyright (C) 2013-2017 Kouhei Sutou <kou@clear-code.com>
+# Copyright (C) 2013-2019 Kouhei Sutou <kou@clear-code.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
@@ -29,7 +29,37 @@
file_uri(path)
end
def file_uri(path)
URI.parse("file://#{path}")
+ end
+
+
+ class CaptureLogger
+ def initialize(output)
+ @output = output
+ end
+
+ def error(message=nil)
+ @output << [:error, message || yield]
+ end
+ end
+
+ def capture_log
+ original_logger = ChupaText.logger
+ begin
+ output = []
+ ChupaText.logger = CaptureLogger.new(output)
+ yield
+ normalize_log(output)
+ ensure
+ ChupaText.logger = original_logger
+ end
+ end
+
+ def normalize_log(log)
+ log.collect do |level, message|
+ message = message.split("\n", 2)[0]
+ [level, message]
+ end
end
end