Skip to content

Creating a simple static mock

Lazarus Lazaridis edited this page Nov 17, 2017 · 3 revisions

Here we will see how we can create the simplest kind of mock, the static one.

Click the Create new mock button in the home page and fill in the fields of the General tab as shown in the picture:

Duckrails mock form in general tab

Mind the path /my-static-mock and the request method get. Once done, the mock will be being served with get requests on the http://localhost:8080/my-static-mock (here I assume you have DuckRails started on port 8080)

Navigate to the Response body tab and set the Body type field to Static.

DuckRails mock form response body tab

Fill in the following html code as Body content:

<!DOCTYPE html>
<html>
    <head>
        <title>Static mock title</title>
    </head>

    <body>
        <h1>This is a static mock</h1>

        <table>
            <thead>
                <tr>
                    <th>First column header</th>
                    <th>Second column header</th>
                </tr>
            </thead>

            <thead>
                <tr>
                    <td>First column</td>
                    <td>Second column</td>
                </tr>
            </thead>
        </table>
    </body>
</html>

and set Content type to text/html.

Finally, change to the Headers tab and add a header:

Save the mock and navigate to http://localhost:8080/my-static-mock

As you can see in the picture below, the mock's body content is being displayed as html and the response contains the DuckRails-Static header that we defined.

DuckRails static mock html request

Now let's change the Content type to text/plain and check what happens. Alter the mock Content type as shown here: DuckRails mock form with content type text plain

Save and request the mock again. You should be seeing the Body content being rendered as plain text!

DuckRails static mock plain text request