async-matrixSourcetestdescribe

describe

Nested

Definitions

StubDiscordClient

Stub client that records calls instead of making HTTP requests.

Implementation

StubDiscordClient = Struct.new(:calls) do
  def initialize
    super([])
  end

  def get(path, max_retries: nil)
    calls << [:get, path, {max_retries: max_retries}]
    {"stub" => true}
  end

  def post(path, body = {}, max_retries: nil)
    calls << [:post, path, body, {max_retries: max_retries}]
    {"stub" => true}
  end

  def put(path, body = {}, max_retries: nil)
    calls << [:put, path, body, {max_retries: max_retries}]
    {"stub" => true}
  end

  def request(method, path, body = nil, max_retries: nil)
    calls << [method.downcase.to_sym, path, body, {max_retries: max_retries}]
    {"stub" => true}
  end

  # Chain checks for media_client on binary routes; Discord doesn't need it
  # but we provide a stub to avoid NoMethodError.
  def media_client
    nil
  end
end

StubResponse

Stub response object for download tests.

Implementation

StubResponse = Struct.new(:body_bytes, :headers, :status) do
  def initialize(body_bytes = "\xFF\xD8\xFF".b)
    super(body_bytes, {"content-type" => "image/jpeg"}, 200)
  end

  def read
    body_bytes
  end
end

StubMediaClient

Stub client with a stub media_client for testing dispatch.

Implementation

StubMediaClient = Struct.new(:calls) do
  def initialize
    super([])
  end

  def upload(method, path, body, content_type)
    calls << [:upload, method, path, body, content_type]
    {"content_uri" => "mxc://example.com/abc123"}
  end

  def download(path)
    calls << [:download, path]
    StubResponse.new
  end
end

StubClient

Stub client that records calls instead of making HTTP requests.

Implementation

StubClient = Struct.new(:calls) do
  def initialize
    super([])
  end

  def get(path, max_retries: nil)
    calls << [:get, path, {max_retries: max_retries}]
    {"stub" => true}
  end

  def post(path, body = {}, max_retries: nil)
    calls << [:post, path, body, {max_retries: max_retries}]
    {"stub" => true}
  end

  def put(path, body = {}, max_retries: nil)
    calls << [:put, path, body, {max_retries: max_retries}]
    {"stub" => true}
  end

  def request(method, path, body = nil, max_retries: nil)
    calls << [method.downcase.to_sym, path, body, {max_retries: max_retries}]
    {"stub" => true}
  end
end