Created
September 7, 2011 10:56
-
-
Save oriolgual/1200278 to your computer and use it in GitHub Desktop.
Assert the contents of a generated PDF with Capybara and Cucumber
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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