RSpec send_file testing
-
11-10-2019 - |
Question
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.
OTHER TIPS
Another way that works is:
controller.should_receive(:send_file).and_return{controller.render :nothing => true}
To me, this captures the fact that the intended side effect of send_file
is to arrange that nothing else be rendered. (Albeit, it admittedly seems a bit wonky to have the stub call a method on the original object.)
You can also do this:
result = get ....
result.body.should eq IO.binread(path_to_file)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow