Skip to content

Commit 34126cb

Browse files
committed
update agent_spec
1 parent d46aaf0 commit 34126cb

File tree

2 files changed

+24
-71
lines changed

2 files changed

+24
-71
lines changed

.rubocop.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ Style/StringLiterals:
1818
Style/StringLiteralsInInterpolation:
1919
EnforcedStyle: double_quotes
2020

21-
RSpec/MultipleExpectations:
21+
RSpec/ExampleLength:
2222
Enabled: false
2323

24-
RSpec/ExampleLength:
24+
RSpec/MultipleExpectations:
2525
Enabled: false
2626

2727
RSpec/VerifiedDoubleReference:

spec/mars/agent_spec.rb

Lines changed: 22 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,39 @@
11
# frozen_string_literal: true
22

33
RSpec.describe Mars::Agent do
4-
describe "#initialize" do
5-
it "initializes with a name" do
6-
agent = described_class.new(name: "TestAgent")
7-
expect(agent.name).to eq("TestAgent")
4+
describe "#run" do
5+
let(:agent) { described_class.new(name: "TestAgent", options: { model: "test-model" }) }
6+
let(:mock_chat_instance) do
7+
instance_double("RubyLLM::Chat").tap do |mock|
8+
allow(mock).to receive_messages(with_tools: mock, with_schema: mock, ask: nil)
9+
end
810
end
11+
let(:mock_chat_class) { class_double("RubyLLM::Chat", new: mock_chat_instance) }
912

10-
it "accepts options parameter" do
11-
options = { model: "gpt-4", temperature: 0.7 }
12-
agent = described_class.new(name: "TestAgent", options: options)
13-
expect(agent.name).to eq("TestAgent")
13+
before do
14+
stub_const("RubyLLM::Chat", mock_chat_class)
1415
end
1516

16-
it "accepts tools parameter as an array" do
17-
tool1 = instance_double("Tool1")
18-
tool2 = instance_double("Tool2")
19-
tools = [tool1, tool2]
20-
agent = described_class.new(name: "TestAgent", tools: tools)
21-
expect(agent.name).to eq("TestAgent")
22-
end
17+
it "initializes RubyLLM::Chat with provided options" do
18+
agent.run("test input")
2319

24-
it "accepts a single tool and converts it to an array" do
25-
tool = instance_double("Tool")
26-
agent = described_class.new(name: "TestAgent", tools: tool)
27-
expect(agent.name).to eq("TestAgent")
20+
expect(mock_chat_class).to have_received(:new).with(model: "test-model")
2821
end
2922

30-
it "accepts schema parameter" do
31-
schema = { type: "object", properties: {} }
32-
agent = described_class.new(name: "TestAgent", schema: schema)
33-
expect(agent.name).to eq("TestAgent")
34-
end
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")
3527

36-
it "accepts all parameters together" do
37-
tool = instance_double("Tool")
38-
agent = described_class.new(
39-
name: "CompleteAgent",
40-
options: { model: "gpt-4" },
41-
tools: [tool],
42-
schema: { type: "object" }
43-
)
44-
expect(agent.name).to eq("CompleteAgent")
28+
expect(mock_chat_instance).to have_received(:with_tools).with(tools)
4529
end
46-
end
47-
48-
describe "#name" do
49-
it "returns the agent name" do
50-
agent = described_class.new(name: "MyAgent")
51-
expect(agent.name).to eq("MyAgent")
52-
end
53-
end
54-
55-
describe "#run" do
56-
let(:agent) { described_class.new(name: "TestAgent") }
57-
let(:mock_chat) { instance_double("Chat") }
5830

59-
it "delegates to chat.ask with the input" do
60-
allow(agent).to receive(:chat).and_return(mock_chat)
61-
allow(mock_chat).to receive(:ask).with("test input").and_return("response")
62-
63-
result = agent.run("test input")
64-
65-
expect(result).to eq("response")
66-
expect(mock_chat).to have_received(:ask).with("test input")
67-
end
68-
69-
it "passes different inputs to chat.ask" do
70-
allow(agent).to receive(:chat).and_return(mock_chat)
71-
allow(mock_chat).to receive(:ask).and_return("response")
72-
73-
agent.run("first input")
74-
agent.run("second input")
75-
76-
expect(mock_chat).to have_received(:ask).with("first input")
77-
expect(mock_chat).to have_received(:ask).with("second input")
78-
end
79-
end
31+
it "configures chat with schema if provided" do
32+
schema = { type: "object" }
33+
agent_with_schema = described_class.new(name: "TestAgent", schema: schema)
8034

81-
describe "inheritance" do
82-
it "inherits from Mars::Runnable" do
83-
expect(described_class.ancestors).to include(Mars::Runnable)
35+
agent_with_schema.run("test input")
36+
expect(mock_chat_instance).to have_received(:with_schema).with(schema)
8437
end
8538
end
8639
end

0 commit comments

Comments
 (0)