A quick workaround for testing controller actions that render a PDF with Prawn

This article is deprecated.I've marked this article as deprecated. It is either because the gem or plugin discussed in this article is no longer maintained, or I've changed my opinion on it. This article is here only as an historic reference.

Prawn and controller tests

There is a real annoying gotcha in using controller tests to test an action that renders a pdf with Prawn. You'll get a NoMethodException on "nil.downcase". The troubling part is that it totally puts you off by providing the wrong lines and backtrace.

This has been mentioned somewhere on some mailinglists, but to make it a bit more findable, I'd thought I'd post it here.

The solution workaround is to set the server protocol, like this:

it "should show the pdf" do
  request.env["SERVER_PROTOCOL"] = "http"
  get :show, :id => "report", "format" => "pdf"
  response.should render_template(:show)
comments powered byDisqus