Skip to content

Commit e854013

Browse files
authored
Fix tests (#18)
1 parent e942f48 commit e854013

File tree

4 files changed

+36
-44
lines changed

4 files changed

+36
-44
lines changed

.rubocop.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ Metrics/MethodLength:
1414
Exclude:
1515
- "lib/mars/workflows/parallel.rb"
1616

17-
RSpec/ExampleLength:
18-
Enabled: false
17+
Metrics/ParameterLists:
18+
Enabled: true
19+
Exclude:
20+
- "lib/mars/agent.rb"
1921

2022
Style/Documentation:
2123
Enabled: false

spec/mars/agent_spec.rb

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,48 @@
22

33
RSpec.describe Mars::Agent do
44
describe "#run" do
5+
subject(:run_agent) { agent.run("input text") }
6+
57
let(:agent) { described_class.new(name: "TestAgent", options: { model: "test-model" }) }
68
let(:mock_chat_instance) do
79
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)
912
end
1013
end
14+
let(:mock_chat_response) { instance_double("RubyLLM::Message", content: "response text") }
1115
let(:mock_chat_class) { class_double("RubyLLM::Chat", new: mock_chat_instance) }
1216

1317
before do
1418
stub_const("RubyLLM::Chat", mock_chat_class)
1519
end
1620

1721
it "initializes RubyLLM::Chat with provided options" do
18-
agent.run("test input")
22+
run_agent
1923

2024
expect(mock_chat_class).to have_received(:new).with(model: "test-model")
2125
end
2226

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
2733

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
2936
end
3037

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) }
3441

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
3747
end
3848
end
3949
end

spec/mars/aggregator_spec.rb

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
RSpec.describe Mars::Aggregator do
44
describe "#run" do
5-
let(:aggregator) { described_class.new }
6-
75
context "when called without a block" do
6+
let(:aggregator) { described_class.new }
7+
88
it "joins inputs with newlines" do
99
inputs = %w[first second third]
1010
result = aggregator.run(inputs)
@@ -15,35 +15,14 @@
1515
result = aggregator.run([])
1616
expect(result).to eq("")
1717
end
18-
19-
it "handles single input" do
20-
result = aggregator.run(["single"])
21-
expect(result).to eq("single")
22-
end
23-
24-
it "handles numeric inputs" do
25-
inputs = [1, 2, 3]
26-
result = aggregator.run(inputs)
27-
expect(result).to eq("1\n2\n3")
28-
end
2918
end
3019

31-
context "when called with a block" do
32-
it "executes the block and returns its value" do
33-
result = aggregator.run(["ignored"]) { "block result" }
34-
expect(result).to eq("block result")
35-
end
36-
37-
it "ignores the inputs when block is given" do
38-
inputs = %w[first second]
39-
result = aggregator.run(inputs) { "custom aggregation" }
40-
expect(result).to eq("custom aggregation")
41-
end
20+
context "when initialized with a block operation" do
21+
let(:aggregator) { described_class.new("Aggregator", operation: lambda(&:join)) }
4222

43-
it "can perform custom aggregation logic" do
44-
inputs = [1, 2, 3, 4, 5]
45-
result = aggregator.run(inputs) { inputs.sum }
46-
expect(result).to eq(15)
23+
it "executes the block and returns its value" do
24+
result = aggregator.run(%w[a b c])
25+
expect(result).to eq("abc")
4726
end
4827
end
4928
end

spec/mars/gate_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@
6969
expect(high_branch).to have_received(:run).with(10)
7070
end
7171

72-
it "raises an error when branch is not defined" do
72+
it "returns the input when branch is not defined" do
7373
# For input 3, condition returns "low" which is not in branches
74-
expect { gate.run(3) }.to raise_error(NoMethodError)
74+
result = gate.run(3)
75+
expect(result).to eq(3)
7576
end
7677
end
7778

0 commit comments

Comments
 (0)