Body matching oddities #162

Closed
dolzenko opened this Issue Feb 8, 2012 · 3 comments

Projects

None yet

2 participants

@dolzenko
dolzenko commented Feb 8, 2012

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 changed, 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

@bblimke
Owner
bblimke commented Feb 8, 2012

Thanks for reporting this. It is definitely an incorrect behaviour.

@bblimke
Owner
bblimke commented Feb 11, 2012

Fixed in master.

@bblimke bblimke closed this Feb 11, 2012
@dolzenko

Fantastic, thanks a lot! And for the mention too ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment