RubyGems   Gem version

The mockserver-client gem provides a Ruby client for MockServer's control-plane REST API, with a fluent builder DSL, WebSocket response callbacks, and an on-demand binary launcher that starts MockServer without Java or Docker.

Install

From the command line:

gem install mockserver-client

Or add to your Gemfile:

gem 'mockserver-client', '~> 7.0'

Quick start

require 'mockserver-client'

client = MockServer::Client.new('localhost', 1080)

# Create an expectation
client.when(
  MockServer::HttpRequest.request(path: '/hello').with_method('GET')
).respond(
  MockServer::HttpResponse.response(body: 'world', status_code: 200)
)

# Verify the request was received
client.verify(
  MockServer::HttpRequest.request(path: '/hello'),
  times: MockServer::VerificationTimes.at_least(1)
)

# Reset
client.reset
client.close

Block form

MockServer::Client.new('localhost', 1080) do |client|
  client.when(
    MockServer::HttpRequest.request(path: '/api/test')
  ).respond(
    MockServer::HttpResponse.response(body: '{"status":"ok"}', status_code: 200)
  )
end

Launch MockServer from Ruby

The gem includes a binary launcher — no Java installation or Docker required:

require 'mockserver-client'

handle = MockServer::BinaryLauncher.start(port: 1080)
puts "MockServer running on port #{handle.port}, PID #{handle.pid}"

# ... use MockServer ...

handle.stop

See Running MockServer — client library launcher for full launcher options (version pinning, cache directory, air-gapped networks).

For the full Ruby client API, see MockServer clients.