Skip to content

A mock answers with the wrong response

A mock that holds several responses answers one of them. When it is not the one you expected, open the request under Request logs: Why this response? names the mock, the response, and how it was chosen, as they were when the request was served. To see what would answer the same request now, select Test against current mocks under Request; the page shows the recorded answer beside today’s (Test a logged request against today’s mocks). The cause is one of these.

The default is not the response you think it is

Section titled “The default is not the response you think it is”

Choosing a response tab to edit never changes the default. Under How a response is chosen, Default response is the one every ordinary request gets, and How this mock responds names it.

  1. Open the mock and read Default response.
  2. To change it, choose another there, or open the response and select Make default on save, then select Save mock.

You changed the default but have not saved it

Section titled “You changed the default but have not saved it”

How this mock responds reads Unsaved changes while the form differs from the saved mock, and says the live mock server keeps answering from the saved one.

  1. Select Save mock.

A save takes effect a moment later. A request sent in between still gets the old default. Send it again. The request log’s Why this response? names the version of the mock that answered, so you can tell a request served before the save from one served after it.

A request that sends X-MockHub-Response is answered with the response it names, whatever the default is. Selected by reads X-MockHub-Response header when that happened, and the default stays as it is. A client that always sends the header, such as a test setup copied from a colleague, keeps getting that response. See Choose the response that answers.

A mock that answers by rules tries them in order, and the first whose conditions all hold answers. Selected by names the rule by its number. A request that meets two rules gets the earlier one, and a request that meets none gets the response in Otherwise answer with.

  1. Open the mock and read the rules under How a response is chosen, from the top.
  2. Move the rule you expected above the one that answered, or narrow the earlier rule’s conditions, then select Save mock.
  3. Check the change in Try it under Which response a request gets before you send the request again.

Two active mocks can match one request, and which answers is not defined. Matched mock shows the one that did. See Request matching.

  1. Under Request, select Test against current mocks, then Test request.
  2. A result headed Now: 2 active mocks accepted this request lists both. Narrow one mock’s request matcher, or deactivate one, with Edit mock beside it. Save, go back to the test page, where your request is still filled in, and select Test request again until one accepts it.

A mock that answers with a sequence gives each call the next step, shared by every caller. Selected by reads Sequence, step 2, with its own number. Start the sequence again, or change the steps, which also starts it again.

A response with a template mistake is tagged Won’t render and answers a 500 when it is asked for. The tag names the response at fault; see A mock’s response did not render.

A log written before MockHub recorded which response answered, and one whose mock was served another way, shows Not recorded for this request. It does not guess from the mock’s default today, which may not be what answered.

Report a problem with the time of the request, the project’s address and the name of the mock.

Report a problem with this page