Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ExpectAny should be extendable #11

@fluidsonic

Description

@fluidsonic

Subject and words of ExpectAny should be accessible publicly so that we can write extension functions for own assertions on the subject with own words being logged.

The following for example checks that two collections are equal while ignoring the order of the elements:

fun <Element> ExpectCollection<Element>.equalIgnoringOrder(expected: Collection<Element>) =
	apply {
		satisfy { subject ->
			val subjectList = subject.toList()
			val expectedList = expected.toList()

			subjectList.size == expectedList.size 
				&& subjectList.all(expectedList::contains) 
				&& expectedList.all(subjectList::contains)
		}
	}

Due to lack of access to subject the function satisfy must be used to access the subject.
Due to lack of access to words a failure would log satisfy predicate instead of something more helpful like equalIgnoringOrder $expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions