-
Notifications
You must be signed in to change notification settings - Fork 737
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document how to use Spring REST Docs with the MockMVC Kotlin DSL #677
Comments
Thanks for the report. REST Docs doesn't contain any Kotlin-specific code so I suspect that this is a problem with the MockMvc Kotlin DSL rather than REST Docs. To help us to figure out if that's the case, can you please provide a complete and minimal sample that reproduces the problem? You can do so by zipping something up and attaching it to this issue or by pushing it to a separate repository. |
Hi wilkinsona, have uploaded example to repo here: |
Thanks for the sample. When using the Kotlin DSL for MockMvc, you need to pass the result handler that is returned from @Test
fun shouldReturnDefaultMessageKotlinDSL() {
mockMvc.get("/hello")
.andExpect {
status { isOk }
content {
string(containsString("Hello, World"))
}
}.andDo {
print()
handle(document("home"))
}
} It's a shame that for this one piece, the Kotlin DSL isn't quite as elegant as the Java equivalent. I'm not sure how it could be improved while keeping the existing more elegant access to the built-in result handlers such as I'll keep this issue open as I think it's worth documenting the above. |
@wilkinsona Looks like there might be another issue with url templates. I'm seeing the following exception when using url templates in the request:
But adding
|
@countableSet Yeah, that's not great. Unfortunately, the Kotlin DSL hardcodes the use of @sdeleuze, do you have any recommendations here please? |
Sorry for the delay of my response.
You could probably extend MockMvc DSL in Spring REST Docs with something like:
Let's maybe discuss that in #547 (comment). |
Was trying to implement RestDocs MockMvc in our Kotlin project
However noticed that when using the MockMvc Kotlin DSL snippets were not generated
e.g.
However using the java format did correctly generate
e.g.
The text was updated successfully, but these errors were encountered: