Spek: V1.0.0: given and on should prefix description

Created on 30 Mar 2016  路  8Comments  路  Source: spekframework/spek

In v1.0.0, given and on are both aliases to describe.
They should be aliases that prefix the description with their keyword.

given(description, block) should translate to given("Given " + description, block)
on(description, block) should translate to on("On " + description, block)

Currently, when you use given("a calculator") {}, the IDEA test runner shows a test group that is named "a calculator" while it should be named "Given a calculator".

Most helpful comment

a) I'm not sure localisation is a problem. "Given" is an english word, using it implies an english sentence.
Being french, I wouldn't write given("une calculatrice"). I'd rather create my own avec function.

b) To me, describe is the default. If you're using given, then you're exepected to provide a sentence that completes after the word.

All 8 comments

The only thing there is a) localisation support b) make it optional and default?

a) I'm not sure localisation is a problem. "Given" is an english word, using it implies an english sentence.
Being french, I wouldn't write given("une calculatrice"). I'd rather create my own avec function.

b) To me, describe is the default. If you're using given, then you're exepected to provide a sentence that completes after the word.

But if you're using French and want to use given, wouldn't you want it to say "avec"? And then where would that be placed? Point being, that one drawback of prefixing with given automatically it's that it will only work for English realistically.

If I would want to use french sentences, I'd use describe.

I sent a PR regarding this issue: https://github.com/JetBrains/spek/pull/90
I think it's OK to leave it tied to english words as the aliases are in english too, also "it" is in this way.

+1 for that PR to increase consistency.

But it would be best to support this with a set of non-spoken qualifiers in case you a) want to use a different language than English or b) have your test just structured in a different way.

I right now I need to end all my tests with an "it" like test name which quite often is just annoying.

So - when we are having given, on, it with forced descriptions I'd like to have corresponding methods that don't imply a description. We have describe, what about adding test as a companion to it?

@chisou There are some changes happening in spek right now which will allow you to extend the DSL. See https://github.com/JetBrains/spek/blob/junit5/spek-api/src/main/kotlin/org/jetbrains/spek/api/dsl/Standard.kt on how to do it. Do note that this has not been merged on master yet.

That looks quite cool and the Standard already seems to have all the methods I dreamed of :-) Great, looking forward to it!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

raosuj picture raosuj  路  3Comments

pilgr picture pilgr  路  3Comments

jcornaz picture jcornaz  路  4Comments

dnowak picture dnowak  路  7Comments

volkdown picture volkdown  路  6Comments