All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tngtech.jgiven.spock.ScenarioSpec.groovy Maven / Gradle / Ivy

There is a newer version: 1.3.1
Show newest version
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)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy