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

Adding support for Spek 2 #3

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,52 @@ apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: "de.mannodermaus.android-junit5"

android {
compileSdkVersion 26
buildToolsVersion "27.0.3"
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "me.rozkmin.spekbdd"
minSdkVersion 19
targetSdkVersion 26
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArgument "runnerBuilder", "de.mannodermaus.junit5.AndroidJUnit5Builder"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
testOptions {
junitPlatform {
filters {
engines {
include 'spek2'
}
}
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:appcompat-v7:28.0.3'
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

implementation rxJavaDependencies.values()

testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
testImplementation unitTestDependencies.values()
testImplementation spekDependencies.values()
testImplementation project(":spekbdd")
testImplementation kotlinTestDependencies.values()
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestRuntimeOnly "de.mannodermaus.junit5:android-instrumentation-test-runner:0.2.2"
}
107 changes: 59 additions & 48 deletions app/src/test/java/me/rozkmin/spekbyexamples/examples.kt
Original file line number Diff line number Diff line change
@@ -1,75 +1,86 @@
package me.rozkmin.spekbyexamples

import me.rozkmin.spekbdd.BddDsl.And
import me.rozkmin.spekbdd.BddDsl.Given
import me.rozkmin.spekbdd.BddDsl.Scenario
import me.rozkmin.spekbdd.BddDsl.Then
import me.rozkmin.spekbdd.BddDsl.When
import me.rozkmin.spekbdd.BddDsl.xAnd
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.describe
import org.jetbrains.spek.api.dsl.it
import org.jetbrains.spek.api.dsl.on
import org.junit.Assert.assertTrue
import BddDsl.xAnd
import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.gherkin.Feature
import org.spekframework.spek2.style.specification.describe
import kotlin.test.assertTrue

class ManyCaseScenarioSample : Spek({
Scenario("user is looking for a bus") {
//setup context of a user
Given("bus list screen") {
Feature("looking for a bus") {
Scenario("user is looking for a bus") {
Given("bus list screen") {
}
When("user exists screen") {
Then("save data ") {

}
}
Then("save data ") {
}
}
Scenario("user is looking for a bus with favorites") {
Given("bust list screen") {
}
When("enters bus list screen") {
And("has favorite stops") {
Then("display list of bus with favorites on top") {
assertTrue(true)
}
}
And("has not favorite stops") {
Then("display list of bus") {
assertTrue(true)
}
}
}
And("has favorite stops") {
}
Then("display list of bus with favorites on top") {
assertTrue(true)
}
And("has not favorite stops") {
}
Then("display list of bus") {
assertTrue(true)
}
}
Scenario("user is entering bus detail") {
When("enters bus detail screen") {
Then("display detailed bus stop") {
assertTrue(true)
}
}
Then("display detailed bus stop") {
assertTrue(true)
}
}
}
})

class ManyCaseAndOneDisabledSample : Spek({
Scenario("user is looking for a bus") {
Given("bus list screen") {
class ManyCaseScenarioAndOneDisabledSample : Spek({
Feature("looking for a bus") {
Scenario("user is looking for a bus") {
Given("bus list screen") {
}
When("user exists screen") {
}
Then("save data ") {
}
}
Scenario("user is looking for a bus with favorites") {
Given("bust list screen") {
}
When("enters bus list screen") {
xAnd("has favorite stops", "NOT IMPLEMENTED YET") {
Then("display list of bus with favorites on top") {
assertTrue(true)
}
}
And("has not favorite stops") {
Then("display list of bus") {
assertTrue(true)
}
}
}
xAnd("has favorite stops", "NOT IMPLEMENTED") {
}
Then("display list of bus with favorites on top") {
assertTrue(true)
}
And("has not favorite stops") {
}
Then("display list of bus") {
assertTrue(true)
}
}
Scenario("user is entering bus detail") {
When("enters bus detail screen") {
Then("display detailed bus stop") {
assertTrue(true)
}
}
Then("display detailed bus stop") {
assertTrue(true)
}
}
}
})


class VanillaSpek : Spek({
describe("something") {
on("user action") {
context("user action") {
it("should respond to action") {
assertTrue(false)
}
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ apply from: 'dependencies.gradle'
apply from: 'testDependencies.gradle'

buildscript {
ext.kotlin_version = '1.2.21'
ext.kotlin_version = '1.2.71'
ext.android_plugin_version = '2.3.3'

repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:3.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

classpath "de.mannodermaus.gradle.plugins:android-junit5:1.2.0.0"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sun Feb 18 12:19:53 CET 2018
#Tue Oct 02 00:52:12 CEST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-all.zip
2 changes: 1 addition & 1 deletion spekbdd/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies {
sourceCompatibility = "1.7"
targetCompatibility = "1.7"
buildscript {
ext.kotlin_version = '1.2.21'
ext.kotlin_version = '1.2.71'
repositories {
mavenCentral()
}
Expand Down
54 changes: 11 additions & 43 deletions spekbdd/src/main/java/me/rozkmin/spekbdd/Extensions.kt
Original file line number Diff line number Diff line change
@@ -1,57 +1,25 @@
package me.rozkmin.spekbdd

import org.jetbrains.spek.api.dsl.ActionBody
import org.jetbrains.spek.api.dsl.Pending
import org.jetbrains.spek.api.dsl.SpecBody
import org.jetbrains.spek.api.dsl.TestBody
import org.jetbrains.spek.api.dsl.TestContainer
import org.spekframework.spek2.dsl.Skip
import org.spekframework.spek2.dsl.TestBody
import org.spekframework.spek2.style.gherkin.ScenarioBody

/**
* Created by jaroslawmichalik on 27.02.2018
*/
object BddDsl {

fun SpecBody.Scenario(description: String, body: SpecBody.() -> Unit) {
group("scenario: $description", body = body)
}

fun SpecBody.xScenario(description: String, pendingReason: String = "", body: SpecBody.() -> Unit) {
group("scenario: $description", body = body, pending = Pending.Yes(pendingReason))
}

fun SpecBody.xStory(description: String, pendingReason: String = "", body: SpecBody.() -> Unit) {
group("story: $description", body = body, pending = Pending.Yes(pendingReason))
}

fun SpecBody.Given(description: String, body: SpecBody.() -> Unit) {
group("given $description", body = body)
}

fun SpecBody.xGiven(description: String, pendingReason: String = "", body: SpecBody.() -> Unit) {
group("given $description", body = body, pending = Pending.Yes(pendingReason))
}

fun SpecBody.When(description: String, body: SpecBody.() -> Unit) {
group("when $description", body = body)
}

fun SpecBody.xWhen(description: String, pendingReason: String = "", body: SpecBody.() -> Unit) {
group("when $description", body = body, pending = Pending.Yes(pendingReason))
}

fun TestContainer.Then(description: String, body: TestBody.() -> Unit) {
test("then $description", body = body)
fun ScenarioBody.xGiven(description: String, pendingReason: String = "", body: TestBody.() -> Unit) {
delegate.test("Given: $description", body = body, skip = Skip.Yes(pendingReason))
}

fun TestContainer.xThen(description: String, pendingReason: String = "", body: TestBody.() -> Unit) {
test("then $description", body = body, pending = Pending.Yes(pendingReason))
fun ScenarioBody.xWhen(description: String, pendingReason: String = "", body: TestBody.() -> Unit) {
delegate.test("When: $description", body = body, skip = Skip.Yes(pendingReason))
}

fun SpecBody.And(description: String, body: ActionBody.() -> Unit) {
action("and $description", body = body)
fun ScenarioBody.xThen(description: String, pendingReason: String = "", body: TestBody.() -> Unit) {
delegate.test("Then: $description", body = body, skip = Skip.Yes(pendingReason))
}

fun SpecBody.xAnd(description: String, pendingReason: String = "", body: ActionBody.() -> Unit) {
action("and $description", body = body, pending = Pending.Yes(pendingReason))
fun ScenarioBody.xAnd(description: String, pendingReason: String = "", body: TestBody.() -> Unit) {
delegate.test("And: $description", body = body, skip = Skip.Yes(pendingReason))
}
}
7 changes: 3 additions & 4 deletions testDependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ext {

def JunitVersion = '4.12'
def KotlinMockitoVersion = '1.5.0'
def SpekVersion = "1.1.5"
def SpekVersion = "2.0.0-rc.1"

unitTestDependencies = [
junit : "junit:junit:${JunitVersion}",
Expand All @@ -13,8 +13,7 @@ ext {
]

spekDependencies = [
spekApi: "org.jetbrains.spek:spek-api:${SpekVersion}",
platformEngine: "org.jetbrains.spek:spek-junit-platform-engine:${SpekVersion}",
junitPlatformRunner: "org.junit.platform:junit-platform-runner:1.0.0"
spekApi: "org.spekframework.spek2:spek-dsl-jvm:${SpekVersion}",
platformEngine: "org.spekframework.spek2:spek-runner-junit5:${SpekVersion}",
]
}