Sha256: 00f1978aee0d8aa32bab7074a88fbf3a3d7c395df859059fc672ec9571e0fa4d

Contents?: true

Size: 1.81 KB

Versions: 2

Compression:

Stored size: 1.81 KB

Contents

class String
  def strip_space
    gsub(/\s/, '')
  end
end

module Medivo::Spec
  def pdf_to_text(file)
    pdf = PDF::Toolkit.open(file)
    pdf.to_text.read.force_encoding('ascii-8bit')
  end

  def pdf_stream_to_text(bytes)
    pdf = Tempfile.new('pdf', :encoding => 'ascii-8bit')
    pdf.write bytes
    pdf.close
    text = pdf_to_text pdf
    pdf.unlink
    text
  end

  ##
  # For seeing the pdf yourself. writes to file so you can open it.
  # All the pdf's are created with tempfiles so you have to write to
  # a real file to see it.
  def show_me_the_pdf(pdf_file, file_name)
    # tmp files auto closed by me, so reopen again to read it
    pdf_file.open
    open(file_name, 'wb+') { |f| f.write pdf_file.read }
  end

  FIXTURE_PATH = File.expand_path('../../fixtures', __FILE__) unless defined? FIXTURE_PATH

  def medivo_fixture_path(file_name)
    "#{FIXTURE_PATH}/#{file_name}"
  end

  ##
  # requisition_id  Number  id of the Medivo::Order you are stubbing
  # file_path       String  points to the path to xml file with order info which contains
  #                         requisition that includes requisition pdf
  def stub_order_requisition(requisition_id, file_path)
    stub_request(:get, "test:test@test.medivo.com/customers/#{requisition_id}.xml?include=requisition").
            to_return(:body => File.read(medivo_fixture_path(file_path)))
  end

  ##
  # requisition_id  Number  id of the Medivo::Order you are stubbing
  # file_path       String  points to the path to xml file with order info which contains
  #                         result info that includes result pdf
  def stub_order_result(requisition_id, file_path)
    stub_request(:get, "test:test@test.medivo.com/customers/#{requisition_id}.xml?include=reconciled_results").
            to_return(:body => File.read(medivo_fixture_path(file_path)))
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
medivo-0.1.13 spec/support/helper.rb
medivo-0.1.12 spec/support/helper.rb