3
votes

I'm using Prawn and Prawnto to generate PDF's in Rails 3.2.6

I have a controller that responds to a .pdf extension like so:

respond_to do |format|
  format.pdf { prawnto some_options }
end

And a test that does this:

get :pdf_route, :format => :pdf
response.header['Content-Type'].should include 'application/pdf'

The PDF rendering takes around 2-3 seconds and slows down my test suite considerably.

That said, since I don't want to test the contents of the PDF in my controller test, I would like to stub out the PDF generation entirely and just ensure that I delegate to the appropriate PDF view template using respond_to. This is the bit that I haven't been able to figure out.

Here's what I have tried so far:

format = mock("format")
format.stub(:pdf).and_return "some PDF stuff"
controller.stub(:respond_to).and_yield(format)

However that doesn't seem to help, the controller still ends up rendering the PDF. Any pointers?

1

1 Answers

1
votes

How about this?

it "generates a pdf with prawnto" do
  controller.should_receive(:prawnto)
  get :pdf_route, :format => :pdf
end