Module: Bidi2pdf::TestHelpers::PdfFileHelper
- Defined in:
- lib/bidi2pdf/test_helpers/pdf_file_helper.rb
Overview
This module provides helper methods for handling PDF files in tests. It includes methods for debugging, storing, and managing PDF files.
Instance Method Summary collapse
-
#store_pdf_file(pdf_data, filename_prefix = "test") ⇒ String
Stores the given PDF data to a file with a specified filename prefix.
-
#with_pdf_debug(pdf_data) {|String| ... } ⇒ Object
Executes a block with the given PDF data and handles debugging in case of test failures.
Instance Method Details
#store_pdf_file(pdf_data, filename_prefix = "test") ⇒ String
Stores the given PDF data to a file with a specified filename prefix. The file is saved in a temporary directory.
26 27 28 29 30 31 32 |
# File 'lib/bidi2pdf/test_helpers/pdf_file_helper.rb', line 26 def store_pdf_file(pdf_data, filename_prefix = "test") pdf_file = tmp_file("pdf-files", "#{filename_prefix}-#{Time.now.to_i}.pdf") FileUtils.mkdir_p(File.dirname(pdf_file)) File.binwrite(pdf_file, pdf_data) pdf_file end |
#with_pdf_debug(pdf_data) {|String| ... } ⇒ Object
Executes a block with the given PDF data and handles debugging in case of test failures. If an expectation fails, the PDF data is saved to a file for debugging purposes.
13 14 15 16 17 18 19 |
# File 'lib/bidi2pdf/test_helpers/pdf_file_helper.rb', line 13 def with_pdf_debug(pdf_data) yield pdf_data rescue RSpec::Expectations::ExpectationNotMetError => e failure_output = store_pdf_file pdf_data, "test-failure" puts "Test failed! PDF saved to: #{failure_output}" raise e end |