I’m trying to test some code that I’ve written to respond to the onopen, onmessage, and onclose events that can be registered via EventMachine::WebSocket, and I’m curious to know if there are any utilities that could help mock out some of the EventMachine functionality for unit tests. Links to example em-websocket tests would be greatly appreciated; I’ve looked all over to find example tests, but to no avail.
I’m trying to test some code that I’ve written to respond to the onopen
Share
Have you tried to mock the
Websocket::Connectioninstance yourself? I would start by setting up a an object with asendmethod?For example:
then create an instance of that to represent the typical
wsinstance used in the em-websocket documentation. Theonmessageis the only event which passes an argument, which is a string, so there’s not much need to mock much else for these events. I would start with this base object and mock more methods as needed.Here’s an example of a EM-Websocket mock from Socky.