Using matchers on properties with "have"

6 views
Skip to first unread message

Shannon Carey

unread,
Apr 28, 2017, 2:43:51 PM4/28/17
to scalatest-users
It's currently possible to use arbitrary matchers when using "inside", provided that the object under test is a pattern-matchable object (such as a case class).

However, I don't see a way to do the same thing with a non-pattern-matchable object. When using "should have", it looks like the only thing you can do is compare equality of properties.

Is there any way of using arbitrary matchers ("not be null", "<", "startWith", etc.) on the properties of an object, while still getting the friendly output from the "should have" matcher?

Thanks!
Shannon

PS:
The output of an "inside" matcher looks like this:

actualValue was not expectedValue,
inside com.example.MyClass@13526e59[propA=actualValue, propB=actualValue]

As you can see, it's difficult to tell what property is actually under test. Do you agree that the output should look more like the following?

Expected propA to be expectedValue but was actualValue
inside com.example.MyClass@13526e59[propA=actualValue, propB=actualValue]
Reply all
Reply to author
Forward
0 new messages