specs2

Still can't run multiple tests against play FakeApp with Salat / Casbah

有些话、适合烂在心里 提交于 2019-12-04 14:46:56
I thought I had fixed the problem temporarily, but it turns out I am still having problems. I am trying to create some specs2 tests for my models layer, I would like to insert some dummy object, and then run some queries to make sure data comes out as expected. Here is what my simple test looks like: class ModelSpec extends Specification { override def is = args(sequential = true) ^ super.is object FakeApp extends FakeApplication() running(FakeApp){ println("set up database") val newUser = User( email = "wfbarksdale@gmail.com", username = "weezybizzle", password = "nutterbutter") User.save

Play Framework Testing using MultipartFormData in a FakeRequest

老子叫甜甜 提交于 2019-12-03 17:39:25
问题 I am currently in the process of writing some Specs2 tests for may Play Framework 2.2.x application which accepts MultipartFormData submissions as part of it's function. I have successfully written other tests with text and JSON bodies using the following form: "respond to POST JSON with description field present" in { running(FakeApplication()) { val response = route(FakeRequest(POST, "/submission.json").withJsonBody(toJson(Map("content" -> toJson("test-content"), "description" -> toJson(

How to test methods that return Future?

喜夏-厌秋 提交于 2019-12-03 15:44:02
问题 I'd like to test a method that returns a Future . My attempts were as follows: import org.specs2.mutable.Specification import scala.concurrent.ExecutionContext.Implicits.global import scala.util.{Failure, Success} class AsyncWebClientSpec extends Specification{ "WebClient when downloading images" should { "for a valid link return non-zero content " in { val testImage = AsyncWebClient.get("https://www.google.cz/images/srpr/logo11ww.png") testImage.onComplete { res => res match { case Success

Play Framework Testing using MultipartFormData in a FakeRequest

帅比萌擦擦* 提交于 2019-12-03 05:54:23
I am currently in the process of writing some Specs2 tests for may Play Framework 2.2.x application which accepts MultipartFormData submissions as part of it's function. I have successfully written other tests with text and JSON bodies using the following form: "respond to POST JSON with description field present" in { running(FakeApplication()) { val response = route(FakeRequest(POST, "/submission.json").withJsonBody(toJson(Map("content" -> toJson("test-content"), "description" -> toJson("test-description"))))).get status(response) must equalTo(OK) contentType(response) must beSome.which(_ ==

How to test methods that return Future?

≡放荡痞女 提交于 2019-12-03 05:15:22
I'd like to test a method that returns a Future . My attempts were as follows: import org.specs2.mutable.Specification import scala.concurrent.ExecutionContext.Implicits.global import scala.util.{Failure, Success} class AsyncWebClientSpec extends Specification{ "WebClient when downloading images" should { "for a valid link return non-zero content " in { val testImage = AsyncWebClient.get("https://www.google.cz/images/srpr/logo11ww.png") testImage.onComplete { res => res match { case Success(image) => image must not have length(0) case _ => } AsyncWebClient.shutDown } } } } Apart from the fact

Play 2.0 FakeApplication setup with test configuration

若如初见. 提交于 2019-12-03 03:45:30
I have a specs2 test which uses a FakeApplication and an embedded mongodb database. def inMemoryMongoDatabase(name: String = "default"): Map[String, String] = { val dbname: String = "play-test-" + scala.util.Random.nextInt Map( ("mongodb." + name + ".db" -> dbname), ("mongodb." + name + ".port" -> EmbeddedMongoTestPort.toString)) } override def around[T <% Result](t: => T) = { running(FakeApplication(additionalConfiguration = inMemoryMongoDatabase(), additionalPlugins = Seq("se.radley.plugin.salat.SalatPlugin"))) { t // execute t inside a http session } } The FakeApplication uses the default

Make ScalaCheck tests deterministic

可紊 提交于 2019-12-03 00:27:26
I would like to make my ScalaCheck property tests in my specs2 test suite deterministic, temporarily, to ease debugging. Right now, different values could be generated each time I re-run the test suite, which makes debugging frustrating, because you don't know if a change in observed behaviour is caused by your code changes, or just by different data being generated. How can I do this? Is there an official way to set the random seed used by ScalaCheck? I'm using sbt to run the test suite. Bonus question: Is there an official way to print out the random seed used by ScalaCheck, so that you can

Specs2 - Tagging tests to run

耗尽温柔 提交于 2019-12-02 03:39:41
问题 I have been using ScalaTest for a while and I find pretty useful the ability to Tag your tests and run just those with a specific Tag from the command line. Is there anything similar in Specs2? I know that you can run a specific test class with testOnly but I would like to just run a test with a specific Tag within a Specification. 回答1: Here is how to do it: import org.specs2.mutable._ class MySpec extends Specification { tag("fast") "example1" >> ok tag("slow") "example2" >> ok } Then in sbt

Scala: How to test methods that call System.exit()?

我的梦境 提交于 2019-12-01 03:48:50
I have been developing a command-line tool which calls System.exit() ( don't want to use exceptions instead of ) on certain inputs. I am familiar with Java: How to test methods that call System.exit()? and its the most elegant approach . Unfortunately, it is not enough pure, due to I had to add the dependencies to system-rules , junit-interface Is there any common pattern for dealing with System.exit in specs2 which is more pure than my current approach which don't use specs2 ? import org.junit.Rule; import org.junit.Test; import org.junit.contrib.java.lang.system.ExpectedSystemExit; public

Parallel execution of tests

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 17:15:45
I've noticed that SBT is running my specs2 tests in parallel. This seems good, except one of my tests involves reading and writing from a file and hence fails unpredictably, e.g. see below. Are there any better options than setting all tests to run in serial, using separate file names and tear-downs for each test? class WriteAndReadSpec extends Specification{ val file = new File("testFiles/tmp.txt") "WriteAndRead" should { "work once" in { new FileWriter(file, false).append("Foo").close Source.fromFile(file).getLines().toList(0) must_== "Foo" } "work twice" in { new FileWriter(file, false)