winterbe / expekt Goto Github PK
View Code? Open in Web Editor NEWBDD assertion library for Kotlin
Home Page: http://winterbe.github.io/expekt
License: MIT License
BDD assertion library for Kotlin
Home Page: http://winterbe.github.io/expekt
License: MIT License
Apologies for the noise, but just wanted to voice my appreciation for this project.
I've been using it for a long time (1.5 years?), and it's become central to all my tests. Thanks so much for your work.
Is there anyway you can support multi-line matching? ๐
"""
This is
some multiline 123
text
""".trimIndent().should.match("some multiline \\d+".toRegex(RegexOption.MULTILINE))
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
.
expect { throw RuntimeException("error") }.to.`throw`.a(RuntimeException::class)
As far as i see there is no easy way to compare the content of two arrays.
e.g. I have two ByteArrays.
I would expect the following to work:
written.readBytes().should.equal(data)
It just compares the references and fails.
This one works:
written.readBytes().toList().should.equal(data.asList())
That's a little bit ugly in my opinion.
It seams that framwork doesn't provide any way to check that tested code throws exception of specific kind. I guess test code can use try/catch, do fail if rich the end of try and do assertions in the catch clause. However this seams clunky and won't give correct nice message in case of failure.
I think the syntax for exceptions could be: expect(MyException::class).thrownBy {...}
If thrownBy returns the exception following code can validate details about it (message, cause, etc.).
Alternative syntax may be expect {...}.throws(MyException::class)
.
Borrowing from Fluent Assertions, it would be quite convenient to have lambda-based assertions for collections:
class Thing(val name)
val collection = arrayListOf(Thing("a"), Thing("b"), Thing("c"))
collection.should.contain({ it.name == "a" })
Currently it's possible to replicate this using list extensions, but it is not as readable, and will not give as descriptive message:
collection.firstOrNull({ it.name == "a" }).should.not.be.`null`
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.