diff --git a/Gemfile b/Gemfile index 8b76222d..c9f42cbd 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,7 @@ source "https://rubygems.org" gemspec # Specify development dependencies below -gem "rubocop-minitest", require: false +gem "rubocop-minitest", ">= 0.39.0", require: false gem "rubocop-rake", require: false gem "rubocop-shopify", ">= 2.18", require: false if RUBY_VERSION >= "3.1" diff --git a/lib/mcp/annotations.rb b/lib/mcp/annotations.rb index 9674c73e..540588a6 100644 --- a/lib/mcp/annotations.rb +++ b/lib/mcp/annotations.rb @@ -5,6 +5,8 @@ class Annotations attr_reader :audience, :priority, :last_modified def initialize(audience: nil, priority: nil, last_modified: nil) + raise ArgumentError, "The value of priority must be between 0 and 1." if priority && !priority.between?(0, 1) + @audience = audience @priority = priority @last_modified = last_modified diff --git a/test/mcp/annotations_test.rb b/test/mcp/annotations_test.rb index 60bfa722..a82b9552 100644 --- a/test/mcp/annotations_test.rb +++ b/test/mcp/annotations_test.rb @@ -55,5 +55,31 @@ def test_initialization_with_last_modified_only assert_equal({ lastModified: timestamp }, annotations.to_h) end + + def test_valid_priority_at_lower_bound + assert_nothing_raised do + Annotations.new(priority: 0) + end + end + + def test_valid_priority_at_upper_bound + assert_nothing_raised do + Annotations.new(priority: 1) + end + end + + def test_invalid_priority_above_upper_bound + exception = assert_raises(ArgumentError) do + Annotations.new(priority: 1.5) + end + assert_equal("The value of priority must be between 0 and 1.", exception.message) + end + + def test_invalid_priority_below_lower_bound + exception = assert_raises(ArgumentError) do + Annotations.new(priority: -0.1) + end + assert_equal("The value of priority must be between 0 and 1.", exception.message) + end end end