Skip to content

Commit

Permalink
Add a scala specs2 example (pantsbuild#4516)
Browse files Browse the repository at this point in the history
Adding a specs2 example, so it is more clear how it can be used. Also tested in an IntelliJ project, the tests run as expected as well in both IntelliJ JUnit runner and specs2 runner.
  • Loading branch information
wisechengyi authored Apr 27, 2017
1 parent 7788817 commit 8b3395c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
9 changes: 9 additions & 0 deletions 3rdparty/jvm/org/specs2/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright 2017 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

jar_library(
name='specs2-junit_2.11',
jars=[
jar(org='org.specs2', name='specs2-junit_2.11', rev='3.8.9'),
],
)
8 changes: 8 additions & 0 deletions examples/tests/scala/org/pantsbuild/example/specs2/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright 2017 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

junit_tests(
dependencies=[
'3rdparty/jvm/org/specs2:specs2-junit_2.11',
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2017 Pants project contributors (see CONTRIBUTORS.md).
// Licensed under the Apache License, Version 2.0 (see LICENSE).

package org.pantsbuild.example.specs2

import org.specs2.mutable.SpecificationWithJUnit

class HelloWorldSpec extends SpecificationWithJUnit {

"add three numbers" in {
1 + 1 + 1 mustEqual 3
}

"add 2 numbers" in {
1 + 1 mustEqual 2
}
}
9 changes: 9 additions & 0 deletions examples/tests/scala/org/pantsbuild/example/specs2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Scala Specs2 Example

Pants supports Scala Specs2. In order for it to work you have to extend the `SpecificationWithJUnit` class, because Pants uses JUnit's runner to run tests.

You can run these tests with the command:

`./pants test examples/tests/scala/org/pantsbuild/example/specs2`

This target can also be imported in IntelliJ. If you choose to run it with IntelliJ Scala Runner, you can see a Specs2 run configuration generated under Run -> Edit Configurations.

0 comments on commit 8b3395c

Please sign in to comment.