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 assert that all properties of the testee are specified (expected) by the gauge definition #113

Closed DaniRey closed 4 years ago

DaniRey commented 4 years ago
DaniRey commented 4 years ago

The long method names are not great. An alternative might be

testee completelyFits types of gauge

instead of

testeee fits typesAndHasOnlyPropertiesSpecified by gauge

All variants would then be

testee completelyFits types of gauge
testee completelyFits typesAndArraySizes of gauge
testee completelyFits values of gauge
testee completelyFits valuesIgnoringArrayOrder of gauge
DaniRey commented 4 years ago

@exoego do you have an opinion on this change?

exoego commented 4 years ago

I am fine with these longer names 😀

DaniRey commented 4 years ago

@exoego sorry for the late reply. Does that mean you would favor

testeee fits typesAndHasOnlyPropertiesSpecified by gauge

over

testee completelyFits types of gauge

I personally prefer the shorter variant using completelyFits. But I would like to gather as much input as I can, before commiting this to the next release.

exoego commented 4 years ago

I personally prefer:

I think fits typesAndHasOnlyPropertiesSpecified is a bit long and verbose, but maybe better choice, since it explains a lot than completelyFits types. (For first look, It is unclear what complete is intended for)

I think DSL like testee completelyFits types of gauge makes sense if there are other variants of assertion, something like:

DaniRey commented 4 years ago

Thank you for that valuable input. I usually prefer self-explaining names as well. Unfortunately I couldn't find a name that makes the DSL feel nice and consistent, while being self-explaining.

There are indeed other variants of assertions. I will therefore use completelyFits.

With ScalaWebTest 3.0.x we have the following assertions for JSON.

testee fits types of gauge
testee fits typesAndArraySizes of gauge
testee fits values of gauge
testee fits valuesIgnoringArrayOrder of gauge

As of ScalaWebTest 4.0.x, we will have the following assertions for JSON.

testee fits types of gauge
testee completelyFits types of gauge

testee fits typesAndArraySizes of gauge
testee completelyFits typesAndArraySizes of gauge

testee fits values of gauge
testee completelyFits values of gauge

testee fits valuesIgnoringArrayOrder of gauge
testee completelyFits valuesIgnoringArrayOrder of gauge

The methods fits and completelyFits are documented as follows.

    /**
      * Build a JsonGauge, which checks if the testee fits the gaugeDefinition, by the rules of the gaugeType.
      * The testee might contain properties, which are not specified in the gaugeDefinition.
      */
    def fits(gaugeType: GaugeType): JsonGaugeFits = JsonGaugeFits(gaugeByType(gaugeType))
    /**
      * Build a JsonGauge, which checks if the testee fits the gaugeDefinition, by the rules of the gaugeType.
      * More restrictive then @see [[org.scalawebtest.json.JsonGauge.JsonGaugeFromPlayJson#fits]]. All properties
      * of the testee have to be specified by the gaugeDefinition.
      */
    def completelyFits(gaugeType: GaugeType): JsonGaugeFits = JsonGaugeFits(gaugeByType(gaugeType, allPropertiesDefined = true))
exoego commented 4 years ago

Thanks ! Now I understood how completelyFits works. It sounds better choice than typesAndHasOnlyPropertiesSpecified