Skip to content

Feature: New unmocked policies#10

Merged
bstien merged 7 commits intomainfrom
feature/unmocked-policies
Sep 13, 2025
Merged

Feature: New unmocked policies#10
bstien merged 7 commits intomainfrom
feature/unmocked-policies

Conversation

@bstien
Copy link
Owner

@bstien bstien commented Sep 13, 2025

Why?

Currently the user is not able to provide their own response for unmocked incoming requests – the only option is a hardcoded 404 and passthrough to real network.

The changes in this PR adds these two cases to UnmockPolicy:

  • .mock(MockResponse)
  • .fatalError

UnmockedPolicy.mock(MockResponse)

This one lets the user provide their own MockResponse for all unmocked requests. The single response will be used for all incoming requests where a mock can't be found – either because none is registered, or the queue is empty.

UnmockedPolicy.fatalError

This is an addition for stricter testing which will call fatalError() if there aren't any mocks for an incoming request. Usecases will be to i.e. create a hard assumption that all network requests are mocked or handled.

Closes #7

What?

  • Add cases .mock(MockResponse) and .fatalError to UnmockedPolicy.
  • Pull out shared code for sending response in HTTPURLMockProtocol.
  • Add tests.
  • Update README.

Show me

let httpMock = HTTPMock()

// Set your own response to unmocked requests.
httpMock.unmockedPolicy = .mock(.plaintext("Ouchie!"))

// Force a `fatalError()` call on incoming unmocked requests.
httpMock.unmockedPolicy = .fatalError

@bstien bstien merged commit 2cf8983 into main Sep 13, 2025
1 check passed
@bstien bstien deleted the feature/unmocked-policies branch September 13, 2025 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Let the user provide a mock for "Not found"

1 participant