Step 2 - It's a test framework, so it asserts!
Please make sure your are on step 2 in your terminal by typing:
bin/step 2
Running a test against our own specification
In this second step we are going to test a simple GET
endpoint.
Our API is currently serving a list of Todo items on /todos
.
We start by creating a yaml file describing the specification of the endpoint. (Have a look at todo-spec/todos/getAll.yml
).
Let's run webspicy:
webspicy --debug todo-spec/todos/getAll.yml
Let's assert some more
If you're doing this tutorial using the docker option you will find the
todo-spec/todos/getAll.yml
file in theyourbackendisbroken/
folder that you created on step 0, that is on your own file system. Alternatively you can change them directly in the container, for instance usingvi
.
We can improve our specification in two ways:
-
We can change the output schema from
Any
to a stricter schema. Let's ensure we receive an actual array of Todo items.Edit the specification in
todo-spec/todos/getAll.yml
with your favorite editor and change theoutput_schema
as follows:output_schema: |- [{ id: Integer description: String }]
-
To ensure we receive 6 Todo items, assert some properties onto the output as shown below:
expected: content_type: application/json status: 200 assert: - size(6)
Let's run webspicy again:
webspicy --debug todo-spec/todos/getAll.yml
Try changing the assertions so that the test fails and see what happens.