ScalaWebTest icon indicating copy to clipboard operation
ScalaWebTest copied to clipboard

Improve Error Message for Gauge when checking Lists for an Element

Open thedodobird2 opened this issue 5 years ago • 1 comments

When a JsonGauge checks a list of elements for a certain element using containsElementFitting, but doesn't fit any (for multiple reasons), the error message isn't very helpful. For example: The name attribute is only correct for one element in the list BUT another attribute of that 'correct' element does not match. This puts it on the same level and your gauge will just say it couldn't find a matching element. Even though there is one that is quite like it.

Proposal:

  • Find the elements with the most correct matches
  • Put these elements in a list
  • Output these "most similar elements" into the error message

Imagine the JSON array would be

{
  "universities": [
    {
      "name": "Universität Leiden",
      "begin": 1948,
      "end": 1956
    },
    {
      "name": "Mathematisch Centrum Amsterdam",
      "begin": 1951,
      "end": 1959
    },
    {
      "name": "Technische Universiteit Eindhoven",
      "begin": 1962,
      "end": 1984
    },
    {
      "name": "University of Texas at Austin",
      "begin": 1984,
      "end": 1999
    }
  ]
}

And the following test would be used

"The universities array"  should "contain an element with the expected values" in {
    universities containsElementFitting values of
      """{
        | "name": "Technische Universiteit Eindhoven",
        | "begin": 1962,
        | "end": 2084
        | }""".stripMargin
  }

Then it would fail with

[{"name":"Universität Leiden","begin":1948,"end":1956},{"name":"Mathematisch Centrum Amsterdam","begin":1951,"end":1959},{"name":"Technische Universiteit Eindhoven","begin":1962,"end":1984},{"name":"University of Texas at Austin","begin":1984,"end":1999}] did not contain an element, which matched the gauge definition {
 "name": "Technische Universiteit Eindhoven",
 "begin": 1962,
 "end": 2084
 }

But preferably it would be

[{"name":"Universität Leiden","begin":1948,"end":1956},{"name":"Mathematisch Centrum Amsterdam","begin":1951,"end":1959},{"name":"Technische Universiteit Eindhoven","begin":1962,"end":1984},{"name":"University of Texas at Austin","begin":1984,"end":1999}] 
did not contain an element, which matched the gauge definition {
 "name": "Technische Universiteit Eindhoven",
 "begin": 1962,
 "end": 2084
 }
the closest matches where [
 {"name":"Technische Universiteit Eindhoven","begin":1962,"end":1984}
 Expected :2084 in 'end'
 Actual   :1984
]

thedodobird2 avatar Jul 23 '19 13:07 thedodobird2