Sha256: 0e17d624a9d3ea84852ffd05fa12c79f4931a0d6c956b643af5cff672a220b00

Contents?: true

Size: 1.78 KB

Versions: 2

Compression:

Stored size: 1.78 KB

Contents

class String
  def strip_space
    gsub(/\s|\n|\r/, '')
  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(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(file_path))
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
medivo-0.1.19 spec/support/helper.rb
medivo-0.1.18 spec/support/helper.rb