To have the contents of the special-resources directory included in the classpath for tests and runMain , follow these steps:
unmanagedClasspath in Test += baseDirectory.value / "special-resources" unmanagedClasspath in (Compile, runMain) += baseDirectory.value / "special-resources"
Make sure the settings are correct using the show :
> show test:unmanagedClasspath [info] List(Attributed(C:\dev\sandbox\runtime-assembly\special-resources))
In the following Specs2 tests, I am convinced that the setup works fine:
import org.specs2.mutable._ class HelloWorldSpec extends Specification { "Hello world" should { "find the file on classpath" in { val text = io.Source.fromInputStream(getClass.getResourceAsStream("hello.txt")).mkString text must have size(11) } } }
hello.txt is located in the special-resources directory with the string hello world inside.
> ; clean ; test [success] Total time: 0 s, completed 2014-08-06 20:00:02 [info] Updating {file:/C:/dev/sandbox/runtime-assembly/}runtime-assembly... [info] Resolving org.jacoco#org.jacoco.agent;0.7.1.201405082137 ... [info] Done updating. [info] Compiling 1 Scala source to C:\dev\sandbox\runtime-assembly\target\scala-2.10\test-classes... [info] HelloWorldSpec [info] [info] Hello world should [info] + find the file on classpath [info] [info] Total for specification HelloWorldSpec [info] Finished in 17 ms [info] 1 example, 0 failure, 0 error [info] Passed: Total 1, Failed 0, Errors 0, Passed 1
And build.sbt :
unmanagedClasspath in Test += baseDirectory.value / "special-resources" libraryDependencies += "org.specs2" %% "specs2" % "2.4" % "test" fork in Test := true
source share