Class: ModelContextProtocol::RSpec::Matchers::HaveMessageWithRole

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

Instance Method Summary collapse

Constructor Details

#initialize(role) ⇒ HaveMessageWithRole

Returns a new instance of HaveMessageWithRole.



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

def initialize(role)
  @expected_role = role.to_s
  @expected_content = nil
  @failure_reasons = []
end

Instance Method Details

#containing(content) ⇒ Object



28
29
30
31
# File 'lib/model_context_protocol/rspec/matchers/have_message_with_role.rb', line 28

def containing(content)
  @expected_content = content
  self
end

#descriptionObject



56
57
58
59
# File 'lib/model_context_protocol/rspec/matchers/have_message_with_role.rb', line 56

def description
  constraint = @expected_content ? " containing #{@expected_content.inspect}" : ""
  "have message with role '#{@expected_role}'#{constraint}"
end

#failure_messageObject



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

def failure_message
  constraint = @expected_content ? " containing #{@expected_content.inspect}" : ""
  "expected response to have message with role '#{@expected_role}'#{constraint}, but:\n" +
    @failure_reasons.map { |reason| "  - #{reason}" }.join("\n")
end

#failure_message_when_negatedObject



51
52
53
54
# File 'lib/model_context_protocol/rspec/matchers/have_message_with_role.rb', line 51

def failure_message_when_negated
  constraint = @expected_content ? " containing #{@expected_content.inspect}" : ""
  "expected response not to have message with role '#{@expected_role}'#{constraint}, but it did"
end

#matches?(actual) ⇒ Boolean

Returns:



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/model_context_protocol/rspec/matchers/have_message_with_role.rb', line 33

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

  return false if @serialized.nil?

  validate_has_messages &&
    validate_has_role &&
    validate_content_match
end