specs2

A simple Scala Given/When/Then style specification failed

只愿长相守 提交于 2019-12-11 06:07:26
问题 I am new to Spec2, and trying to learn it. I come up with the following codes, @RunWith(classOf[JUnitRunner]) class GWTStyleSpec extends Specification { "A given-when-then example for the addition" ^ "Given the following number: ${1}" ^ number1 ^ "And a second number: ${2}" ^ number2 ^ "Then I should get: ${3}" ^ result ^ end val number1: Given[Int] = (_: String).toInt val number2: When[Int, (Int, Int)] = (n1: Int) => (s: String) => (n1, s.toInt) val result: Then[(Int, Int)] = (n: (Int, Int))

Specify tests order using specs2 (scala/play framework)

不羁的心 提交于 2019-12-11 05:38:28
问题 I am currently writing a set of tests for a Scala Play application using the Specs2 library. I had some Stack overflow errors during the compilation process because the tests string was too long, so I've split it into several classes. The problem is that the tests are run simultaneously using a multi-threading process. I need to specify the order of those tests. Is there a way to do this? Regards. 回答1: You can specify that the tests must execute sequentially by adding sequential to your

sbt test encoding hickup

谁都会走 提交于 2019-12-10 21:19:48
问题 I am writing a Java library for the work with geo-coordinates and the tests are implemented with specs2 in Scala. I have many tests that do String comparisons against Strings that include the degree symbol ° (which is a non-ASCII character). If I run these tests from within IntelliJ, they all pass. They also pass on Travis CI. But if I run sbt test (sbt 11.3) from my Power Shell (Windows x64), all those tests fail and the console shows malformed Strings like shown in the screen shot: What

How to use jUnit's TemporaryFolder in scala's specs2 tests?

天涯浪子 提交于 2019-12-10 20:12:21
问题 I'm writing a test with Playframework, and I need to create a temporary file. @RunWith(classOf[JUnitRunner]) class DiagnosticSpec extends Specification { @Rule val temporaryFolder: TemporaryFolder = new TemporaryFolder() "my test" should { "run with temporary file" in { val file = temporaryFolder.newFile() // line.35 // go on with the file } } } But when I run this test, it always throw exception: [error] IllegalStateException: the temporary folder has not yet been created (MyTest.scala:35)

How to mock an Object in Scala

半腔热情 提交于 2019-12-10 16:15:30
问题 I'm new with scala. I'm trying to UT method inside my object Category, using Specs2 for UT and Mockito for mock. Why should I mock this? because this method take some data from mongo. There is my example object Category extends MongoBase[Category]("categories") { .... def myMethod(str: String): String .... } I've tried to mock object this way: val mockCategory = mock[Category.type] mockCategory.myMethod("1") returns "2" But my test failed Cannot mock/spy class Mockito cannot mock/spy

specs2: How to use “failtrace” option

杀马特。学长 韩版系。学妹 提交于 2019-12-10 15:04:04
问题 In my specs2 tests, I frequently use helper functions to test groups of conditions at once. Unfortunately, that makes the line number output of failed tests useless, since all failures are on the same line. Google turned up that there's a "failtrace" option that will output the stack trace of failure. However, I can't find an example of how to actually use that. Is it in build.sbt ? Is it used on the SBT command line? Is it set somehow in the constructor of the Specification class? 回答1: You

Using specs2 and FakeApplication() to test database fails evolution inserts

人走茶凉 提交于 2019-12-10 13:21:59
问题 This is for Play! Framework 2.0. I'm trying to write a simple test case to ensure my user model is functioning properly and persisting data in my database. I'd like to run it in memory if possible so I can get a fresh start with every new run. The issue I have is that my evolutions run(tables are created, data is inserted, but I can't query it as being there). First, my code. CREATE TABLE user_data ( id SERIAL PRIMARY KEY, user_name varchar(256) UNIQUE NOT NULL, email varchar(256) NOT NULL,

Play2 Framework/Scala/Specs2 - Do different FakeApplications share Singleton objects?

北战南征 提交于 2019-12-10 09:49:14
问题 I'm quite new to Play2 and Scala. I'm writing a simple application that uses ReactiveMongo plugin. I wrote a simple object to use as DAO object UserDAO { def db: reactivemongo.api.DB = ReactiveMongoPlugin.db def collection: JSONCollection = db.collection[JSONCollection]("users") collection.indexesManager.ensure(Index(List("name" -> IndexType.Ascending), unique = true)) def insert(User): Future[LastError] = { collection.insert(unit) } def findOne(query: JsObject): Future[Option[User]] = {

How to show custom failure message in Specs2 (Scala)?

混江龙づ霸主 提交于 2019-12-10 02:52:06
问题 For example, for code like this: myNum must beEqualTo("SOME INTERESTING TEXT") The message will be like the following: java.lang.Exception: ArrayBuffer() doesn't have size 1 but size 0 Is there an elegant way to get customised message displayed here? 回答1: First you can name value you're testing. myNum aka "meaningful name" must_== expectedValue You can also overwrite the full message. (myNum must_== expectedValue).setMessage("Full failure message") 来源: https://stackoverflow.com/questions

How to start Play application before tests and then shut it down in specs2?

孤人 提交于 2019-12-09 13:32:52
问题 My goal is to get an application running and execute multiple tests on the same instance of the app. I have tried this solution without much luck. Here is my test: class ApplicationSpec extends Specification { sequential object AppWithTestDb2 extends FakeApplication(additionalConfiguration = Map( ("db.default.driver") -> "org.h2.Driver", ("db.default.url") -> ( // "jdbc:h2:mem:play-test-" + scala.util.Random.nextInt + // in memory database "jdbc:h2:/tmp/play-test-" + scala.util.Random.nextInt