Class: Engram::Adapters::FakeCompletion
- Inherits:
-
Object
- Object
- Engram::Adapters::FakeCompletion
- Includes:
- Ports::Completion
- Defined in:
- lib/engram/adapters/fake_completion.rb
Overview
Deterministic Completion for tests. Returns queued responses (already-parsed Hashes) in order, and records every call so specs can assert on the prompts/schemas sent.
Instance Attribute Summary collapse
-
#calls ⇒ Object
readonly
Returns the value of attribute calls.
Instance Method Summary collapse
- #complete(system:, user:, schema:) ⇒ Object
- #enqueue(response) ⇒ Object
-
#initialize(responses: []) ⇒ FakeCompletion
constructor
A new instance of FakeCompletion.
Constructor Details
#initialize(responses: []) ⇒ FakeCompletion
Returns a new instance of FakeCompletion.
12 13 14 15 |
# File 'lib/engram/adapters/fake_completion.rb', line 12 def initialize(responses: []) @responses = responses.dup @calls = [] end |
Instance Attribute Details
#calls ⇒ Object (readonly)
Returns the value of attribute calls.
10 11 12 |
# File 'lib/engram/adapters/fake_completion.rb', line 10 def calls @calls end |
Instance Method Details
#complete(system:, user:, schema:) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/engram/adapters/fake_completion.rb', line 22 def complete(system:, user:, schema:) @calls << {system: system, user: user, schema: schema} if @responses.empty? raise Engram::Error, "FakeCompletion: no scripted response left (call ##{@calls.size})" end @responses.shift end |
#enqueue(response) ⇒ Object
17 18 19 20 |
# File 'lib/engram/adapters/fake_completion.rb', line 17 def enqueue(response) @responses << response self end |