Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jun 19 20:38

    github-actions[bot] on gh-pages

    Deploying to gh-pages from @ et… (compare)

  • Jun 19 20:32

    etorreborre on specs2-five

    scala3 project: adjustments to … (compare)

  • Jun 19 20:32

    etorreborre on SPECS2-5.0.0-ALPHA-00

    (compare)

  • Jun 19 18:54

    etorreborre on SPECS2-5.0.0-RC09

    (compare)

  • Jun 19 18:23

    etorreborre on specs2-five

    scala3 project: new attempt to … (compare)

  • Jun 19 18:23

    etorreborre on SPECS2-5.0.0-RC08

    (compare)

  • Jun 19 11:03

    github-actions[bot] on gh-pages

    Deploying to gh-pages from @ et… (compare)

  • Jun 19 10:56

    etorreborre on SPECS2-5.0.0-RC07

    (compare)

  • Jun 19 10:56

    etorreborre on specs2-five

    scala3 project: fixed the displ… (compare)

  • Jun 19 10:42

    github-actions[bot] on gh-pages

    Deploying to gh-pages from @ et… (compare)

  • Jun 19 10:35

    etorreborre on specs2-five

    scala3 project: fix the version… (compare)

  • Jun 19 10:35

    etorreborre on SPECS2-5.0.0-RC06

    (compare)

  • Jun 19 10:13

    github-actions[bot] on gh-pages

    Deploying to gh-pages from @ et… (compare)

  • Jun 19 10:05

    etorreborre on SPECS2-5.0.0-RC05

    (compare)

  • Jun 19 10:05

    etorreborre on specs2-five

    scala3 doc: small clean up for … scala3 project: don't clean the… (compare)

  • Jun 18 10:07

    github-actions[bot] on gh-pages

    Deploying to gh-pages from @ et… (compare)

  • Jun 18 10:00

    etorreborre on SPECS2-5.0.0-RC04

    (compare)

  • Jun 18 09:54

    etorreborre on specs2-five

    scala3 project: fixed the direc… (compare)

  • Jun 18 09:31

    etorreborre on SPECS2-5.0.0-RC03

    (compare)

  • Jun 18 09:31

    etorreborre on SPECS2-5.0.0-RC02

    (compare)

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. :/
Alex Antonov
@antonoal
Hi All. Is there a way I can embed a String from a local val into specification defined as def is = s2""" ... """? Eg I've got a val called parallelism and I'd like to use its value in the test description like s2"""Client has to handle $parallelism simultaneous requests $e1 """.
Eric Torreborre
@etorreborre
@antonoal sorry I just saw your message now. You can use .toString to display the value s2””"Client has to handle ${parallelism.toString} simultaneous requests $e1 "”".
Luís Campos
@LLCampos
@etorreborre, is beNone supposed to be supported? https://etorreborre.github.io/specs2/guide/SPECS2-4.10.0/search.html?q=beNone
Alex Antonov
@antonoal

@antonoal sorry I just saw your message now. You can use .toString to display the value s2””"Client has to handle ${parallelism.toString} simultaneous requests $e1 "”".

Thanks, I wouldn't guess it.

Andrey Ivanov
@a-nigredo
Hi all, is it possible to convert Future[List[Fragment]] into Fragments without await.result?
Luís Campos
@LLCampos
Hello everyone :) I created a repo with a summary of the Scala testing libraries ecosystem: https://github.com/LLCampos/state-of-the-art-scala-testing/ Should I add/change anything regarding specs2?
Andreas Flierl
@asflierl
specs2 definitely supports test examples that return a Future @LLCampos
Luís Campos
@LLCampos
@asflierl, you're right, found it in the docs! Will fix.
heksesang
@heksenlied:matrix.org
[m]
How far is 5.0 from release? I assume that will be the first version with proper Scala 3 support?
Sergey Torgashov
@satorg

Hi there. I'm struggling to make containTheSameElementsAs matcher working with IOMatchers:

class MySpec extends Specification with IOMatchers {
  "foo" should {
    val expected = List(123, 456, 789)
    def actual = expected.reverse

    "sync" in {
      actual must containTheSameElementsAs(expected)
    }
    "async1" in {
      IO { actual } must
        returnBefore(5.seconds).withValue(containTheSameElementsAs(expected))
    }
    "async2" in {
      IO { actual } must
        returnBefore(5.seconds).withValue((_: List[String]) must containTheSameElementsAs(expected))
    }
  }
}

Everything compiles, and looks like the compiler picks up matcherIsValueCheck conversion, but when I run this, then sync passes but both async1 and async2 fail.

How to employ it properly, could you suggest please?

Eric Torreborre
@etorreborre

Hi all, sorry for the very late responses again.
I am not using Scala professionally these days I just don't open Gitter :-(. Moreover I've had very few personal time
to work on open source for the past months. Anyway, don't hesitate to send me a message on twitter if you need an answer!

@a-nigredo

Hi all, is it possible to convert Future[List[Fragment]] into Fragments without await.result?

Here is the 5.0 way to do it (the specs2 internals have been massively simplified so they are easier to access for this kind of scenario):

val fs: Future[List[Fragment]] = Future.successful(List(example("e1", ok), example("e2", ok)))
val fragments: Fragments = Fragments(Producer.emitAction(Action.future(fs)))

For the record, Producer is a small streaming library to support streaming Fragments in specs2 and Action is an IO-like data type to support async execution.

@heksenlied:matrix.org

How far is 5.0 from release? I assume that will be the first version with proper Scala 3 support?

There is already a preview available (and it has been converted to Scala 3 indeed). I need now to:

  1. rework the release process using github actions
  2. write a migration guide (some stuff has been simplified, some specific stuff could not be done in Scala3)
  3. put back in some form some feature that have been removed (ScalaJS, cats/scalaz matchers which need to move to their own project)
  4. add proper support for resources management (the functional way, not the beforeAll way)
  5. finish an overall review pass on the User Guide

I think I am going to release some RC version as soon as point 1. is done which hopefully should not take too long now (it's Saturday, I can work on it, yay!)

@satorg this is an interesting bug for which I couldn't find a workaround (but the fix is on the way).
Basically you have 2 withValue functions on the IO TimedMatcher and the wrong one is being picked up whatever we try.

Eric Torreborre
@etorreborre
@satorg the issue is now fixed in specs2-4.12.1
Sergey Torgashov
@satorg
@etorreborre nice, thanks a lot!