Prawn and controller tests
- November 18th, 2009
- Posted in Gems . Ruby . Tips
- Write comment
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 solutionworkaround 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)
end
Interesting issue, but a minor correction:
I doubt this has to do with Prawn, and instead, has to do with Prawnto, which is not an official part of Prawn anyway. Prawn itself does not touch anything at all that could conflict with Rails.