module Riffer::Testing
Builds throwaway agents and tools a test suite can resolve by identifier or constant name, and removes them again. Require riffer/testing/rspec or riffer/testing/minitest to get stub_agent/stub_tool in every example plus per-test cleanup; otherwise include this module and call reset! from your own teardown, or call the methods on the module directly.
Tracking is not synchronized — stub from a single-threaded test, before concurrent lookups begin.
Public Instance Methods
Source
# File lib/riffer/testing.rb, line 59 def reset! tracked = Riffer::Testing.registrations tracked.reverse_each do |stub, const_name| registrable = stub.superclass #: untyped registrable.unregister(stub) remove_stub_const(const_name, stub) if const_name end tracked.clear end
Removes every stub built since the last reset — its registration and any constant it created — newest first, and forgets them. A no-op when nothing has been stubbed.
Source
# File lib/riffer/testing.rb, line 33 def stub_agent(name = nil, base: Riffer::Agent, &body) build_stub(name, base: base, &body) #: singleton(Riffer::Agent) end
Builds an agent class, evaluates the optional body in it, and makes it resolvable until the next reset!. A name assigns a top-level constant and derives the identifier; the body may set identifier like any other agent config.
agent = stub_agent("SupportAgent") { model "mock/gpt-5-mini" }
Raises Riffer::ArgumentError when the constant is already defined or the stub ends up with no identifier, and Riffer::DuplicateIdentifierError when another agent already holds the identifier.
Source
# File lib/riffer/testing.rb, line 50 def stub_tool(name = nil, base: Riffer::Tool, &body) build_stub(name, base: base, &body) #: singleton(Riffer::Tool) end
Builds a tool class, evaluates the optional body in it, and makes it resolvable until the next reset!. A name assigns a top-level constant and derives the identifier; the body may set identifier like any other tool config.
tool = stub_tool("KbSearch") { def call(context:, **) = text("stubbed") }
Raises Riffer::ArgumentError when the constant is already defined or the stub ends up with no identifier, and Riffer::DuplicateIdentifierError when another tool already holds the identifier.