|
2 | 2 |
|
3 | 3 | RSpec.describe Mars::Agent do |
4 | 4 | describe "#run" do |
| 5 | + subject(:run_agent) { agent.run("input text") } |
| 6 | + |
5 | 7 | let(:agent) { described_class.new(name: "TestAgent", options: { model: "test-model" }) } |
6 | 8 | let(:mock_chat_instance) do |
7 | 9 | instance_double("RubyLLM::Chat").tap do |mock| |
8 | | - allow(mock).to receive_messages(with_tools: mock, with_schema: mock, ask: nil) |
| 10 | + allow(mock).to receive_messages(with_tools: mock, with_schema: mock, with_instructions: mock, |
| 11 | + ask: mock_chat_response) |
9 | 12 | end |
10 | 13 | end |
| 14 | + let(:mock_chat_response) { instance_double("RubyLLM::Message", content: "response text") } |
11 | 15 | let(:mock_chat_class) { class_double("RubyLLM::Chat", new: mock_chat_instance) } |
12 | 16 |
|
13 | 17 | before do |
14 | 18 | stub_const("RubyLLM::Chat", mock_chat_class) |
15 | 19 | end |
16 | 20 |
|
17 | 21 | it "initializes RubyLLM::Chat with provided options" do |
18 | | - agent.run("test input") |
| 22 | + run_agent |
19 | 23 |
|
20 | 24 | expect(mock_chat_class).to have_received(:new).with(model: "test-model") |
21 | 25 | end |
22 | 26 |
|
23 | | - it "configures chat with tools if provided" do |
24 | | - tools = [proc { "tool" }] |
25 | | - agent_with_tools = described_class.new(name: "TestAgent", tools: tools) |
26 | | - agent_with_tools.run("test input") |
| 27 | + context "when tools are provided" do |
| 28 | + let(:tools) { [proc { "tool1" }, proc { "tool2" }] } |
| 29 | + let(:agent) { described_class.new(name: "TestAgent", tools: tools) } |
| 30 | + |
| 31 | + it "configures chat with tools" do |
| 32 | + run_agent |
27 | 33 |
|
28 | | - expect(mock_chat_instance).to have_received(:with_tools).with(tools) |
| 34 | + expect(mock_chat_instance).to have_received(:with_tools).with(*tools) |
| 35 | + end |
29 | 36 | end |
30 | 37 |
|
31 | | - it "configures chat with schema if provided" do |
32 | | - schema = { type: "object" } |
33 | | - agent_with_schema = described_class.new(name: "TestAgent", schema: schema) |
| 38 | + context "when schema is provided" do |
| 39 | + let(:schema) { { type: "object" } } |
| 40 | + let(:agent) { described_class.new(name: "TestAgent", schema: schema) } |
34 | 41 |
|
35 | | - agent_with_schema.run("test input") |
36 | | - expect(mock_chat_instance).to have_received(:with_schema).with(schema) |
| 42 | + it "configures chat with schema" do |
| 43 | + run_agent |
| 44 | + |
| 45 | + expect(mock_chat_instance).to have_received(:with_schema).with(schema) |
| 46 | + end |
37 | 47 | end |
38 | 48 | end |
39 | 49 | end |
0 commit comments