com.tngtech.jgiven.spock.ScenarioSpec.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jgiven-spock Show documentation
Show all versions of jgiven-spock Show documentation
Module for writing JGiven tests with Spock
package com.tngtech.jgiven.spock
import com.google.common.reflect.TypeToken
import com.tngtech.jgiven.impl.Scenario
import com.tngtech.jgiven.junit.JGivenClassRule
import com.tngtech.jgiven.spock.junit.JGivenSpockMethodRule
import org.junit.ClassRule
import org.junit.Rule
import spock.lang.Shared
import spock.lang.Specification
class ScenarioSpec extends Specification {
@ClassRule @Shared JGivenClassRule writerRule = new JGivenClassRule()
@Rule JGivenSpockMethodRule scenarioRule = new JGivenSpockMethodRule(createScenario())
GIVEN given() {
getScenario().given()
}
WHEN when() {
getScenario().when()
}
THEN then() {
getScenario().then()
}
Scenario getScenario() {
(Scenario) scenarioRule.getScenario()
}
Scenario createScenario() {
Class givenClass = (Class) new TypeToken(getClass()) {}.getRawType()
Class whenClass = (Class) new TypeToken(getClass()) {}.getRawType()
Class thenClass = (Class) new TypeToken(getClass()) {}.getRawType()
new Scenario(givenClass, whenClass, thenClass)
}
}