Class: RubyLLM::Test::Harness
- Inherits:
-
Object
- Object
- RubyLLM::Test::Harness
- Defined in:
- lib/ruby_llm/test/harness.rb
Overview
This class serves as a test harness for stubbing responses and recording requests sent to the provider. It allows tests to set up expected responses and then verify that the provider received the correct parameters.
Instance Attribute Summary collapse
-
#requests ⇒ Object
readonly
Returns the value of attribute requests.
Instance Method Summary collapse
- #clear_requests ⇒ Object
-
#initialize ⇒ Harness
constructor
A new instance of Harness.
- #last_request ⇒ Object
- #next_response ⇒ Object
- #record_request(request) ⇒ Object
- #reset ⇒ Object
- #responses_empty? ⇒ Boolean
-
#stub_response(body) ⇒ Object
Pass in a RubyLLM::Message to have full control; strings and hashes will be wrapped in a message.
- #stub_responses(*bodies) ⇒ Object
- #with_responses(*bodies) ⇒ Object
Constructor Details
#initialize ⇒ Harness
Returns a new instance of Harness.
11 12 13 |
# File 'lib/ruby_llm/test/harness.rb', line 11 def initialize reset end |
Instance Attribute Details
#requests ⇒ Object (readonly)
Returns the value of attribute requests.
9 10 11 |
# File 'lib/ruby_llm/test/harness.rb', line 9 def requests @requests end |
Instance Method Details
#clear_requests ⇒ Object
49 50 51 |
# File 'lib/ruby_llm/test/harness.rb', line 49 def clear_requests requests.clear end |
#last_request ⇒ Object
45 46 47 |
# File 'lib/ruby_llm/test/harness.rb', line 45 def last_request requests.last end |
#next_response ⇒ Object
33 34 35 |
# File 'lib/ruby_llm/test/harness.rb', line 33 def next_response responses.shift end |
#record_request(request) ⇒ Object
41 42 43 |
# File 'lib/ruby_llm/test/harness.rb', line 41 def record_request(request) requests << request end |
#reset ⇒ Object
53 54 55 56 |
# File 'lib/ruby_llm/test/harness.rb', line 53 def reset @responses = [] @requests = [] end |
#responses_empty? ⇒ Boolean
37 38 39 |
# File 'lib/ruby_llm/test/harness.rb', line 37 def responses_empty? responses.empty? end |
#stub_response(body) ⇒ Object
Pass in a RubyLLM::Message to have full control; strings and hashes will be wrapped in a message
16 17 18 |
# File 'lib/ruby_llm/test/harness.rb', line 16 def stub_response(body) responses << body end |
#stub_responses(*bodies) ⇒ Object
20 21 22 |
# File 'lib/ruby_llm/test/harness.rb', line 20 def stub_responses(*bodies) responses.concat(bodies) end |
#with_responses(*bodies) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/ruby_llm/test/harness.rb', line 24 def with_responses(*bodies) previous_responses = responses.dup @responses = [] stub_responses(*bodies) yield ensure @responses = previous_responses end |