Adventures with Ruby

Prawn and controller tests

View Comments

prawn_logoThere 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 solutionworkaround is to set the server protocol, like this:

[sourcecode language=ruby]
it “should show the pdf” do
request.env["SERVER_PROTOCOL"] = “http”
get :show, :id => “report”, “format” => “pdf”
response.should render_template(:show)
end
[/sourcecode]

Written by Iain Hecker

November 18th, 2009 at 10:33 am

Posted in Uncategorized

blog comments powered by Disqus