Class: ModelContextProtocol::RSpec::Matchers::HaveImageContent

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

Instance Method Summary collapse

Constructor Details

#initialize(mime_type: nil) ⇒ HaveImageContent



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

def initialize(mime_type: nil)
  @expected_mime_type = mime_type
  @failure_reasons = []
end

Instance Method Details

#descriptionObject



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

def description
  constraint = @expected_mime_type ? " with mime type '#{@expected_mime_type}'" : ""
  "have image content#{constraint}"
end

#failure_messageObject



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

def failure_message
  constraint = @expected_mime_type ? " with mime type '#{@expected_mime_type}'" : ""
  "expected response to have image content#{constraint}, but:\n" +
    @failure_reasons.map { |reason| "  - #{reason}" }.join("\n")
end

#failure_message_when_negatedObject



41
42
43
44
# File 'lib/model_context_protocol/rspec/matchers/have_image_content.rb', line 41

def failure_message_when_negated
  constraint = @expected_mime_type ? " with mime type '#{@expected_mime_type}'" : ""
  "expected response not to have image content#{constraint}, but it did"
end

#matches?(actual) ⇒ Boolean



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

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

  return false if @serialized.nil?

  validate_has_content &&
    validate_has_image_content
end