Improve diagnostics for null configuration

See gh-583
This commit is contained in:
Dmytro Nosan
2019-02-18 16:08:53 +02:00
committed by Andy Wilkinson
parent c4d664c3a2
commit b5f2454c00
6 changed files with 100 additions and 16 deletions

View File

@@ -47,6 +47,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import static io.restassured.RestAssured.given;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.fail;
import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName;
import static org.springframework.restdocs.headers.HeaderDocumentation.responseHeaders;
@@ -339,6 +340,27 @@ public class RestAssuredRestDocumentationIntegrationTests {
.hasContent("Custom curl request");
}
@Test
public void exceptionShouldBeThrownWhenCallDocumentRequestSpecificationNotConfigured() {
assertThatThrownBy(() -> given().port(tomcat.getPort()).filter(document("default")).get("/"))
.isInstanceOf(IllegalStateException.class).hasMessageContaining(messingConfigurationMessage());
}
@Test
public void exceptionShouldBeThrownWhenCallDocumentSnippetsRequestSpecificationNotConfigured() {
RestDocumentationFilter documentation = document("{method-name}-{step}");
assertThatThrownBy(() -> given().port(tomcat.getPort())
.filter(documentation.document(responseHeaders(headerWithName("a").description("one")))).get("/"))
.isInstanceOf(IllegalStateException.class).hasMessageContaining(messingConfigurationMessage());
}
private String messingConfigurationMessage() {
return "There is no REST Docs configuration. Looks like 'org.springframework."
+ "restdocs.restassured3.RestDocumentationFilter' was not invoked."
+ " Please check your configuration.";
}
private void assertExpectedSnippetFilesExist(File directory, String... snippets) {
for (String snippet : snippets) {
assertThat(new File(directory, snippet)).isFile();