Sha256: 5b605b4520af313399847b69561e77a8c62e72fae88f028faecbe20bb46a1681

Contents?: true

Size: 1.88 KB

Versions: 5

Compression:

Stored size: 1.88 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 usually are kept closed, so reopen again to read it
    pdf_file.open
    open(file_name, 'wb+') { |f| f.write pdf_file.read }
  end

  def show_me_the_pdf_stream(bytes, file_name)
    open(file_name, 'wb+') { |f| f.write bytes }
  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

5 entries across 5 versions & 1 rubygems

Version Path
medivo-0.1.24 spec/support/helper.rb
medivo-0.1.23 spec/support/helper.rb
medivo-0.1.22 spec/support/helper.rb
medivo-0.1.21 spec/support/helper.rb
medivo-0.1.20 spec/support/helper.rb