Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
How To Test PDFs with Capybara Blog post with details: http://pivotallabs.com/test-pdfs-with-capybara/
group :test do
gem 'rspec-rails'
gem 'capybara'
gem 'pdf-reader'
end
require 'spec_helper'
feature 'Viewing a PDF' do
scenario 'User requests the PDF page' do
visit "/pdfs.pdf"
convert_pdf_to_page
page.should have_content("Hi, PDF!") # Passes
end
end
def convert_pdf_to_page
temp_pdf = Tempfile.new('pdf')
temp_pdf << page.source.force_encoding('UTF-8')
reader = PDF::Reader.new(temp_pdf)
pdf_text = reader.pages.map(&:text)
temp_pdf.close
page.driver.response.instance_variable_set('@body', pdf_text)
end
class PdfsController < ApplicationController
def index
respond_to do |format|
format.pdf do
render :pdf => 'filename.pdf',
:show_as_html => params[:debug]
end
end
end
end
PdfValidation::Application.routes.draw do
resources :pdfs, only: [:index]
root to: "pdfs#index"
end
%h1 Hi, PDF!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.