mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-25 07:16:40 +00:00
Response body value validation
Add the possibility to pass a block to the run_test! method in order to add expectations on your response
This commit is contained in:
10
README.md
10
README.md
@@ -103,6 +103,16 @@ If you've used [Swagger](http://swagger.io/specification) before, then the synta
|
||||
|
||||
Take special note of the __run_test!__ method that's called within each response block. This tells rswag to create and execute a corresponding example. It builds and submits a request based on parameter descriptions and corresponding values that have been provided using the rspec "let" syntax. For example, the "post" description in the example above specifies a "body" parameter called "blog". It also lists 2 different responses. For the success case (i.e. the 201 response), notice how "let" is used to set the blog parameter to a value that matches the provided schema. For the failure case (i.e. the 422 response), notice how it's set to a value that does not match the provided schema. When the test is executed, rswag also validates the actual response code and, where applicable, the response body against the provided [JSON Schema](http://json-schema.org/documentation.html).
|
||||
|
||||
If you want to do additional validation on the JSON response, pass a block to the __run_test!__ method:
|
||||
|
||||
```ruby
|
||||
response '201', 'blog created' do
|
||||
run_test! do |body|
|
||||
expect(body['title']).to eq('foo')
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
If you'd like your specs to be a little more explicit about what's going on here, you can replace the call to __run_test!__ with equivalent "before" and "it" blocks:
|
||||
|
||||
```ruby
|
||||
|
||||
Reference in New Issue
Block a user