How can I test pdf generation in Rails using Cucumber/Rspec + Prawn + Prawnto?

1,370 views
Skip to first unread message

Cássio Marques

unread,
Feb 4, 2010, 11:10:29 AM2/4/10
to Prawn
Hi everyone!

I'm using Prawn + Prawnto in my Rails application to generate pdfs. I
would like to know how could I test it using Cucumber (assert that the
pdf was generated and sent to the browser) and how could I test the
pdf contents with Rspec. Has anyone tried this?

Thanks!

Daniel Nelson

unread,
Feb 4, 2010, 11:36:49 AM2/4/10
to prawn...@googlegroups.com
Hello Cássio,

To check in Cucumber, you could have a line like "Then I should see "%PDF-1.3".

One possibility for testing content of the PDF would be to use
pdf-inspector, just like Prawn does in its specs.

Cheers,

Daniel

Cássio Marques

unread,
Feb 4, 2010, 11:44:56 AM2/4/10
to prawn...@googlegroups.com
Hum... the approach for Cucumber seems very obvious... but I didn't think of that. Thanks!

For the rspec part, I'm just wondering how to intercept the pdf generated by prawnto, since it sends it directly to the browser. I don't  know where I can have access to it when it's generated. Maybe in a controller test through response.body?

Thanks!


--
You received this message because you are subscribed to the Google Groups "Prawn" group.
To post to this group, send email to prawn...@googlegroups.com.
To unsubscribe from this group, send email to prawn-ruby+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/prawn-ruby?hl=en.




--
Cássio Marques

Blog: http://cassiomarques.wordpress.com

If you're writing code and you're not testing it, the code is wrong. I don't care if it does the right thing, and people need to understand this. If it works by accident, you're still wrong.
Bryan Liles - Ruby Hoedown 2008

Gregory Brown

unread,
Feb 4, 2010, 12:19:35 PM2/4/10
to prawn...@googlegroups.com
2010/2/4 Cássio Marques <cass...@gmail.com>:

> Hum... the approach for Cucumber seems very obvious... but I didn't think of
> that. Thanks!
> For the rspec part, I'm just wondering how to intercept the pdf generated by
> prawnto, since it sends it directly to the browser. I don't  know where I
> can have access to it when it's generated. Maybe in a controller test
> through response.body?

Though not an answer to your question, you could avoid using Prawnto,
and that would solve the problem :)
http://wiki.github.com/sandal/prawn/using-prawn-in-rails

Daniel Nelson

unread,
Feb 4, 2010, 12:20:11 PM2/4/10
to prawn...@googlegroups.com
Since PDF output is a view, I wouldn't test it with a controller spec.
I use Cucumber for all of my view checks. You could build a custom
step that analyzes the returned content.

-Daniel

Cássio Marques

unread,
Feb 4, 2010, 12:26:42 PM2/4/10
to prawn...@googlegroups.com
Hum... yes, in fact Cucumber would be better for this.

Thanks everyone!

--
You received this message because you are subscribed to the Google Groups "Prawn" group.
To post to this group, send email to prawn...@googlegroups.com.
To unsubscribe from this group, send email to prawn-ruby+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/prawn-ruby?hl=en.

Reply all
Reply to author
Forward
0 new messages