Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How test the send_data method in Rails?

How can I test the send_data method in Rails?

like image 311
Pavel Druzyak Avatar asked Jun 17 '10 16:06

Pavel Druzyak


2 Answers

First of all look at the source of the send_data method http://api.rubyonrails.org/classes/ActionController/DataStreaming.html#method-i-send_data

According to that, send_data simply put everything to render :text => '...' with additional options.

I think you can do it in this way:

response.body.should eql data
response.header['Content-Type'].should eql 'image/png'
like image 189
Artur Małecki Avatar answered Oct 08 '22 03:10

Artur Małecki


You shouldn't need to test the behaviour of send_data itself, mainly because that's covered by Rails' own tests. Also, it will make your tests run slowly (eventually). What you should do (from my perspective) is to stub the send_data method, something like:

controller.expects(:send_data).with("foo").returns(:success)

Hope it helps.

like image 41
jpemberthy Avatar answered Oct 08 '22 04:10

jpemberthy