[rspec-users] specing send_file

Stephen Eley
Mon, 23 Feb 2009 16:30:37 -0000

On Fri, Feb 20, 2009 at 5:45 PM, vo.x <v.ondruch at gmail.com>
wrote:
> Hello everybody!
>
> Im wondering what is the best way of specing action with send file
> such as:

I''d probably do it on two fronts.  On the unit test level, you can
stub it in your setup so that it won''t try to send that file every
time you run tests, then mock it in one particular spec with
"[yourcontroller].should_receive(:send_file).with([your params])" to
make sure it''s getting called with the right values.

In your integration tests (with RSpec or Cucumber or Selenium or
trained gerbils or whatever), have it actually send the file.  Then,
if you''re using RSpec or Cucumber with Webrat, you can check the
response object to make sure it has the right length, the right
content-type, and if you want to be thorough, do a checksum on the
body to make sure the right stuff was sent.

If you''re using Selenium, life''s even better: you can look to
make
sure that the file showed up in your Downloads directory (set your
browser to not prompt you on that file type first) and checksum the
actual file as it was actually saved.

Does that make sense?



--
Have Fun,
   Steve Eley (sfeley at gmail.com)
   ESCAPE POD - The Science Fiction Podcast Magazine