-
Notifications
You must be signed in to change notification settings - Fork 22
Fix nil handling in item_type method and add parameter specs #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| RSpec.describe RubyLLM::MCP::Parameter do | ||
| describe "#item_type" do | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at your specs, we are missing the case that kicked off the issue in the first place. An array type without a item type attached. Possible to add that case? |
||
| context "when @items is nil" do | ||
|
||
| it "returns nil" do | ||
| parameter = described_class.new("test_param", type: "string") | ||
| expect(parameter.item_type).to be_nil | ||
| end | ||
| end | ||
|
|
||
| context "when @items is empty hash" do | ||
| it "returns nil" do | ||
| parameter = described_class.new("test_param", type: "string") | ||
| parameter.items = {} | ||
| expect(parameter.item_type).to be_nil | ||
| end | ||
| end | ||
|
|
||
| context "when @items['type'] is nil" do | ||
| it "returns nil" do | ||
| parameter = described_class.new("test_param", type: "string") | ||
| parameter.items = { "other_key" => "value" } | ||
| expect(parameter.item_type).to be_nil | ||
| end | ||
| end | ||
|
|
||
| context "when @items['type'] has a value" do | ||
| it "returns the type as a symbol" do | ||
| parameter = described_class.new("test_param", type: "array") | ||
| parameter.items = { "type" => "string" } | ||
| expect(parameter.item_type).to eq(:string) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe "#initialize" do | ||
| it "creates a parameter with default values" do | ||
| parameter = described_class.new("test_param") | ||
| expect(parameter.name).to eq("test_param") | ||
| expect(parameter.type).to eq(:string) | ||
| expect(parameter.required).to be(true) | ||
| expect(parameter.items).to be_nil | ||
| end | ||
|
|
||
| it "creates a parameter with custom values" do | ||
| parameter = described_class.new("test_param", type: "array", desc: "Test description", required: false) | ||
| expect(parameter.name).to eq("test_param") | ||
| expect(parameter.type).to eq(:array) | ||
| expect(parameter.desc).to eq("Test description") | ||
| expect(parameter.required).to be(false) | ||
| end | ||
| end | ||
| end | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible to use dig on this, that's the pattern that used in other locations in the codebase