specs2

How to stub a method call with an implicit matcher in Mockito and Scala

送分小仙女□ 提交于 2021-02-20 05:52:51
问题 My application code uses AService trait AService { def registerNewUser (username: String)(implicit tenant: Tenant): Future[Response] } to register a new user. Class Tenant is a simple case class: case class Tenant(val vstNumber:String, val divisionNumber:String) Trait AServiceMock mimics the registration logic by using a mocked version of AService trait AServiceMock { def registrationService = { val service = mock[AService] service.registerNewUser(anyString) returns Future(fixedResponse)

How to stub a method call with an implicit matcher in Mockito and Scala

℡╲_俬逩灬. 提交于 2021-02-20 05:52:03
问题 My application code uses AService trait AService { def registerNewUser (username: String)(implicit tenant: Tenant): Future[Response] } to register a new user. Class Tenant is a simple case class: case class Tenant(val vstNumber:String, val divisionNumber:String) Trait AServiceMock mimics the registration logic by using a mocked version of AService trait AServiceMock { def registrationService = { val service = mock[AService] service.registerNewUser(anyString) returns Future(fixedResponse)

Testing json data using Specs2

落花浮王杯 提交于 2021-02-09 18:37:28
问题 I added(In built.sbt) matcher-extra :- "org.specs2" %% "specs2" % "2.3.4" % "test", "org.specs2" % "specs2-matcher-extra_2.10" % "2.3-scalaz-7.1.0-M3", the ("/" the symbols are not resolving) My example test case for Json is looking like below:- package specs.model import org.specs2.mutable.Specification import org.specs2.matcher.JsonMatchers class Json extends Specification with JsonMatchers { "Json Matcher" should { "1st field" in { val json = """{"name":"sagar"}""" json must /("name" ->

What does the <% operator mean in Scala generics? [duplicate]

空扰寡人 提交于 2021-01-21 08:26:59
问题 This question already has an answer here : What are Scala context and view bounds? (1 answer) Closed 15 days ago . In specs2 there is a method called Around, documented here that has the following example: object http extends Around { def around[T <% Result](t: =>T) = openHttpSession("test") { t // execute t inside a http session } } The source for this code can be found here. I'm curious what the <% operator means in this context? EDIT: here is a solid answer on this subject, What are Scala

What does the <% operator mean in Scala generics? [duplicate]

流过昼夜 提交于 2021-01-21 08:25:23
问题 This question already has an answer here : What are Scala context and view bounds? (1 answer) Closed 15 days ago . In specs2 there is a method called Around, documented here that has the following example: object http extends Around { def around[T <% Result](t: =>T) = openHttpSession("test") { t // execute t inside a http session } } The source for this code can be found here. I'm curious what the <% operator means in this context? EDIT: here is a solid answer on this subject, What are Scala

What does the <% operator mean in Scala generics? [duplicate]

故事扮演 提交于 2021-01-21 08:24:13
问题 This question already has an answer here : What are Scala context and view bounds? (1 answer) Closed 15 days ago . In specs2 there is a method called Around, documented here that has the following example: object http extends Around { def around[T <% Result](t: =>T) = openHttpSession("test") { t // execute t inside a http session } } The source for this code can be found here. I'm curious what the <% operator means in this context? EDIT: here is a solid answer on this subject, What are Scala

Make ScalaCheck tests deterministic

这一生的挚爱 提交于 2020-01-12 01:45:08
问题 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.

Specs2 - How to define complex objects for Given/When/Then steps

和自甴很熟 提交于 2020-01-06 07:57:23
问题 Specs2's documentation and samples show some codes about the use of Given/Then/When style in an acceptance test. Here one of them: "A given-when-then example for the addition" ^ "Given the following number: ${1}" ^ number1 ^ "And a second number: ${2}" ^ number2 ^ "And a third number: ${3}" ^ number3 val number1: Given[Int] = (_:String).toInt val number2: When[Int, (Int, Int)] = (n1: Int) => (s: String) => (n1, s.toInt) val number3: When[Seq[Int], Seq[Int]] = (numbers: Seq[Int]) => (s: String

Specs2 - How to define complex objects for Given/When/Then steps

笑着哭i 提交于 2020-01-06 07:56:06
问题 Specs2's documentation and samples show some codes about the use of Given/Then/When style in an acceptance test. Here one of them: "A given-when-then example for the addition" ^ "Given the following number: ${1}" ^ number1 ^ "And a second number: ${2}" ^ number2 ^ "And a third number: ${3}" ^ number3 val number1: Given[Int] = (_:String).toInt val number2: When[Int, (Int, Int)] = (n1: Int) => (s: String) => (n1, s.toInt) val number3: When[Seq[Int], Seq[Int]] = (numbers: Seq[Int]) => (s: String

How to group tests using specs2?

风流意气都作罢 提交于 2020-01-02 02:01:06
问题 I'm used to JUnit, in JUnit it is possible to group several tests (usually related to a class) just by defining these tests in a single file (class) and annotating them with @Test . Then, to run several of these tests, a TestSuite is created with @Suite.SuiteClasses and so on. In specs2 it is possible to group several tests at two different levels extending some Specification . For example: "Whatever" should { "do its job when possible" in { whatever(new Thing).work must beSome } "return none