# `PactEx.MockServer`
[🔗](https://github.com/arctarus/pact_ex/blob/v0.1.0/lib/pact_ex/mock_server.ex#L1)

A running Pact mock server.

Start one with `PactEx.Consumer.start_mock_server/3`, or let
`PactEx.Consumer.run/4` manage it. Send the requests of your test to `url`.

# `t`

```elixir
@type t() :: %PactEx.MockServer{
  pact_dir: Path.t(),
  pact_ref: reference(),
  port: pos_integer(),
  url: String.t()
}
```

# `matched?`

```elixir
@spec matched?(t()) :: boolean()
```

Returns `true` if every expected request arrived and no unexpected request did.

Returns `false` for a server that was already stopped.

# `mismatches`

```elixir
@spec mismatches(t()) :: [map()]
```

Returns the mismatches seen so far, as decoded maps.

Returns `[]` when there are none, and for a server that was already stopped.
See `PactEx.MismatchError` for the `"type"` values.

# `stop`

```elixir
@spec stop(t()) :: :ok
```

Stops the server and frees its resources. Always returns `:ok`, also when
the server was already stopped.

Read `matched?/1` and `mismatches/1` before calling it.

# `write_pact`

```elixir
@spec write_pact(t(), keyword()) :: :ok | {:error, PactEx.Error.t()}
```

Writes the pact file to the server's `pact_dir`, creating the directory if needed.

The file is named `<consumer>-<provider>.json`.

## Options

  * `:overwrite` - when `false` (the default), merges with an existing file.
    When `true`, replaces it.

Returns `{:error, %PactEx.Error{}}` if the file cannot be written, or if the
server was already stopped (code `3`). Raises `ArgumentError` on unknown
options or a non-boolean `:overwrite`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
