Class: Riffer::Providers::Mock
- Defined in:
- lib/riffer/providers/mock.rb
Overview
Mock provider for mocking LLM responses in tests.
No external gems required.
Constant Summary
Constants inherited from Base
Instance Attribute Summary collapse
-
#calls ⇒ Object
readonly
Array of recorded method calls for assertions.
Class Method Summary collapse
-
.skills_adapter(model = nil) ⇒ Object
Returns the preferred skill adapter for the given mock model.
Instance Method Summary collapse
-
#clear_stubs ⇒ Object
Clears all stubbed responses.
-
#initialize(**options) ⇒ Mock
constructor
Initializes the mock provider.
-
#stub_response(content, tool_calls: [], token_usage: nil) ⇒ Object
Stubs the next response from the provider.
Methods inherited from Base
Methods included from Messages::Converter
#convert_to_file_part, #convert_to_message_object
Methods included from Helpers::Dependencies
Constructor Details
#initialize(**options) ⇒ Mock
Initializes the mock provider.
responses: accepts an array of response hashes in the same shape #stub_response takes — raw tool_calls: hashes are normalised to Riffer::Messages::Assistant::ToolCall instances. This is the canonical way to pre-configure canned LLM responses on an agent via provider_options responses: […].
Riffer::Providers::Mock.new(responses: [
{content: "", tool_calls: [{name: "tool_a", arguments: "{}"}]},
{content: "Final answer"}
])
– : (**untyped) -> void
41 42 43 44 45 46 |
# File 'lib/riffer/providers/mock.rb', line 41 def initialize(**) @responses = ([:responses] || []).map { |r| normalize_response(r) } @current_index = 0 @calls = [] @stubbed_responses = [] end |
Instance Attribute Details
#calls ⇒ Object (readonly)
Array of recorded method calls for assertions.
24 25 26 |
# File 'lib/riffer/providers/mock.rb', line 24 def calls @calls end |
Class Method Details
.skills_adapter(model = nil) ⇒ Object
Returns the preferred skill adapter for the given mock model.
Mock is used to stand in for any real provider in tests, so the model string itself is the only signal we have. When the model name contains claude (e.g. mock/claude-sonnet-4-6), pick the XML adapter to mirror what a real Claude-backed provider would do; otherwise fall back to Markdown.
– : (?String?) -> singleton(Riffer::Skills::Adapter)
18 19 20 21 |
# File 'lib/riffer/providers/mock.rb', line 18 def self.skills_adapter(model = nil) return Riffer::Skills::XmlAdapter if model&.include?("claude") Riffer::Skills::MarkdownAdapter end |
Instance Method Details
#clear_stubs ⇒ Object
Clears all stubbed responses.
– : () -> void
66 67 68 |
# File 'lib/riffer/providers/mock.rb', line 66 def clear_stubs @stubbed_responses = [] end |
#stub_response(content, tool_calls: [], token_usage: nil) ⇒ Object
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::Providers::TokenUsage.new(input_tokens: 10, output_tokens: 5))
– : (String, ?tool_calls: Array[Hash[Symbol, untyped]], ?token_usage: Riffer::Providers::TokenUsage?) -> void
58 59 60 |
# File 'lib/riffer/providers/mock.rb', line 58 def stub_response(content, tool_calls: [], token_usage: nil) @stubbed_responses << normalize_response(content: content, tool_calls: tool_calls, token_usage: token_usage) end |