class Riffer::Providers::Mock
Mock provider for mocking LLM responses in tests.
No external gems required.
Attributes
Array of recorded method calls for assertions.
Public Class Methods
Source
# File lib/riffer/providers/mock.rb, line 14 def initialize(**options) @responses = options[:responses] || [] @current_index = 0 @calls = [] @stubbed_responses = [] end
Initializes the mock provider.
: (**untyped) -> void
Public Instance Methods
Source
# File lib/riffer/providers/mock.rb, line 45 def clear_stubs @stubbed_responses = [] end
Clears all stubbed responses.
: () -> void
Source
# File lib/riffer/providers/mock.rb, line 30 def stub_response(content, tool_calls: [], token_usage: nil) formatted_tool_calls = tool_calls.map.with_index do |tc, idx| Riffer::Messages::Assistant::ToolCall.new( id: tc[:id] || "mock_id_#{idx}", call_id: tc[:call_id] || tc[:id] || "mock_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, token_usage: token_usage} end
Stubs the next response from the provider.
Can be called multiple times to queue responses.
provider.stub_response(“Hello”) provider.stub_response(“”, tool_calls: [{name: “my_tool”, arguments: ‘{“key”:“value”}’}]) provider.stub_response(“Final response”, token_usage: Riffer::TokenUsage.new(input_tokens: 10, output_tokens: 5))
: (String, ?tool_calls: Array[Hash[Symbol, untyped]], ?token_usage: Riffer::TokenUsage?) -> void