How can I test the send_data
method in Rails?
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'
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With