RSpec send_file testing

Mirko picture Mirko · Jan 15, 2011 · Viewed 10.8k times · Source

How to test a controller action that sends a file?

If I do it with controller.should_receive(:send_file) test fails with "Missing template" because nothing gets rendered.

Answer

Andy Lindeman picture Andy Lindeman · Jan 15, 2011

From Googling around, it appears that render will also be called at some point .. but with no template, will cause an error.

The solution seems to be to stub it out as well:

controller.stub!(:render)