Class: ModelContextProtocol::RSpec::Matchers::BeMcpErrorResponse

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

Instance Method Summary collapse

Constructor Details

#initialize(expected_message = nil) ⇒ BeMcpErrorResponse

Returns a new instance of BeMcpErrorResponse.



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

def initialize(expected_message = nil)
  @expected_message = expected_message
  @failure_reasons = []
end

Instance Method Details

#descriptionObject



49
50
51
52
# File 'lib/model_context_protocol/rspec/matchers/be_mcp_error_response.rb', line 49

def description
  constraint = @expected_message ? " with message matching #{@expected_message.inspect}" : ""
  "be an MCP error response#{constraint}"
end

#failure_messageObject



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

def failure_message
  constraint = @expected_message ? " with message matching #{@expected_message.inspect}" : ""
  "expected response to be an MCP error response#{constraint}, but:\n" +
    @failure_reasons.map { |reason| "  - #{reason}" }.join("\n")
end

#failure_message_when_negatedObject



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

def failure_message_when_negated
  constraint = @expected_message ? " with message matching #{@expected_message.inspect}" : ""
  "expected response not to be an MCP error response#{constraint}, but it was"
end

#matches?(actual) ⇒ Boolean

Returns:



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

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

  return false if @serialized.nil?

  validate_is_error &&
    validate_error_message
end