its
Extracts a feature out of the current subject of this expectation with the help of the given extractor, creates a new Expect for it and returns it so that subsequent calls are based on the feature.
Return
The newly created Expect for the extracted feature.
Since
0.16.0
Samples
val person = Person(name = "John Smith", age = 25)
expect(person) its { age } toBeLessThan 30 toBeGreaterThan 20
// | | | subject is still of type Int (value = 25)
// | | subject is still of type Int (value = 25)
// | subject is now Int (value = 25)
fails {
expect(person) its { age } toBeLessThan 20 toBeGreaterThan 30
// | | | not reported because `toBeLessThan` fails
// | | fails
// | subject is now Int (value = 25)
}Extracts a feature out of the current subject of this expectation with the help of the given extractorWithCreator.extractor, creates a new Expect for it, applies an expectation-group based on the given extractorWithCreator.assertionCreator for the feature and returns the initial Expect with the current subject.
Return
an Expect for the subject of this expectation.
Since
0.16.0
Samples
val person = Person(name = "John Smith", age = 25)
expect(person) its feature({ age }) {
it toBeGreaterThan 18
it toBeLessThan 35
} // subject here is back to type Person
fails {
// all expectations are evaluated inside an expectation-group block; for more details:
// https://github.com/robstoll/atrium#define-single-expectations-or-an-expectation-group
expect(person) its feature({ age }) {
it toBeGreaterThan 40 // fails
it toBeLessThan 50 // still evaluated, use `its { ... }` if you want fail fast behaviour
}
}Inline property referring actually to this and allows writing infix assertions within an expectation-group
For instance, instead of:
expect {
...
}.toThrow<...>{
this messageToContain "oho"
}You can write
expect {
...
}.toThrow<...>{
its messageToContain "oho"
}Return
this
Since
0.12.0