I've yet to find something that fills this hole in my test cases.
Does anyone do this, and if so, what tools do they use?
I do some of this with custom stubs in memcache-client, see below. I've
also simulated call failures (Errno::whatever) with slightly more
powerful stubs that can take a block to raise the exception.
Here's a fake socket:
class FakeSocket
attr_reader :written, :data
def initialize
@written = StringIO.new
@data = StringIO.new
end
def write(data)
@written.write data
end
def gets
@data.gets
end
def read(arg)
@data.read arg
end
end
And here's a test using it:
def test_flush_all_failure
socket = FakeSocket.new
socket.data.write "ERROR\r\n"
socket.data.rewind
server = FakeServer.new socket
def server.host() "localhost"; end
def server.port() 11211; end
@cache.servers = []
@cache.servers << server
assert_raise MemCache::MemCacheError do
@cache.flush_all
end
assert_equal "flush_all\r\n", socket.written.string
end