Skip to content

Instantly share code, notes, and snippets.

@oriolgual
Created September 7, 2011 10:56
Show Gist options
  • Save oriolgual/1200278 to your computer and use it in GitHub Desktop.
Save oriolgual/1200278 to your computer and use it in GitHub Desktop.
Assert the contents of a generated PDF with Capybara and Cucumber
# Dependencies: pdftotext (included in xpdf)
# OSX: brew install xpdf
# Ubuntu/Debian: apt-get install xpdf
Then /^I should have get a pdf with the business name$/ do
page.response_headers['Content-Type'].should include 'application/pdf'
pdf_to_text.should include @current_business.name
end
def pdf_to_text
begin
require 'tempfile'
pdf = Tempfile.new('pdf')
pdf.write(page.source.force_encoding('utf-8'))
return `pdftotext #{pdf.path} -`
ensure
pdf.close
pdf.unlink
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment