Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make own DSL keywords runnable #25

Open
robstoll opened this issue Jan 16, 2017 · 3 comments
Open

Make own DSL keywords runnable #25

robstoll opened this issue Jan 16, 2017 · 3 comments
Assignees

Comments

@robstoll
Copy link

robstoll commented Jan 16, 2017

I have implemented own extension functions to have a DSL which suits more my needs. For instance, I have a keyword inCase similar to on and itThrows similar to it.

I do not really know how the plugin works but after a quick glance I guess the current keywords a hard-coded in SpekUtil.: If so, then it would be nice if GROUP_FN and TEST_FN would be configurable.

@raniejade raniejade self-assigned this Jan 17, 2017
@raniejade
Copy link
Owner

Will look into it. Thanks!

@berlin-ab
Copy link

berlin-ab commented Jan 26, 2017

Plus one. I was recently doing a code kata with the Rock Paper Scissors kata, but I could not get the Spek runner to pick up these tests:

class RockPaperScissorsTest : Spek({
    describe("rock paper scissors outcomes for matches") {
        whenThrowing(rock, and = rock, expect = tieGame)
        whenThrowing(rock, and = paper, expect = playerTwoWins)
        whenThrowing(rock, and = scissors, expect = playerOneWins)
        whenThrowing(paper, and = paper, expect = tieGame)
        whenThrowing(paper, and = rock, expect = playerOneWins)
        whenThrowing(paper, and = scissors, expect = playerTwoWins)
        whenThrowing(scissors, and = scissors, expect = tieGame)
        whenThrowing(scissors, and = paper, expect = playerOneWins)
        whenThrowing(scissors, and = rock, expect = playerTwoWins)
    }
})

private fun SpecBody.whenThrowing(value: String, and: String, expect: String) {
    it("throwing ${value} and ${and}") {
        val result = Game().playRound(value, and)
        assertThat(result).isEqualTo(expect)
    }
}

Using JUnit4's @RunWith(JUnitPlatform::class) picks up the whenThrowing method calls as tests.

@raniejade
Copy link
Owner

This will be a bit tricky to implement, since I have to rework how UniqueIds are generated. This ids are used to tell JUnit Platform which test to run. Currently the plugin inspects the source and build a UniqueId from it (generation code is in sync with spek-junit-platform-engine). UniqueIds are based on the description passed to test and group. We only use the source during inspection, so dynamic descriptions ("some $value") are not supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants