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
-
#connect_to_ollama_server(instantiate: true) ⇒ Object
The connect_to_ollama_server method establishes a connection to an Ollama server.
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.
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'spec/spec_helper.rb', line 184 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')) stub_request(:get, %r(/api/ps\z)). to_return(status: 200, body: asset_json('api_ps.json')) allow_any_instance_of(OllamaChat::Chat).to receive(:connect_message) allow_any_instance_of(OllamaChat::Chat).to receive(:connect_message_done) allow_any_instance_of(OllamaChat::Chat).to receive(:info_session) instantiate and chat end end |