How to test pdf files

class EmployeeWriter attr_accessor :employee, :output_file def initialize(employee, output_file) @employee = employee @output_file = output_file end def export_to_pdf Prawn::Document.generate(output_file) do bounding_box([0, cursor], width: 200) do text “Name: #{}” text “Employee id: #{employee.employee_id}” text “Occupation: #{employee.occupation}” stroke_bounds end end And we have Employee class

  class Employee
    attr_accessor :name, :employee_id, :occupation
    def initialize(name, employee_id, occupation)
      @name = name
      @employee_id = employee_id
      @occupation = occupation
Now"name", "employee_id", "occupation")
will give us the following pdf Now let us write test which ensure pdf has right contents. We read the data using Pdfreader First get the pdf-reader
gem install pdf-reader -v 1.4.0
RSpec.describe EmployeeWriter do
  it "should have correct content" do
    employee ="employee_name", "employee_id", "developer"), 'employee.pdf').export_to_pdf
    reader ='employee.pdf')
    pdf_content = reader.pages[0].to_s
    expect(pdf_content).to include('Name: employee_name')
    expect(pdf_content).to include('Employee id: employee_id')
    expect(pdf_content).to include('Occupation: developer')