doc / ch.tutteli.atrium.api.infix.en_GB / feature

feature

fun <T, R> feature(extractor: T.() -> R, assertionCreator: Expect<R>.() -> Unit): ExtractorWithCreator<T, R> (source)

Helper function to create an ExtractorWithCreator

infix fun <T, R> Expect<T>.feature(property: KProperty1<in T, R>): FeatureExpect<T, R> (source)

Extracts the property out of the current subject of this expectation, 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 given property.

Since
0.12.0

infix fun <T, R> Expect<T>.feature(f: KFunction1<T, R>): FeatureExpect<T, R> (source)

Extracts the value which is returned when calling the method f on the current subject of this expectation, creates a new Expect for it and returns it so that subsequent calls are based on the feature.

Use feature of(...) in case the method requires parameters or in case you want to define an assertion group block for it.

Return
The newly created Expect for the return value of calling the method f on the current subject of this expectation.

Since
0.12.0

infix fun <T, R> Expect<T>.feature(of: Feature<in T, R>): FeatureExpect<T, R> (source)

Extracts a feature out of the current subject of this expectation using the given Feature.extractor, creates a new Expect for it and returns it so that subsequent calls are based on the feature.

Use of(K..., ...) to create a Feature where the first argument is the extractor in form of a KProperty1 or a KFunctionX and potentially the required arguments for a KFunctionX where X > 1.

Note, Feature will be made invariant once Kotlin 1.4 is out and Atrium depends on it (most likely with 1.0.0)

Parameters

of - Use of(K..., ...) to create a Feature where the first argument is the extractor in form of a KProperty1 or a KFunctionX and potentially the required arguments for a KFunctionX where X > 1.

Return
The newly created Expect for the extracted feature.

Since
0.12.0

infix fun <T, R> Expect<T>.feature(of: FeatureWithCreator<in T, R>): Expect<T> (source)

Extracts a feature out of the current subject of this expectation using the given FeatureWithCreator.extractor, creates a new Expect for it, applies an assertion group based on the given FeatureWithCreator.assertionCreator for the feature and returns the initial Expect with the current subject.

Use of(K..., ...) { ... } to create a FeatureWithCreator where the first argument is the extractor in form of a KProperty1 or a KFunctionX, the last an assertionCreator-lambda and the remaining arguments in-between the required arguments in case of a KFunctionX where X > 1.

Note, FeatureWithCreator will be made invariant once Kotlin 1.4 is out and Atrium depends on it (most likely with 1.0.0)

Parameters

of - Use of(K..., ...) { ... } to create a FeatureWithCreator where the first argument is the extractor in form of a KProperty1 or a KFunctionX, the last an assertionCreator-lambda and the remaining arguments in-between the required arguments in case of a KFunctionX where X > 1.

Return
an Expect for the subject of this expectation.

Since
0.12.0

infix fun <T, R> Expect<T>.feature(provider: MetaFeatureOption<T>.(T) -> MetaFeature<R>): FeatureExpect<T, R> (source)

Extracts a feature out of the current subject of this expectation, based on the given provider, creates a new Expect for it and returns it so that subsequent calls are based on the feature.

Parameters

provider - Creates a MetaFeature where the subject of this expectation is available via implicit parameter it. Usually you use f to create a MetaFeature, e.g. feature { f(it::size) }

Return
The newly created Expect for the extracted feature.

Since
0.12.0

infix fun <T, R> Expect<T>.feature(of: MetaFeatureOptionWithCreator<T, R>): Expect<T> (source)

Extracts a feature out of the current subject of this expectation, based on the given MetaFeatureOptionWithCreator creates a new Expect for it, applies an assertion group based on the given MetaFeatureOptionWithCreator.assertionCreator for the feature and returns the initial Expect with the current subject.

Note that you need to enable the new type inference of Kotlin (or use Kotlin 1.4 and above) in order that Kotlin is able to infer the types. As workaround you can use the overload which expects MetaFeatureOption<T>.(T) -> MetaFeature<R> and use it after the call (import from the package workaround). For instance:

// use
import ch.tutteli.atrium.api.infix.en_GB.workaround.it
expect(person) feature { f(it::age) } it { o toBe 20 }

// instead of (which causes problems with Kotlin < 1.4)
expect(person) feature of({ f(it::age) }) { o toBe 20 }

Parameters

of - Use the function of({ ... }) { ... } to create the MetaFeatureOptionWithCreator where the first argument is a lambda with a MetaFeatureOption as receiver which has to create a MetaFeature where the subject of this expectation is available via implicit parameter it. Usually you use f to create a MetaFeature, e.g. feature of({ f(it::size) }) { o toBe 3 }

Return
an Expect for the subject of this expectation.

Since
0.12.0