Closed radarsh closed 7 years ago
Better logging is something I have wanted to do, so now that someone else wants it I can make it happen. :-)
I will have to consider how best to make it more spock/junit friendly. Good idea though. I will add this to my upcoming work.
Though I am currently working on something more robust, the server does already log some of this information. An expectation like:
ersatzServer.expectations {
get('/foo'){
called 1
query 'alpha', 'one'
responder {
code 200
content 'done'
}
}
}
would log something like this:
18:40:53.457 [XNIO-1 task-1] DEBUG com.stehno.ersatz.ErsatzServer - Request: { GET /foo (query=[alpha:[one]], headers={Accept=[text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2], Connection=[keep-alive], User-Agent=[Java/1.8.0_131], Host=[localhost:43451]}, cookies=[:]): <empty> }
18:40:53.503 [XNIO-1 task-1] DEBUG com.stehno.ersatz.ErsatzServer - Response({}): done
I have a solution for this which will be merged into development
shortly (and will be in the next release). For a failed request match you will get a report like this in the logging:
# Unmatched Request
http GET /foo ? alpha=[two]
Headers:
- Accept: [text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2]
- Connection: [keep-alive]
- User-Agent: [Java/1.8.0_131]
- Host: [localhost:33879]
Cookies:
Character-Encoding: null
Content-type: null
Content-Length: -1
Content:
<empty>
# Expectations
Expectation 0 (3 matchers):
✓ HTTP method matches <GET>
✓ Path matches "/foo"
X Query string alpha matches iterable containing ["one"]
(3 matchers: 2 matched, 1 failed)
and optionally on the standard output console as well (using a server config option).
This should provide at least a better starting point for figuring out what is not matching in a request.
Thanks for picking this up so swiftly. I can't wait to try it out.
I hope to be able to cut a release sometime early next week.
It would be invaluable if the actual and expected requests were logged in more detail and if possible, identify where they didn't match. I think mock-server does this and prints out which part of the request did not match (whether it was the method, body, headers etc).
Also consider making the output Spock and/or JUnit friendly so that IDEs (esp IntelliJ) can show a diff.