question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
johanhalebycommented, Mar 23, 2016

I’ll keep this in the back of my head to see if something pops up in the future.

0reactions
wilkinsonacommented, Mar 23, 2016

Thanks for the clarification. But if linksWithRel throws exception on every failure how can you present all failures at once when using MockMvc?

It throws an exception describing all of the problems with the documentation of the links. The key thing is that this exception is thrown before any other expectations are checked. That’s the opposite of what happens with MockMvc and is what left @jlstrater slightly confused.

But it will require a lot of time to implement this (I think) and currently I cannot see any other use cases for it (which make me a bit reluctant to add support for this).

Understood. I thought I might be asking a lot.

Perhaps the conclusion is that we’ll have to live with this for now?

Yes, I think so. Thanks for taking the time to help us to explore a few possibilities.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing REST Endpoints Using REST Assured - Semaphore CI
Learn how to create functional tests that focus on the HTTP endpoints of a REST application using the Java library REST Assured.
Read more >
Part III, Subpart iv, Chapter 3, Section A. Examination Requests
For example, a claim for an amputated finger could be granted but the rest of the claim might be deferred until the pregnancy...
Read more >
5 tips to take your API testing with REST Assured ... - Siili Auto
In REST Assured, there are built-in assertions that allow us to check if, for instance, the status code we expect is, in fact,...
Read more >
Questions and Answers on the Title IX Regulations on Sexual ...
Answer 3: The 2020 amendments focus on “setting forth requirements for [schools'] responses to sexual harassment.”3 However, the preamble also ...
Read more >
SECTION 1: EVALUATING BORROWER INCOME CHAPTER 4
Section 4: Other Eligibility Requirements addresses a variety of other ... able to repay a loan, the Loan Originator must use repayment income....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found