# Mocking file downloads

**URL:** <https://www.ruby-forum.com/t/mocking-file-downloads/186301>\
**Category:** Ruby\
**Created:** [April 4, 2010, 1:55am UTC](https://www.ruby-forum.com/t/mocking-file-downloads/186301 "2010-04-04T01:55:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_Theaker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a6a055/32.png) [@Andrew\_Theaker](https://www.ruby-forum.com/u/Andrew_Theaker)\
**Post date:** [April 4, 2010, 1:55am UTC](https://www.ruby-forum.com/t/mocking-file-downloads/186301/1 "2010-04-04T01:55:57Z")

</div>

I’m developing a data loading for work and I’m using RSpec as my testing  
framework. One feature of the tool is that it downloads any required  
data  
files that are missing from the local filesystem from a website.

I have a test case that sets up a situation where a data file is should  
be  
downloaded, but I don’t want the test to actually get the file from the  
website as the files are quite large and take a while to download,  
slowing  
down the internet connection.

I’ve started looking into options for testing this functionality without  
the  
download. My current idea is to set up a local webserver as part of the  
test, maybe using Sinatra, and point my tool at it for the downloads.  
I’m  
not sure that this feels like the best option? Is there a way to do this  
with Mock objects? Any suggestions would be very much appreciated.

This is also my first time using RSpec, so if I did go down the path of  
setting up a Sinatra webserver to download the files from, where is the  
best  
place to set it up? Should I create it in my spec file, or does it  
belong in  
the spec\_helper?

Cheers,  
Andrew Theaker

---

<div class="post-metadata">

**Author:** ![Andrew\_Theaker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a6a055/32.png) [@Andrew\_Theaker](https://www.ruby-forum.com/u/Andrew_Theaker)\
**Post date:** [April 4, 2010, 5:21am UTC](https://www.ruby-forum.com/t/mocking-file-downloads/186301/2 "2010-04-04T05:21:24Z")

</div>

On Apr 3, 2010, at 4:53 PM, Andrew Theaker wrote:

> I have a test case that sets up a situation where a data file is should be  
> downloaded, but I don’t want the test to actually get the file from the  
> website as the files are quite large and take a while to download, slowing  
> down the internet connection.

> **[GitHub - chrisk/fakeweb: Ruby test helper for injecting fake responses to web...](https://github.com/chrisk/fakeweb)**
>
> Ruby test helper for injecting fake responses to web requests - GitHub - chrisk/fakeweb: Ruby test helper for injecting fake responses to web requests

~ j.
