Module: RubyLLM::Tester

Defined in:
lib/ruby_llm/tester.rb

Overview

Testing with RubyLLM::Tester

For tests, require ruby_llm/tester to switch to an in-memory provider. It behaves like Mail::TestMailer by collecting prompt interactions in an array:

require "ruby_llm/tester"

RubyLLM::Tester.interactions.clear

RubyLLM.chat.say "Hello!"

RubyLLM::Tester.interactions.size         # => 1
RubyLLM::Tester.interactions.last.role    # => :user
RubyLLM::Tester.interactions.last.content # => "Hello!"

The test provider uses an echo model and returns the prompt content back as the assistant response, so assertions stay deterministic and offline.

Class Method Summary collapse

Class Method Details

.register(*messages) ⇒ Object



26
27
28
# File 'lib/ruby_llm/tester.rb', line 26

def self.register *messages
  interactions.concat messages.flatten
end