module Amber::Testing::WebSocketHelpers

Overview

Provides helpers for testing WebSocket channels.

describe "ChatChannel" do
  include Amber::Testing::WebSocketHelpers

  it "handles messages" do
    test_socket = create_test_socket("/chat")
    test_socket.send({"event" => "join", "topic" => "chat:lobby"}.to_json)
    test_socket.close
  end
end

Defined in:

amber/testing/websocket_helpers.cr

Instance Method Summary

Instance Method Detail

def create_test_socket(path : String) : TestWebSocket #

Create a test WebSocket connection to the given path. This starts a minimal HTTP server on an unused port, connects a WebSocket client, and returns a TestWebSocket for interaction.


[View source]