Skip to content

When using REST Assured, investigate if it's possible to defer documentation generation until after other conditions have been evaluated #214

@wilkinsona

Description

@wilkinsona

Feedback from @jlstrater:

When using the rest assured version, the documentation tests fail before other conditions like the status code. I'm not sure if this is by design but it was slightly confusing

This is due to the use of a Filter and the fact that it's called before the assertions in the then phase.
I've just looked at the possibility of the Filter returning a Response wrapper that can then hook into then() being called, but I don't think that would be enough to allow the documentation to be generated after all of the other conditions had been evaluated.

Another possibility (that would also read better) would be something like then().do(document(…)). This would also be a closer match for the approach with Spring MVC Test. Unfortunately, there's no such API in REST Assured that I'm aware of and then deals purely with responses whereas REST Docs needs access to both the request and the response.

@johanhaleby If you have a moment, I'd welcome your thoughts on this one please. The current approach looks like this:

given(this.documentationSpec)
        .accept("text/plain")
        .filter(document("sample", 
                preprocessRequest(modifyUris()
                        .scheme("https")
                        .host("api.example.com")
                        .removePort())))
.when()
        .port(this.port)
        .get("/")
.then()
        .assertThat().statusCode(is(200));

The Filter that's returned from document can throw an exception if the documentation doesn't match the service. Ideally, the failure would occur after checking that the response's status code was 200.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: declinedSuggestion or change that we don't want to make at this time

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions