I have this code in my controller which streams a file to the client. How on earth do I test this? #Stream the file to the client over HTTP def preview device_id=params[:device_id] path = @campaign.get_preview_url(device_id) #THE CONTENT TYPE IS REQUIRED! ext=File.extname(file_name) if ext == ".3gp" m_type="video/3gpp" elsif ext == ".3g2" m_type="video/3gpp2" elsif ext ==".mp4" m_type="video/mp4" end send_file path, :disposition => ''inline'', :type => m_type end --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
-----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of eggie5> I have this code in my controller which streams a file to the client.How on earth do I test this? #Stream the file to the client over HTTP def preview device_id=params[:device_id] path = @campaign.get_preview_url(device_id) #THE CONTENT TYPE IS REQUIRED! ext=File.extname(file_name) if ext == ".3gp" m_type="video/3gpp" elsif ext == ".3g2" m_type="video/3gpp2" elsif ext ==".mp4" m_type="video/mp4" end send_file path, :disposition => ''inline'', :type => m_type end < I''m too new to Ruby on Rails to be more specific, but the general way to handle things like this is to "mock out" the call to send_file. Then, send_file can be made to simply record how it was called, instead of actually sending a file across the wire. You then test that it was called correctly - without caring about what it actually does. The reason you don''t care is that it''s not your code. All you care about is that you called it with the right arguments at the right time. ///ark --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hye Eggie, what''s that @campaign object contain?, if it''s your server, then you have to just write one mock server, and i am assuming this code is in some controller., def test_preview_for_3gp get :preview, :device_id => test_device # send what ever you want. assert_response :success assert_not_nil @response.headers["Content-Type"].index(''video/ 3gpp'') # write different set of Functional TestCases for your if/else ladder. expected_file_name = "/tmp/test.3gpp" assert_equal expected_file_name, assigns(:path) # i just assumed the path variable can be made instance variable. assert_not_nil @response assert_kind_of String, @response.body # i don''t know what put in place of String here, if you do some google you may get some idea. Sorry, here end and one more thing is you can add some more assertions provided if you know what''s the 3gp format, so if you want your FT''s(Functional-Test- Cases) to cover even the content delivered, then you have to parse the 3gp file(or find any equivalent Ruby class, [i don''t know any such class]) and write assertions for response.body to contain like header, tags etc. of 3gp format. I guess it helps you, sorry if not. Good Luck, On Oct 8, 1:41 am, eggie5 <egg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have this code in my controller which streams a file to the client. > How on earth do I test this? > > #Stream the file to the client over HTTP > def preview > device_id=params[:device_id] > > path = @campaign.get_preview_url(device_id) > > #THE CONTENT TYPE IS REQUIRED! > ext=File.extname(file_name) > > if ext == ".3gp" > m_type="video/3gpp" > elsif ext == ".3g2" > m_type="video/3gpp2" > elsif ext ==".mp4" > m_type="video/mp4" > end > > send_file path, :disposition => ''inline'', :type => m_type > end--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---