It’s a bad idea to have your tests depending on external resources (rss feeds, images, etc) on a http/ftp server. What happens if for some reason the server those files are on is offline?
You could either hide the access of the files behind a service and use a mock service in your tests or overwrite the method of your object that would normally access a file (for example Channel#read_rss_feed). Under some circumstances both solutions make things just more complicated and can cause all kinds of trouble.
Assuming you use open-uri’s open method to access those files, MockOpenURI lets you mock that out:
open('http://mock/test_example.txt') acts like it would download test_example.txt from an online server now.
Using a mock domain different than the default ‘mock’:
MockOpenURI.register('http://www.foo.com/test_example.txt', :file => File.dirname(__FILE__) + '/test_example.txt')
Using a simple string:
MockOpenURI.register('test_string.txt', :string => 'foo')
Returning a specific status:
MockOpenURI.register('test_string.txt', :status => ['301', 'Moved Permanently'])
I’m sure there are quite a couple. Right now it’s a ‘good enough’-solution for us at Odeo. If you come across anything you think is missing, doesn’t work properly, etc.. please let me know.