Class: ModelContextProtocol::RSpec::Matchers::HaveResourceAnnotations

Inherits:
Object
  • Object
show all
Defined in:
lib/model_context_protocol/rspec/matchers/have_resource_annotations.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected_annotations) ⇒ HaveResourceAnnotations

Returns a new instance of HaveResourceAnnotations.



22
23
24
25
# File 'lib/model_context_protocol/rspec/matchers/have_resource_annotations.rb', line 22

def initialize(expected_annotations)
  @expected_annotations = expected_annotations
  @failure_reasons = []
end

Instance Method Details

#descriptionObject



47
48
49
# File 'lib/model_context_protocol/rspec/matchers/have_resource_annotations.rb', line 47

def description
  "have resource annotations matching #{@expected_annotations.inspect}"
end

#failure_messageObject



38
39
40
41
# File 'lib/model_context_protocol/rspec/matchers/have_resource_annotations.rb', line 38

def failure_message
  "expected resource response to have annotations matching #{@expected_annotations.inspect}, but:\n" +
    @failure_reasons.map { |reason| "  - #{reason}" }.join("\n")
end

#failure_message_when_negatedObject



43
44
45
# File 'lib/model_context_protocol/rspec/matchers/have_resource_annotations.rb', line 43

def failure_message_when_negated
  "expected resource response not to have annotations matching #{@expected_annotations.inspect}, but it did"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
36
# File 'lib/model_context_protocol/rspec/matchers/have_resource_annotations.rb', line 27

def matches?(actual)
  @actual = actual
  @failure_reasons = []
  @serialized = serialize_response(actual)

  return false if @serialized.nil?

  validate_has_contents &&
    validate_has_annotations
end