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

Shared subject specs support #88

Closed
raniejade opened this issue Jun 6, 2016 · 0 comments
Closed

Shared subject specs support #88

raniejade opened this issue Jun 6, 2016 · 0 comments
Milestone

Comments

@raniejade
Copy link
Member

raniejade commented Jun 6, 2016

Sometimes it's convenient to reuse specs - like testing a subclass (e.g Calculator and AdvancedCalculator).

DSL

class CalculatorSpec: SubjectSpek<Calculator>({
    ...
});

class AdvancedCalculatorSpec: SubjectSpek<AdvancedCalculator>({
    includeSubjectSpek(CalculatorSpec::class) // or an extension fun itBehavesLike(CalculatorSpec::class)
});

In KSpec we something like this:

class CalculatorSpec: KSpec() {
    override fun spec() {
        describe(Calculator::class) {
            itBehavesLike(calculator())
        }
    }

    companion object {
        fun calculator() = sharedExample<Calculator> {
            describe("add") {
                it("1 + 1 = 2") {
                    assertThat(subject.add(1, 1), equalTo(2))
                }
            }
            ...
        }
    }
}

class AdvancedCalculatorSpec: KSpec() {
    override fun spec() {
        describe(AdvancedCalculator::class) {
            itBehavesLike(CalculatorSpec.calculator())
        }
    }
}

Depends on #87.

@raniejade raniejade added this to the 1.0.0 milestone Jun 6, 2016
@raniejade raniejade changed the title Shared examples support Shared specs support Jun 11, 2016
@raniejade raniejade changed the title Shared specs support Shared subject specs support Jun 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant