Class ExpectationToRubySerializer
java.lang.Object
org.mockserver.serialization.code.ExpectationToRubySerializer
Generates copy-paste-ready Ruby expectation code for the MockServer Ruby
client (
mockserver-client).
Following the same JSON-wrap pattern as the JavaScript/Python generators, the
generated code embeds each expectation's existing JSON serialization (the
same bytes produced by format=JSON) in a heredoc, parses it with
JSON.parse, reconstructs it via MockServer::Expectation.from_hash
and passes it to client.upsert(...).
Verified against the Ruby client source:
MockServer::Client.new(host, port, ...)(require'mockserver-client')def upsert(*expectations)MockServer::Expectation.from_hash(data)(accepts a parsed JSON hash)
The JSON is embedded in a heredoc opened with <<JSON. The closing
delimiter is the literal token JSON alone on a line; Jackson's
serialized JSON can never produce such a line (every line is part of
structural JSON whose string values are escaped and quoted), so the heredoc
can never be terminated early by expectation content.
Example output for a single expectation:
require 'mockserver-client'
require 'json'
client = MockServer::Client.new('localhost', 1080)
client.upsert(MockServer::Expectation.from_hash(JSON.parse(<<JSON)))
{ ... }
JSON
- Author:
- jamesdbloom
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
ExpectationToRubySerializer
-
-
Method Details
-
serialize
-