Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
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.
Sergey Torgashov
@satorg

Hey everyone. I wonder, is it possible to create a one-column Table with some DSL? I mean the following doesn't work because it cannot differentiate where header ends and actual rows begin:

class MyFancySpec extends mutable.Specification with mutable.Tables {
  "should be fine for every valid string value" in {
    "Valid String" |
    "valid-str-1" |
    "valid-str-2" |
    "valid-str-3" |> { validStr =>
      myTestee(validStr) must beFine
    }
  }
}

Is it possible to achieve something like this somehow?

Eric Torreborre
@etorreborre
@satorg if you just have a list of values the best is to use Result.foreach: https://etorreborre.github.io/specs2/guide/SPECS2-4.2.0/org.specs2.guide.ForLoops.html
Sergey Torgashov
@satorg
@etorreborre yes, I was looking for something like this. Thanks!
Sergey Torgashov
@satorg
Hey guys. One more question about tables please. I'd like to have something like inner tables to let each outer table row being tested along with each inner table row. Very simple and synthetic example below:
  def testee(foo: Int, bar: Int): String = s"foo$foo,bar$bar"

  "simple" >> {
    "foo" | "result" |
      1 ! "foo1" |
      2 ! "foo2" |
      3 ! "foo3" |> { (foo, fooRes) =>

      "bar" | "result" |
        4 ! "bar4" |
        5 ! "bar?" |
        6 ! "bar6" |> { (bar, barRes) =>

        testee(foo, bar) must_=== s"$fooRes,$barRes"
      }
    }
  }
Sergey Torgashov
@satorg

If all cases pass then everything is just fine. But if some combination fails, then result test output provides no useful information at all:

[info] MyTableSpec
[info] x simple (39 ms)

– so it only says that the entire "simple" case fails and nothing more.
While if I do testing for a single level table, it shows much more details.

Is it possible to make output more verbose and descriptive for inner tables?
..or do it in another way somehow
Diego E. Alonso Blas
@diesalbla
Good morning.
So, Specs2 provides two ways or scopes to setup and teardown the environment for a test: for each test, and for each suite.
I am looking for a way to perform setup and teardown on resources for the whole suite of tests.
Is there a way to achieve that?
Eric Torreborre
@etorreborre

Hi @diesalbla there’s no great way to do that at the moment, it’s more like a pattern

case class MyResource(value: Int)

object Resource {
  var resource: MyResource = null

  def getResource: MyResource = {
    if (resource == null) {
      println("creating resource")
      resource = MyResource(1)
      resource
    } else resource
  }

  def closeResource() = {
    println("closing resource")
    resource = null
  }
}

class Resource1Spec extends Specification { def is =
  s2"""
    use a shared resource in spec1 $useIt
    """

  def useIt = {
    println("execute spec1")
    Resource.getResource.value === 1
  }
}

class Resource2Spec extends Specification { def is =
  s2"""
    use a shared resource in spec2 $useIt
    """

  def useIt = {
    println("execute spec2")
    Resource.getResource.value === 1
  }
}

class ResourceSpec extends Specification { def is =
  s2"""
    ${link(new Resource1Spec)}
    ${link(new Resource2Spec)}
    ${step(Resource.closeResource())}
  """
}

You need to run the ResourceSpec with the all command-line argument so that all the linked specifications are also executed

Eric Torreborre
@etorreborre
@satorg there are 2 problems here: the first one is that failed data tables should be displayed. I created an etorreborre/specs2#852 for that (it’s an easy fix). The second problem is that nested tables are not supported in terms of display. If you want to see the current output replace ”simple” >> {...} by eg {…}in your specification (this creates an “auto-example”, an example without a description, which will always show the resulting data table. Fixing this seems possible but it will take me a bit more time
Eric Torreborre
@etorreborre
@satorg can you please try 4.10.3?
Sergey Torgashov
@satorg
Oh, cool, thanks. I'll try it a bit later for sure.
Steve Jones
@sjfloat
   def underTest: Either[String,Int] = Left("The bad string")
   "catch bad string" >> {
      underTest match {
        case Right(_) => failure
        case Left(s) => s === "The bad string"
      }   
    }
I'm not sure why the above doesn't compile. Is there a more idiomatic way to do this?
The error I get is could not find implicit value for evidence parameter of type org.specs2.specification.core.AsExecution[Object]
Steve Jones
@sjfloat
nvm. beLeft(matcher) seems to be what I need.
Eric Torreborre
@etorreborre
@sjfloat indeed, the 2 branches of the pattern match have type Result and MatchResult[String] and their common ancestor is Object. specs2 tries to make it an Execution and fails to find an implicit definition for that
Diego E. Alonso Blas
@diesalbla
Hi! Looking at the manual, there is a reference to a examplesBlock method... but I cannot find it in the source code... Was it removed or replaced?
https://etorreborre.github.io/specs2/guide/SPECS2-2.4.17/org.specs2.guide.Structure.html
Eric Torreborre
@etorreborre
@diesalbla this has been replaced by Result.foreach quite some time ago now: https://etorreborre.github.io/specs2/guide/SPECS2-4.10.0/org.specs2.guide.ForLoops.html#a-list-of-results
Diego E. Alonso Blas
@diesalbla
thx,
Luís Campos
@LLCampos

Hello!
Following these docs, I've tried to run:

sbt> testOnly -- smartdiffs show,separators,triggerSize,shortenSize,diffRatio,full

But I get

[error] stack trace is suppressed; run last Test / testOnly for the full output
[error] (Test / testOnly) java.lang.IllegalArgumentException: Argument unrecognized by ScalaTest's Runner: smartdiffs
[error] Total time: 2 s, completed 30/dez/2020 11:22:38
Any ideia of what I might be doing wrong?
João Ferreira
@jtjeferreira
the error message is refering to scalatest but those are specs2 flags...
Luís Campos
@LLCampos
Yup, true. On investigation, it seems that if you have circe-testing in your dependencies, it leads to scalatest runner being used instead of specs2's. :/