imbo / behat-api-extension

API extension for Behat, used to ease testing of JSON-based APIs
MIT License
109 stars 42 forks source link

New step: Set request body before sending the request #19

Closed christeredvartsen closed 7 years ago

christeredvartsen commented 8 years ago

Currently there is no way to set the request body without making the request in the same step. The following step might do the trick:

@Given the request body contains :content( as a string)

where :content can be a string. The step should check if :content is a path (unless the as a string part is specified in the step), and if so, attach a resource to the request body instead of the actual string, along with setting the correct Content-Type request header.

When as a string is used, the :content will be treated as a string even if it might be a valid path.

christeredvartsen commented 7 years ago

An implementation of this assertion can be found here: https://github.com/imbo/imbo/pull/513/commits/f2b0716f076e3e87b34f814f8d2d1017e346c7db

christeredvartsen commented 7 years ago

It might be better to split this into two different steps to have better error handling (for instance if one specifies a file that does not exist). The two steps could be:

Given the request body contains :path
Given the request body is :string