Skip to content

Instantly share code, notes, and snippets.

@rodrigo-galba
Created November 12, 2012 11:52
Show Gist options
  • Save rodrigo-galba/4058942 to your computer and use it in GitHub Desktop.
Save rodrigo-galba/4058942 to your computer and use it in GitHub Desktop.
Rest assured with cucumber step definitions
public class TransformationStepdefs {
private RequestSpecification spec = RestAssured.with();
@Given("^I have a single \"([^\"]*)\" file$")
public void I_have_a_single_file(String format) throws Throwable {
spec.given().
multiPart("requestData", objectAsJson()).
header("Version", 1);
}
@Given("^I have a resize action with '(\\d+)x(\\d+)'$")
public void I_have_a_resize_action_with_x_(int arg1, int arg2) throws Throwable {
spec.given().
multiPart("image", new File("./src/test/resources/file.jpg"), "image/jpeg").
log().all();
}
@When("^I render the PDF$")
public void I_render_the_PDF() throws Throwable {
spec.when().
post("/service");
}
@Then("^I should have \"([^\"]*)\" \"([^\"]*)\" image file$")
public void I_should_have_image_file(String arg1, String arg2) throws Throwable {
spec.expect().
statusCode(200).
log().all();
}
}
@PPLCraigSyme
Copy link

PPLCraigSyme commented Nov 11, 2016

Hi
Thanks for publishing this code. I tried to use this approach testing a REST API, however, the test doesn't fail when a matcher doesn't match. If I use the standard approach:

.expect()
             .given()
                   .statusCode(200)
                   .body("postcode", equalTo(postCode))
                   .body("district", is(equalTo(postCode.substring(0, postCode.indexOf(' ')))))
                   .body("geopoint.lat", is(notNullValue() ))
                   .body("geopoint.lng", is(notNullValue() ))
               .when()
                   .get("/postcode/"+postCode);

The same test fails as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment