org.scalatest.Inside
See theInside companion object
trait Inside
Trait containing the inside construct, which allows you to make statements about nested object graphs using pattern matching.
For example, given the following case classes:
case class Address(street: String, city: String, state: String, zip: String) case class Name(first: String, middle: String, last: String) case class Record(name: Name, address: Address, age: Int)
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 toString of each value passed to inside clauses enclosing the failed assertion. For example, if rec in the previous expression was defined like this:
val rec = Record(
Name("Sally", "Anna", "Jones"),
Address("25 Main St", "Los Angeles", "CA", "12345"),
38
)
The error message will read:
"Ann[a]" was not equal to "Ann[]", inside Name(Sally,Anna,Jones), inside Record(Name(Sally,Anna,Jones),Address(25 Main St,Los Angeles,CA,12345),38)
Attributes
Members list
In this article