Inspects inside the passed value using the passed partial function.
Inspects inside the passed value using the passed partial function.
The inside method checks to see whether the partial function passed as the second curried
parameter is defined at the value passed as the first parameter, and if so, passes that value to the
partial function.
If the partial function is not defined at the passed value, inside will throw a
TestFailedException with a detail message describing the problem. Otherwise, if the
partial function returns normally, inside will return normally. If the partial function
completes abruptly with an exception that mixes in ModifiableMessage (such as
TestFailedException), inside will append the value's toString of
to the exception's detail message, and rethrow it. If the exception thrown by the partial function does not mix
in ModifiableMessage, inside completes abruptly with that same exception.
the value inside of which to inspect
the partial function to use to inspect inside the passed value
if the passed partial function is not defined at the passed value
Trait containing the
insideconstruct, which allows you to make statements about nested object graphs using pattern matching.For example, given the following case classes:
You could write:
inside (rec) { case Record(name, address, age) => inside (name) { case Name(first, middle, last) => first should be ("Sally") middle should be ("Ann") last should be ("Jones") } inside (address) { case Address(street, city, state, zip) => street should startWith ("25") city should endWith ("Angeles") state should equal ("CA") zip should be ("12345") } age should be < 99 }If an assertion fails, the error message will include the
toStringof each value passed toinsideclauses enclosing the failed assertion. For example, ifrecin the previous expression was defined like this:The error message will read: