Module: StubOllamaServer

Defined in:
spec/spec_helper.rb

Overview

A module that provides functionality for stubbing Ollama server responses.

The StubOllamaServer module enables developers to simulate Ollama API interactions in test environments by intercepting requests and returning predefined responses. This allows for faster, more reliable testing without requiring external service calls.

Instance Method Summary collapse

Instance Method Details

#connect_to_ollama_server(instantiate: true) ⇒ Object

The connect_to_ollama_server method establishes a connection to an Ollama server.

This method sets up stubbed HTTP requests to simulate responses from an Ollama server, including API tags, show, and version endpoints. It can optionally instantiate a chat session after setting up the stubs.

Parameters:

  • instantiate (true, false) (defaults to: true)

    whether to instantiate a chat session after setting up stubs



152
153
154
155
156
157
158
159
160
161
162
163
# File 'spec/spec_helper.rb', line 152

def connect_to_ollama_server(instantiate: true)
  before do
    stub_request(:get, %r(/api/tags\z)).
      to_return(status: 200, body: asset_json('api_tags.json'))
    stub_request(:post, %r(/api/show\z)).
      to_return(status: 200, body: asset_json('api_show.json'))
    stub_request(:get, %r(/api/version\z)).
      to_return(status: 200, body: asset_json('api_version.json'))
    allow_any_instance_of(OllamaChat::Chat).to receive(:connect_message)
    instantiate and chat
  end
end