func orderPizza() throws
enum PizzaOrderError: Error {
case pizzaServiceNotAnsweringPhone
case unexpectedAnswer(String)
}
// Test that orderPizza throws any PizzaOrderError
expect { try orderPizza() }.to(throwError(errorType: PizzaOrderError.self))
// Test that orderPizza throws a .pizzaServiceNotAnsweringPhone error
expect { try orderPizza() }
.to(throwError(PizzaOrderError.pizzaServiceNotAnsweringPhone))
Given the abovementioned interface, how can I unit test, that orderPizza() throws any PizzaOrderError.unexpectedAnswer without checking the String?
Something like matching throwError(PizzaOrderError.unexpectedAnswer)
doesn't seem to be possible, as the compiler always expects a specific String argument to be provided with the reference error.
Nimble has a way to provide a closure to perform "arbitrary custom matching". I haven't been able to find any examples of how this should work and am a little bit confused about the return type of this closure being Void
. I would have expected something like Bool
.
How would I indicate success or failure in such a matching closure? And is there any shorter or cleaner way to extract a boolean information about an enum case match than this?
if case PizzaOrderError.unexpectedAnswer(_) = error {
return true
} else {
return false
}