Class: ModelContextProtocol::RSpec::Matchers::HaveResourceMimeType

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

Instance Method Summary collapse

Constructor Details

#initialize(expected_mime_type) ⇒ HaveResourceMimeType

Returns a new instance of HaveResourceMimeType.



19
20
21
22
# File 'lib/model_context_protocol/rspec/matchers/have_resource_mime_type.rb', line 19

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

Instance Method Details

#descriptionObject



44
45
46
# File 'lib/model_context_protocol/rspec/matchers/have_resource_mime_type.rb', line 44

def description
  "have resource mime type matching #{@expected_mime_type.inspect}"
end

#failure_messageObject



35
36
37
38
# File 'lib/model_context_protocol/rspec/matchers/have_resource_mime_type.rb', line 35

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

#failure_message_when_negatedObject



40
41
42
# File 'lib/model_context_protocol/rspec/matchers/have_resource_mime_type.rb', line 40

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

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
32
33
# File 'lib/model_context_protocol/rspec/matchers/have_resource_mime_type.rb', line 24

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

  return false if @serialized.nil?

  validate_has_contents &&
    validate_mime_type
end