bblimke/webmock — Issue #162: Body matching oddities
Author: dolzenko
Created: 2012-02-08 19:01:36+00:00
State: open

So I have just discovered a few oddities in the way Webmock matches request bodies, since I have already had to delve into internals I will use internal API for demonstration too:

> WebMock::BodyPattern.new(a: 1, b: 2).matches?({a: 1, c: nil}.to_json, 'application/json')
=> true

In other words - body matching algorithm [1] seems surprising to me, i.e. stubbed and actual bodies should have the same size, but then having different keys in stubbed and actual is accepted. If we agree that this should be change my proposition would be to compare actual keys, not the sizes of the both bodies.

[1] https://github.com/bblimke/webmock/blob/master/lib/webmock/request_pattern.rb#L224