Giter Club home page Giter Club logo

spek's People

Contributors

alilosoft avatar artem-zinnatullin avatar arturdryomov avatar bdalenoord avatar binkley avatar byunghanyoo avatar charleskorn avatar eriwen avatar fboldog avatar floralvikings avatar hhariri avatar iamsteveholmes avatar igor-korotenko avatar jcornaz avatar jonnyzzz avatar lkogler avatar mhshams avatar ming13 avatar nkb03 avatar orangy avatar paslavsky avatar rabidaudio avatar raniejade avatar robstoll avatar seadowg avatar smred avatar tomtanti avatar turansky avatar udalov avatar ultraon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spek's Issues

Sample maven project

I tried to configure sample maven project with spek tests runnable from IDEA and during maven build but had no luck.

What I tried:

  1. configured sample maven project with kotlin JUnit test similar to https://github.com/JetBrains/kotlin-examples maven/mixed-code-hello-world. Tests runs fine both with IDEA (ultimate 14.0.2) and maven test (from command line).
  2. added spek dependency as described at http://jetbrains.github.io/spek/download.html version 0.1-SNAPSHOT was used. Btw: versions like 0.127 or 0.145 mentioned on the page do not exist - should be like 0.1.127 or 0.1.145
  3. added spek test
import kotlin.test.assertEquals
import org.jetbrains.spek.api.Spek

class BlaherSpecs: Spek() {{

    given("Let's test Blaher") {
        val blaher = Blaher()
        on("Blaher blah") {
            val blah = blaher.blah()
            it("should be Blah!") {
                assertEquals("Blah1!", blah)
            }
        }
    }
}}

it didn't compile because maven dependency had <type>pom</type> - compliled after commenting that out.

  1. Tried to run it with IDEA runner - got
/bin/bash /Users/admin/Projects/kotlin/src/test/java/SpecSample.kt
/Users/admin/Projects/kotlin/src/test/java/SpecSample.kt: line 1: import: command not found
/Users/admin/Projects/kotlin/src/test/java/SpecSample.kt: line 2: import: command not found
/Users/admin/Projects/kotlin/src/test/java/SpecSample.kt: line 4: syntax error near unexpected token `('
/Users/admin/Projects/kotlin/src/test/java/SpecSample.kt: line 4: `class BlaherSpecs: Spek() {{'

When building with maven it looks like SpecSample gets compiled

[info] Kotlin Compiler version 0.10.372
[info] Compiling Kotlin sources from [src/test/java]
[info] Classes directory is /Users/admin/Projects/kotlin/target/test-classes
[debug] Removed target directory from compiler classpath (/Users/admin/Projects/kotlin/target/test-classes)
[info] Classpath: src/test/java:/Users/admin/Projects/kotlin/target/classes:/Users/admin/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib/0.10.195/kotlin-stdlib-0.10.195.jar:/Users/admin/.m2/repository/org/jetbrains/kotlin/kotlin-runtime/0.10.195/kotlin-runtime-0.10.195.jar:/Users/admin/.m2/repository/junit/junit/4.10/junit-4.10.jar:/Users/admin/.m2/repository/org/hamcrest/hamcrest-core/1.1/hamcrest-core-1.1.jar:/Users/admin/.m2/repository/org/jetbrains/spek/spek/0.1-SNAPSHOT/spek-0.1-SNAPSHOT.jar
[info] Classes directory is /Users/admin/Projects/kotlin/target/test-classes
[debug] Scanning for kotlin annotations in /Users/admin/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib/0.10.195/kotlin-stdlib-0.10.195.jar
[debug] Scanning for kotlin annotations in /Users/admin/.m2/repository/org/jetbrains/kotlin/kotlin-runtime/0.10.195/kotlin-runtime-0.10.195.jar
[debug] Scanning for kotlin annotations in /Users/admin/.m2/repository/junit/junit/4.10/junit-4.10.jar
[debug] Scanning for kotlin annotations in /Users/admin/.m2/repository/org/hamcrest/hamcrest-core/1.1/hamcrest-core-1.1.jar
[debug] Scanning for kotlin annotations in /Users/admin/.m2/repository/org/jetbrains/spek/spek/0.1-SNAPSHOT/spek-0.1-SNAPSHOT.jar
[info] Using kotlin annotations from /Users/admin/.m2/repository/org/jetbrains/kotlin/kotlin-jdk-annotations/0.1-SNAPSHOT/kotlin-jdk-annotations-0.1-SNAPSHOT.jar
[debug] Using Kotlin home directory <no_path>
[debug] Configuring the compilation environment
[debug] Output:
/Users/admin/Projects/kotlin/target/test-classes/BlaherSpecs.class
Sources:
/Users/admin/Projects/kotlin/src/test/java/SpecSample.kt
[debug] Output:
/Users/admin/Projects/kotlin/target/test-classes/BlaherSpecs$1.class
Sources:
/Users/admin/Projects/kotlin/src/test/java/SpecSample.kt
[debug] Output:
/Users/admin/Projects/kotlin/target/test-classes/BlaherSpecs$1$1.class
Sources:
/Users/admin/Projects/kotlin/src/test/java/SpecSample.kt
[debug] Output:
/Users/admin/Projects/kotlin/target/test-classes/BlaherSpecs$1$1$1.class
Sources:
/Users/admin/Projects/kotlin/src/test/java/SpecSample.kt

but SpecSample test does not run - it should fail, but build succed.

I want to setup spek project with maven and IDEA so that

  1. I can run spek tests from IDEA - it works with this project spek-samples, so I assume it can be done. spek-samples is on gradle and spek dependency is compile project(':spek-core') though.
  2. Spek tests get run on maven build - I found no description or working sample how to achive that.

Sample project available at https://github.com/nhekfqn/kotlin-spek-maven-sample

If you help me to configure sample project, I will publish working version on github so that others can use it.

Thanks in advance.

Support pre-post actions for ```on```

Thats gonna be nice to allow running pre or post tasks before or after each on, e.g.

         given("aaa") {
              beforeOn { setupTheTest() }
              afterOn { tearDownTheTest() }

              on("aaa") { it("should be called after beforeOn closure") }
              on("bbb") { it("should be called afterOn and beforeOn prior to this") }
         }

init keyword is clunky

I don't like having to do { init { } } instead of {{ }}, have you guys any ideas about how you might be able to land on a clean syntax again?

Improve grouping in JUnit test reports

I've setup a test repo for this issue here.

When I run Spek suites in IntelliJ IDEA, the reports looks awesome:
IntelliJ IDEA test report

Suite class's name is visible alongside with it's package. The sings are aligned in tree. Just great.

But when I run tests in Gradle (./gradlew test) the report (build/reports/tests/index.html) is not so good:
Gradle test report - root
Gradle test report - default-package expanded
Gradle test report - arithmetics expanded

  • Everything is put inside default-package, which is not true.
  • given / describe / on blocks appear in one list.

I understand that reports are not supposed to support custom tree structures, but wouldn't it be better if describe goes to package name and all ons being grouped by them?

Also, XML reports should be tweaked too to improve reporting on CI...

Run configurations get hosed up and fail to work

Somehow it is possible to end up with run configurations that throw up this error:

java.lang.NoSuchMethodError: kotlin.properties.Delegates.lazy(Lkotlin/jvm/functions/Function0;)Lkotlin/properties/ReadOnlyProperty;

This sure looks like a classloader problem. Was able to slink out of this a few times by deleting them then recreating them.

Android documentation?

I created a spek test somewhere in the androidTest package. How do I include it in the test APK? Or how to run it at all? The website states that you can "just run it" in IntelliJ, how do I "just run it" in Android Studio without getting an "Empty test suite" error?

Basically I'm looking for a quick Android tutorial for Spek.

Switch to 1.6

I noticed current config requires Java 1.7. Why? Unless we have any prerequisites for that, let's consider 1.6 that my expand applicability of the library

Running (spring) integration speks?

Is there an equivalent for the following JUnit?

@RunWith(SpringJUnit4ClassRunner::class)
@ContextConfiguration(classes = arrayOf(Application::class), loader = SpringApplicationContextLoader::class)
@WebIntegrationTest

afterOn executing before On

Expected: on runs before afterOn
Actual: afterOn runs before on

Sample:

given("") {
    beforeOn { print("1") }
        on("") {
            print("2")
            it("") {
                print("3")
            }
    }
    afterOn { print("4") }
}

output:
1423

Handle expected exception

Is it possible to write tests where specific exception is expected, like using @Test(expected = UnhandledException::class) from JUnit ?
Thanks!

Robolectric integration

Currently, Spek doesn't play well with Robolectric ๐Ÿ˜ž

The reason is that Robolectric requires a BlockJUnit4ClassRunner, but Spek requires its own JUnitClassRunner. The exception thrown is:

java.lang.Exception: No runnable methods
    at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:191)
    at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:128)
    at org.junit.runners.ParentRunner.validate(ParentRunner.java:416)
    at org.junit.runners.ParentRunner.<init>(ParentRunner.java:84)
    at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:65)
    at org.robolectric.RobolectricTestRunner.<init>(RobolectricTestRunner.java:78)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

Would it be possible to support framework like Robolectric?

Release 0.1

Guys,

You think we can set a date for a 0.1 release of this?

Standard test definition

Currently we have 2 main approaches to define a test:

     class Speks : ConsoleTest() {{
         given("...") { ... }
     }}  //note double }} and {{

The next way is JUnit compatible:

     class Speks : JUnitSpek() {{
         given("...") { ... }
     }}

There are following questions:

  • do we like the syntax in general?
  • what is the best name for base class?

V1.0.0: given and on should prefix description

In v1.0.0, given and on are both aliases to describe.
They should be aliases that prefix the description with their keyword.

given(description, block) should translate to given("Given " + description, block)
on(description, block) should translate to on("On " + description, block)

Currently, when you use given("a calculator") {}, the IDEA test runner shows a test group that is named "a calculator" while it should be named "Given a calculator".

Testing async code

Hi there,
we trying to figure out how to test async code with Spek. Does Spek offer any facilities to test async code? With Quick we use waitUntil and toEventually.

Merging JUnitSpek and ConsoleSpek

Hi,

having looked at JUnitSpek and ConsoleSpek, I found they are almost identical.
the only difference is the "RunWith(javaClass<JSpec<*>>())" in the JUnitSpek.

I was thinking, we can merge them and have one parent Spek class only, which is of course annotated with "RunWith(javaClass<JSpec<*>>())".

By this approach, there will be one type of Specks only, But user can decide to whether run them with JUnit or Console Runner.

what do you think ?

Subject support

Most of the time you write specifications for a single class. Normally you would create a nullable local variable of that type and instantiate the said class in a beforeEach clause. With subjects we lessen the boilerplate, each test (it) will get their own instance of the subject.

class CalculatorSpec: SubjectSpek<SampleCalculator>({
    subject { SampleCalculator() }

    it("should return the result of adding the first number to the second number") {
        val sum = subject.sum(2, 4)
        assertEquals(6, sum)
    }

    it("should return the result of subtracting the second number from the first number") {
        val subtract = subject.subtract(4, 2)
        assertEquals(2, subtract)
    }
})

Improve IntelliJ Integration.

When using JUnit, I can tell IntelliJ to run a single test by right-clicking on it in the test results window or by right clicking on the test method name in the text area. With Spek tests, I am unable to do either of these things and it appears I can only run entire test classes (not individual given, it or on blocks). When all of the tests are passing this is fine. However, when I have a failing test that I want to debug this means I have to either comment out all other tests in the class or do some other kind of code-level test ignoring in order for my break points to not be hit when other (passing) tests in the suite are run.

Sadly, the inability to run single tests in IntelliJ has driven me away from Spek and back to JUnit for the time being. I'll watch this issue though as I would like to go back at some point. :)

shouldNotBeNull does not work

Does the opposite:

shouldNotBeNull(agentCommission)

Yields this result:

  java.lang.AssertionError: . Expected value to be null, but was: <Payout@326de728>.
    at kotlin.test.DefaultAsserter.fail(TestJVM.kt:79)
    at kotlin.test.Asserter$DefaultImpls.assertTrue(Test.kt:112)
    at kotlin.test.DefaultAsserter.assertTrue(TestJVM.kt:73)
    at kotlin.test.Asserter$DefaultImpls.assertNull(Test.kt:149)

Opposite of what is expressed.

IDEA vs Gradle vs Maven

What is the main project model that is used for the project?

Currently I see .gradle and .idea project. What should I open in IDEA to start?

spek-core missing in SNAPSHOT release

There is a dependency in the POM against spek-core and a unspecified version on jetbrains repo.

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.spek</groupId>
  <artifactId>spek</artifactId>
  <version>0.1-SNAPSHOT</version>
  <dependencies>
    <dependency>
      <groupId>spek</groupId>
      <artifactId>spek-core</artifactId>
      <version>unspecified</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>spek</groupId>
      <artifactId>spek-tests</artifactId>
      <version>unspecified</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

Conflict in runtime versions

Error:Conflict with dependency 'org.jetbrains.kotlin:kotlin-stdlib'. Resolved versions for app (1.0.1) and test app (1.0.0) differ. See http://g.co/androidstudio/app-test-app-conflict for details.

I saw some people talking about excluding the runtime from the test import. But since it's not in the docs, and I just spent ~ half an hour trying to add this one dependency to an Android project, going to go back to JUnit instead.

Why are releases not made on this project?

Spek + Android

I have an Android library in Kotlin and I want to start to bulid my test clases with Spek and probably with Mockito to mock a Context. I'm trying all day long but it not works.

Can Spek works with Android?

Allow it on given without an on

Sometimes you are just checking the static state of something and not really performing an action. For example, something simple like my API exports a constant for use by users and I want to just verify its value.

In English, I basically want to say something like this:

given("MY_CONSTANT")
{
     it("Should have the value 5") { shouldEqual(5, MY_CONSTANT) }
}

But I am forced to add an on in there, which isn't really needed since nothing is being done. You basically end up saying something unncessary like

given("MY_CONSTANT")
{
     on("inspection") { it("Sould have the value 5") { shouldEqual(5, MY_CONSTANT) } }
}

Shared subject specs support

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.

Incorrect reporting of exceptions in "on" clause

Tested on 0.1-SNAPSHOT (0.1-20140926.162946-6)

When there is an exception thrown inside "on" clause, IntelliJ shows me "Tests were not started".
Furthermore, other given clauses don't run at all.

Expected behavior:

  • exception in one clause shouldn't affect the others
  • IntelliJ test runner should mark only failed clauses as failed

Upgrade to JUnit 5

A custom JUnit 5 engine needs to be implemented, we should preserve the current behavior as much as possible.

M12 support

Any chance we'll be seeing a maven drop that includes 1ac8fe2?

(I realise I could use the snapshot version, but I'd rather keep my kotlin dependency on a stable release)

All Ons executes before Its

Actual: All Ons executes before Its.
Expected: Its executes after his Ons.
Kotlin M8 and Spek 0.127

class SpekSpecs: Spek() {{
    given("given1") {
        var log = ""
        on("on1") {
            log += "on1"
            it("it1 goes after on1") {
                log += "it1"
                shouldEqual("on1it1",log)
            }
        }

        on("on2") {
            log += "on2"
            it("it1 goes after on1 and it2 goes after on2") {
                log += "it2"
                shouldEqual("on1it1on2it2",log)
            }
        }
    }
}}

Intellij IDEA support for creating Spek tests

Correct me if I'm wrong, but it seems like Intellij doesn't support Spek as a first-class testing framework.

Ctrl+Shift+T -> Create New Test... -> Testing library

Spek is not on the list.

Spek breaks coverage reports

When I'm selecting "Run Tests in <package_name> with Coverage" in Android Studio.
The test coverage report works as long as I don't run any tests written with Spek.
Including Spek tests the report is showing 0 % coverage everywhere.

I fear loosing coverage reports is a K.O. criteria for using Spek for me. Do you know how to fix that?

spec-sample tests are not run with ./gradlew test

I've changed TimingSpecification test so that it fails when running with IDEA runner, than tried to run

./gradlew test

command from root of the project. Build succed. It looks like tests are not run while building project with gradle.

Empty blocks or not implemented scenarios, must be skipped (Pending mode)

User should be able to add "given", "on" and "it" without implementation. this is useful when he/she wants to create the scenarios only.

given("a fact, i need to do something about it")   //No action

given("a fact") {
     on("an event, there will be some results, but they are not clear yet")  //No action
}

given("a fact") {
      on("an event") {
          it("should result to ..., but is not clear yet") //No action
      }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.