Class: Riffer::Providers::Test
- Defined in:
- lib/riffer/providers/test.rb
Overview
Test provider for mocking LLM responses in tests.
No external gems required.
Instance Attribute Summary collapse
-
#calls ⇒ Object
readonly
Array of recorded method calls for assertions.
Instance Method Summary collapse
-
#clear_stubs ⇒ Object
Clears all stubbed responses.
-
#initialize(**options) ⇒ Test
constructor
Initializes the test provider.
-
#stub_response(content, tool_calls: []) ⇒ Object
Stubs the next response from the provider.
Methods inherited from Base
Methods included from Messages::Converter
Constructor Details
#initialize(**options) ⇒ Test
Initializes the test provider.
- options
-
Hash - optional configuration
Use :responses to pre-configure responses.
17 18 19 20 21 22 |
# File 'lib/riffer/providers/test.rb', line 17 def initialize(**) @responses = [:responses] || [] @current_index = 0 @calls = [] @stubbed_responses = [] end |
Instance Attribute Details
#calls ⇒ Object (readonly)
Array of recorded method calls for assertions.
Returns Array of Hash.
10 11 12 |
# File 'lib/riffer/providers/test.rb', line 10 def calls @calls end |
Instance Method Details
#clear_stubs ⇒ Object
Clears all stubbed responses.
Returns void.
52 53 54 |
# File 'lib/riffer/providers/test.rb', line 52 def clear_stubs @stubbed_responses = [] end |
#stub_response(content, tool_calls: []) ⇒ Object
Stubs the next response from the provider.
Can be called multiple times to queue responses.
- content
-
String - the response content
- tool_calls
-
Array of Hash - optional tool calls to include
Returns void.
provider.stub_response("Hello")
provider.stub_response("", tool_calls: [{name: "my_tool", arguments: '{"key":"value"}'}])
provider.stub_response("Final response")
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/riffer/providers/test.rb', line 37 def stub_response(content, tool_calls: []) formatted_tool_calls = tool_calls.map.with_index do |tc, idx| { id: tc[:id] || "test_id_#{idx}", call_id: tc[:call_id] || tc[:id] || "test_call_#{idx}", name: tc[:name], arguments: tc[:arguments].is_a?(String) ? tc[:arguments] : tc[:arguments].to_json } end @stubbed_responses << {role: "assistant", content: content, tool_calls: formatted_tool_calls} end |