Using Specs2 in a Typesafe activator play application

248 views Asked by At

I have used specs2 many times successfully in vanilla SBT projects. now I am starting to learn typesafe activator platform.

I did the following steps

activator new Shop just-play-scala

this is my build.sbt file

name := """Shop"""
version := "1.0-SNAPSHOT"
// Read here for optional jars and dependencies
libraryDependencies ++= Seq("org.specs2" %% "specs2-core" % "3.6.1" % "test")
resolvers += "scalaz-bintray" at "http://dl.bintray.com/scalaz/releases"
scalacOptions in Test ++= Seq("-Yrangepos")
lazy val root = project.in(file(".")).enablePlugins(PlayScala)

I created a file Shop/app/test/models/ShopSpec.scala

import org.specs2.mutable.Specification
class ShopSpec extends Specification {
  def foo = s2"""
    | This is a specification to check the 'Hello world' string
    | The 'Hello world' string should
    | contain 11 characters                             $e1
    | start with 'Hello'                                $e2
    | end with 'world'                                  $e3
    | """.stripMargin
    def e1 = "Hello world" must haveSize(11)
    def e2 = "Hello world" must startWith("Hello")
    def e3 = "Hello world" must endWith("world")
}

When I run activator test I get an error

[success] Total time: 0 s, completed Jun 24, 2015 12:21:32 AM
Mohitas-MBP:Shop abhi$ activator test
[info] Loading project definition from /Users/abhi/ScalaProjects/Shop/project
[info] Set current project to Shop (in build file:/Users/abhi/ScalaProjects/Shop/)

**cannot create a JUnit XML printer. Please check that specs2-junit.jar is on the classpath**

org.specs2.reporter.JUnitXmlPrinter$
java.net.URLClassLoader.findClass(URLClassLoader.java:381)
java.lang.ClassLoader.loadClass(ClassLoader.java:424)
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.jav

I have previously written spec2 test cases successfully when I was using SBT projects. but only when I use the typesafe activator that I get this issue with test cases.

I even changed the code of my test to something as simple as

import org.specs2.mutable.Specification

class ShopSpec extends Specification {
    "A shop " should {
        "create item" in {
            failure
        }
    }
}

But still the same problem.

2

There are 2 answers

0
Knows Not Much On BEST ANSWER

Wait .. I think I resolved it.

The activator play platform already has specs2 included so there is no need for me to tweak the built.sbt file for specs 2.

So I removed everything I had added to build.sbt file and left the file as

name := """Shop"""

version := "1.0-SNAPSHOT"

lazy val root = project.in(file(".")).enablePlugins(PlayScala)

Now it works fine. So basically, I don't need to add anything in a activator project for specs2.

I could have deleted the question... but leaving it here so that it can be of help to someone.

0
Ram Rajamony On

What worked for me was adding the following to build.sbt:

libraryDependencies ++= Seq("org.specs2" %% "specs2-core" % "3.6.2" % "test",
                            "org.specs2" %% "specs2-junit" % "3.6.2" % "test")