by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Matthew de Detrich
@mdedetrich
When comparing values using ==, does anyone have any ideas what might be causing this?
Eric Torreborre
@etorreborre
You mean comparing with ===?
Matthew de Detrich
@mdedetrich
No, we just use ==
Eric Torreborre
@etorreborre
=== will give better diagnostics than False is not True and might get around this implicits issue
Matthew de Detrich
@mdedetrich
Actually nvm, it was a type inference issue from elsewhere
Eric Torreborre
@etorreborre
+1
Matthew de Detrich
@mdedetrich
Gotta love Scala's type inference somtimes
Eric Torreborre
@etorreborre
That’s why I get some comfort working in a language with no subtyping / variance / covariance :-)
Mohamedali10
@Mohamedali10
Hello, is it possible to check on directory size?
I' am using the method haveSameFilesAs would it be sufficient for checking directory size and content?
Eric Torreborre
@etorreborre
There’s no existing matcher for this but you can define your own haveDirectorySize(greaterThan(10000)) where haveDirectorySize takes a org.specs2.matcher.ValueCheck[Int] as a parameter
Mohamedali10
@Mohamedali10
ok thanks
Mohamedali10
@Mohamedali10

Hello @all, I ahve the following example :

object testSpec
    extends Specification {
  def is =
    s2"""
       ${Step(firstStep)}
      example of execution1 $e1
      example of execution2  $e2
     example of execution3  $e3
     example of execution4  $e4
 ${Step(secondStep)}
       example of execution1 $e1
      example of execution2  $e2
     example of execution3  $e3
     example of execution4  $e4
"""
}

Is it possible to minimize the number of lines in the description and put all that in a loop in order to execute the firstStep and secondStep on each example of execution?

Andrey Ivanov
@a_nigredo_twitter

Hi all, is it possible to achive this one:

import org.specs2._
import specification._
import core.Fragments
import runner.SpecificationsFinder

// run this specification with `all` to execute
// all linked specifications
class Database extends Specification { def is =
  "All database specifications".title ^ br ^
  link(new Create).hide ^
  Fragments.foreach(specs)(s => link(s) ^ br) ^
  link(new Delete).hide

  def specs = specifications(pattern = ".*Db.*")
} 

// start the database with this specification
class Create extends Specification { def is = xonly ^ 
  step("create database".pp)
}

// stop the database with this specification
class Delete extends Specification {  def is = xonly ^
  step("delete database".pp)
}

// an example of a specification using the database
// it will be invoked by the "Database" spec because 
// its name matches ".*Db.*"
class Db1Spec extends Specification { def is = s2"""
   test $db
   """
  def db = { println("use the database - 1"); ok }
}
class Db2Spec extends Specification { def is = s2"""
   test $db
   """
  def db = { println("use the database - 2"); ok }
}

in specs2 4.3.4?

I try to fix error that beforeAll and After all run in parallell with test suite
Predrag Stefanovic
@predragstefanovic

Hey, I would like to know whether is possible to assert a condition on all elements of a JsonArray. I am using JsonMatchers.
In the example

val json = """{"products":[{"flag":true},{"flag":false}]}"""

Is there a way to assert that all flag fields are true

Eric Torreborre
@etorreborre
@a_nigredo_twitter sorry about that, there is a bug: etorreborre/specs2#797. I will try to fix it ASAP
@predragstefanovic unfortunately not at the moment
Predrag Stefanovic
@predragstefanovic
ok thanks
Eric Torreborre
@etorreborre
@a_nigredo_twitter I released 4.8.2which fixes the issue you found
Andrey Ivanov
@a_nigredo_twitter
@etorreborre great, thanks, I'll update my project
Eric Torreborre
@etorreborre
Tell me how this goes, this part is a bit ad-hoc in specs2
Andrey Ivanov
@a-nigredo
@etorreborre, unfortunately, it does not work
Eric Torreborre
@etorreborre
@predragstefanovic could you please create a small github project reproducing the issue because the example you pasted above works ok for me?
Gunnar Lilleaasen
@heksesang
Is there gonna be any Dotty-releases soon? .withDottyCompat doesn’t work for the non-mutable specs because it relies on Scala 2 macros.
Eric Torreborre
@etorreborre
Unfortunately not soon. I am still (slowly) working on a version 5 which removes a few features that are not supported by Dotty, like DelayedInit for mutable specs, but I haven’t had a look yet at the s2 macro. There seems to be a way to do it: https://github.com/lampepfl/dotty/issues/5095#issuecomment-423299541
Gunnar Lilleaasen
@heksesang
Yeah, there are a couple of examples in the Dotty repo, like this: https://github.com/lampepfl/dotty/blob/master/tests/run-macros/xml-interpolation-1/XmlQuote_1.scala
Should probably be able to do the same for the s2 macro.
Eric Torreborre
@etorreborre
Thanks for the link I’ll try that
Keir Lawson
@keirlawson
what's the most concise way to check that a map's contents is either equal to or a subset of another map? I see havePairs but that requires that I convert one map to a list of pairs, for which there doesn't seem to be a ready-made function in the standard library
Eric Torreborre
@etorreborre
@keirlawson there’s indeed no matcher for that. A MapMatchers.isSubsetOf PR is welcome!
Andrey Ivanov
@a_nigredo_twitter
Hi @all, are there any requirements for stack size for specs2 4.2.0? I add new test case to my specs2 and it is start to throw StackOverflow error for FutureEffect. I use default stack size
Andrey Ivanov
@a_nigredo_twitter
I've fixed, must update specs >= 4.3.2. The issue was etorreborre/specs2#682
Philip Schwarz
@philip_schwarz_twitter
hello - I am unable to use the cats none[Int] syntax within a specs2 Specification because in there none refers to a matcher rather than to the cats syntax. Any ideas how to avoid the problem? (love specs2 btw). https://scastie.scala-lang.org/philipschwarz/Q0pHNey3SLqNixeTJj5q0A/71
image.png
Philip Schwarz
@philip_schwarz_twitter
Christopher Davenport
@ChristopherDavenport
Hi all, trying to figure out how to run tests for Future or Asynchronous code for scalajs. Was trying to figure out how to test cats-effect based code for that platform. Is there any support for that at the moment?
Eric Torreborre
@etorreborre

ScalaJS is supported but I am not a primary user so it is hard for me to tell. Using a Future as a result in an example should work thanks to this implicit:

implicit class futureAsResult[T](f: => Future[T])(implicit ee: ExecutionEnv, asResult: AsResult[T]) extends FutureAsResult[T](f)

So if your class has an implicit ExecutionEnv like class MySpec(implicit ee: ExecutionEnv) extends Specificationyou should be able to write ”test ok” >> Future(ok)

Christopher Davenport
@ChristopherDavenport
I arrived at that same thought, but got a linking error. I'll double check myself.
Eric Torreborre
@etorreborre
It might be a problem on specs2 side. Please post a small reproducible sample if you have one
Christopher Davenport
@ChristopherDavenport
Will try to pin it down. Going to check to see if its the awaitFor. This is the PR I found it on, but is obviously not minimal yet. - https://github.com/djspiewak/cats-effect-testing/pull/70/files
Christopher Davenport
@ChristopherDavenport
@etorreborre Heres a minimal reproduction thats blocking me from hitting the later one. Can't initialize the class. First one seems to work so theres something between the ExecutionEnv and the AsResult instance thats ending me up in the painful point, as the Future(ok) works on scalajs with the global EC.
https://github.com/ChristopherDavenport/specs2scalajstest/blob/master/core/src/test/scala/io/chrisdavenport/specs2jstest/MainSpec.scala#L18
Eric Torreborre
@etorreborre
I have a fix on the way. Let’s see if everything is fine on CI
Eric Torreborre
@etorreborre
Oh, I forgot to say. The FutureMatchers and FutureAwait traits need to be moved to JVM only because they are using await which does not work on ScalaJS
Paweł Kiersznowski
@pk044
is it possible to skip all tests on condition on 'trait' level? it generally works if i execute it in every test suite, but i'd rather do it inside a trait
Eric Torreborre
@etorreborre
You can use the AroundEach trait for that
class MySpec extends mutable.Specification with SkipAll {
  "this is ok" >> ok
  "this is ko" >> ko
}

import org.specs2.specification._
import org.specs2.execute._

trait SkipAll extends AroundEach {
  def around[R : AsResult](r: =>R) =
    Skipped("skipped")
}
Eric Torreborre
@etorreborre
@ChristopherDavenport if you want to try out the latest release: https://repo1.maven.org/maven2/org/specs2/specs2-core_2.13/4.10.0/
Christopher Davenport
@ChristopherDavenport
@etorreborre So the only way I see by Future to get to Result is via await. How do you evaluate the Future[Result] for the specs and is there a way I could create similar functionality for IO? I'm missing a piece of code somewhere but I'm not sure where it is inside the specs2 repo.
Eric Torreborre
@etorreborre
Sorry this is not necessarily super well documented but you can use the AsExecution typeclass to integrate IO:

import org.specs2.execute.{AsResult}
import org.specs2.specification.core.{AsExecution, Execution}
import scala.concurrent._

case class IO[T](run: ExecutionContext => Future[T])

object IO {
  def successful[T](t: =>T): IO[T] =
    IO(_ => Future.successful(t))

  implicit def ioAsExecution[R : AsResult]: AsExecution[IO[R]] = new AsExecution[IO[R]] {
    def execute(io: =>IO[R]): Execution =
      Execution.withEnvAsync(env => io.run(env.executionContext))
  }
}


class TestMutableSpec extends mutable.Specification {

  "e1" >> {
    IO.successful(ok)
  }

}
Raphael Mäder
@randm-ch
:wave: I have this exact problem with specs2-mock: https://stackoverflow.com/questions/49070901/mocking-a-method-which-returns-an-fs2-stream
Is there a remedy? I can't use the solution suggested by the answerers since the API is fix. Thank you.