unic / ScalaWebTest

ScalaWebTest is a library for writing ScalaTest/Selenium based integration tests for web applications. It helps you with your basic setup and provides a new and very efficient approach to testing.
https://scalawebtest.org
Apache License 2.0
29 stars 9 forks source link

Extend json.Gauge to disallow unspecified properties in testees #112

Closed DaniRey closed 4 years ago

DaniRey commented 4 years ago

While the JSON specification generally allows to send more properties then expected by the receiver, asserting that only certain properties are part of a JSON response is useful sometimes.

Therefore the json.Gauge should be extend to provide the following additional tests.

jsonTestee completelyFits types of jsonGauge
jsonTestee completelyFits typesAndArraySizes of jsonGauge
jsonTestee completelyFits values of jsonGauge
jsonTestee completelyFits valuesIgnoringArrayOrder of jsonGauge

The keyword by has the same function as of, but it reads better when combined with ...HasOnlyPropertiesSpecified

Examples using the following jsonGauge

{
 "specifiedNum": 1,
 "specifiedObj": {
   "specifiedText": "text"
 },
 "specifiedArray": [1,2]
}

The following testees should fail, because they contain an unspecified property.

{
 "specifiedNum": 1,
 "specifiedObj": {
   "specifiedText": "text"
 },
 "specifiedArray": [1,2],
 "unspecifiedBool": false
}
{
 "specifiedNum": 1,
 "specifiedObj": {
   "specifiedText": "text",
   "unspecifiedText": "oh no"
 },
 "specifiedArray": [1,2]
}