Class: ModelContextProtocol::RSpec::Matchers::HaveMessageWithRole
- Inherits:
-
Object
- Object
- ModelContextProtocol::RSpec::Matchers::HaveMessageWithRole
- Defined in:
- lib/model_context_protocol/rspec/matchers/have_message_with_role.rb
Instance Method Summary collapse
- #containing(content) ⇒ Object
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(role) ⇒ HaveMessageWithRole
constructor
A new instance of HaveMessageWithRole.
- #matches?(actual) ⇒ Boolean
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 |
#description ⇒ Object
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_message ⇒ Object
45 46 47 48 49 |
# File 'lib/model_context_protocol/rspec/matchers/have_message_with_role.rb', line 45 def 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_negated ⇒ Object
51 52 53 54 |
# File 'lib/model_context_protocol/rspec/matchers/have_message_with_role.rb', line 51 def 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
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_role && validate_content_match end |