mock-server / mockserver

MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Ruby. MockServer also includes a proxy that introspects all proxied traffic including encrypted SSL traffic and supports Port Forwarding, Web Proxying (i.e. HTTP proxy), HTTPS Tunneling Proxying (using HTTP CONNECT) and SOCKS Proxying (i.e. dynamic port forwarding).
http://mock-server.com
Apache License 2.0
4.59k stars 1.07k forks source link

Ruby client doesn't correctly retrieve requests with a body #239

Closed jnormington closed 6 years ago

jnormington commented 8 years ago

Here is a very basic reproducible rspec

RSpec.describe 'Mockserver retrieve requests' do
  it 'returns requests' do
    `curl -XPOST localhost:2000/message -d 'Hello this is a message'`

    msc = MockServer::MockServerClient.new('localhost', 2000)
    req = MockServer::Model::Request.new(method: :POST, path: '/message')

    #It will error on the below line    

    puts msc.retrieve(req)
   end
end

The error that comes out from retrieving the request from mockserver is

Hashie::CoercionError: Cannot coerce property :body from String to MockServer::Model::Body: undefined method `each_pair' for "Hello this is a message":String

It appears that the coercian isn't possible because the mockserver isn't sending the body type along to the request.

There is a PR which fixes the ruby client https://github.com/jamesdbloom/mockserver/pull/238 but my gut feeling tells me it ideally should returned from the overridden toString method in all the classes extending Body like StringBody below

https://github.com/jamesdbloom/mockserver/blob/master/mockserver-core/src/main/java/org/mockserver/model/StringBody.java#L65-L68
jamesdbloom commented 6 years ago

Closing as this issue will be fixed once the ruby client is re-written, that will happen once support for generating clients from Open API 3.0 becomes available https://github.com/swagger-api/swagger-codegen. Closing this issue as related to #182.