test/writer_test.rb in slim2pdf-0.0.1 vs test/writer_test.rb in slim2pdf-0.0.2

- old
+ new

@@ -1,6 +1,8 @@ require 'test_helper' +require 'logger' +require 'stringio' module Slim2pdf class WriterTest < MiniTest::Unit::TestCase def setup @data = {title: 'Slim2pdf', content: 'Slim to PDF conversion gem'} @@ -57,19 +59,47 @@ assert File.exists?(path) File.unlink(path) assert_equal false, File.exists?(path) end + def test_wkhtmltopdf_command + assert_match /wkhtmltopdf/, @writer.wkhtmltopdf_command + assert_match /-q/, @writer.wkhtmltopdf_command + @writer.wkhtmltopdf_command = 'test -a -b -c' + assert_equal 'test -a -b -c', @writer.wkhtmltopdf_command + end + def test_footer_params @writer.footer_text = 'Footer' - command = @writer.wkhtmltopdf_command('tmp.html', 'out.pdf') + command = @writer.wkhtmltopdf_command assert_match /Footer/, command assert_match /10/, command assert_match /verdana/, command @writer.footer_font = 'arial' @writer.footer_font_size = 14 - command = @writer.wkhtmltopdf_command('tmp.html', 'out.pdf') + command = @writer.wkhtmltopdf_command assert_match /14/, command assert_match /arial/, command + end + + def test_logger_accessor + assert_nil @writer.logger + stderr = Logger.new(STDERR) + @writer.logger = stderr + assert_equal stderr, @writer.logger + end + + def test_logging + sio = StringIO.new + @writer.logger = Logger.new(sio) + @writer.logger.level = Logger::DEBUG + @writer.save_to_html('/tmp/out.html') + File.unlink('/tmp/out.html') + @writer.save_to_pdf('/tmp/out.pdf') + File.unlink('/tmp/out.pdf') + log = sio.string + assert_match %r(/tmp/out.html), log + assert_match %r(/tmp/out.pdf), log + assert_match /Run command: wkhtmltopdf/, log end end end