Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Dec 09 09:22
    Travis etorreborre/specs2 (specs2-five) errored (2037)
  • Dec 09 08:57

    etorreborre on specs2-five

    (compare)

  • Dec 08 20:11
    Travis etorreborre/specs2 (specs2-five-remove-eff) errored (2036)
  • Dec 08 19:47

    etorreborre on specs2-five-remove-eff

    use suml where possible simplified the Reporter interfa… made a component for the Select… and 11 more (compare)

  • Dec 03 12:15
    Travis etorreborre/specs2 (specs2-five-remove-eff) errored (2035)
  • Dec 03 11:52

    etorreborre on specs2-five-remove-eff

    fixed more specs everything is compiling passing the core-js tests and 8 more (compare)

  • Nov 30 17:12
    Travis etorreborre/specs2 (master) passed (2034)
  • Nov 30 16:22

    etorreborre on master

    Update mockito-core to 3.2.0 (#… (compare)

  • Nov 30 16:22
    etorreborre closed #789
  • Nov 30 14:18
  • Nov 30 09:03
    etorreborre commented #788
  • Nov 30 05:03
    Synesso commented #788
  • Nov 30 05:02
    Synesso commented #788
  • Nov 30 05:02
    Synesso commented #788
  • Nov 30 03:55
  • Nov 30 03:06
    scala-steward opened #789
  • Nov 29 14:48
    Travis etorreborre/specs2 (SPECS2-4.7.1) passed (2032)
  • Nov 29 14:10
    etorreborre commented #788
  • Nov 29 14:00

    etorreborre on SPECS2-4.7.1

    (compare)

  • Nov 29 13:54

    etorreborre on 2.12

    (compare)

Gunnar Lilleaasen
@heksesang
@ChristopherDavenport I tested the immutable spec, and sort of liked having that list of tests defind at the top. Made it easier to get an overview of what tests are defined.
But by the sound of it, it just comes down to preference.
If you prefer to have them all defined in one place or split up.
Eric Torreborre
@etorreborre
Yes that’s exactly it. This depends on how you prefer to have your “test narration"
Mohamedali10
@Mohamedali10
hello, is it possible to test the content of a file, like the presence of a node in the xml file?
Eric Torreborre
@etorreborre
There are some matchers for checking the contents of files but it’s only line by line: https://etorreborre.github.io/specs2/guide/SPECS2-4.2.0/org.specs2.guide.Matchers.html#file-contents
if you want to check XML, you can search for the Xml tab on the table
Mohamedali10
@Mohamedali10
ok thanks I will try
Mohamedali10
@Mohamedali10

Hello, what if I want to test the content of a file, this file is returned by a rest call: for example :

  def downloadReport(fileName: String) = Action {
    implicit request =>
    val file  = new File("/tmp/"+ fileName)
    if(file.exists()) {
      val dataContent: Enumerator[Array[Byte]] = Enumerator.fromFile(file)
      Ok.chunked(dataContent) withHeaders(
        "Content-Disposition" -> s"attachment;filename=$fileName")
    } else {
      json(ReportNotFound("/tmp/"+ fileName))
    }
  }

my file contain a line "hello world!", i want tocheck if is contentcorrect after calling the api

Eric Torreborre
@etorreborre
If that file is returned by a REST call that means that you have some corresponding code calling this downloadReport endpoint, right? Then I would say it depends on the HTTP client library you use to access this endpoint but most libraries can do a GET and get back some String I suppose. I guess I don’t understand exactly what is your difficulty and what you expect from specs2 in that situation
Mohamedali10
@Mohamedali10
@etorreborre correct Iam using a GET that returns array of Bytes
Sergey Torgashov
@satorg

Hey, It seems I have encountered some weird behavior while checking arrays for emptiness, consider example:

  "expected behavior" >> {
    List.empty[Int] must not be empty // fails as expected
  }
  "unexpected behavior" >> {
    Array.empty[Int] must not be empty // does not fail, passes successfully
  }

So for lists this must not be empty matcher works as expected, but not for arrays.
It isn't clear for me, what is the difference in these two cases...
specs2 4.7.1
cc @etorreborre

Sergey Torgashov
@satorg

What is even more weird for me, this expressions fails as expected:

Array.emptyIntArray must not beEmpty

(compare to the previous one, which doesn't):

Array.emptyIntArray must not be empty

I would expected that these two must be equivalent

Eric Torreborre
@etorreborre
This is a bug indeed, I fixed it on master. Thanks for reporting it!
Dave Stevens
@drstevens
Hi, I'm sure this probably gets asked all the time, but is there a way to have scalacheck classification output when executing tests with specs2?

e.g.

import org.scalacheck.{Gen, Prop}
import org.specs2.ScalaCheck
import org.specs2.mutable.Specification

class FooSpec extends Specification with ScalaCheck {
  "Some test" >> Prop.forAll(Gen.choose[Int](0, 10), Gen.choose[Int](0, 10)) { (a, b) =>
    Prop.classify(a == b, "Equal", "NotEqual") {
      1 ==== 1
    }
  }
}

It's entirely possible I'm using classify incorrectly here

... or

class FooSpec extends Specification with ScalaCheck {
  "Some test" >> Prop.forAll(Gen.choose[Int](0, 10), Gen.choose[Int](0, 10)) { (a, b) =>
    Prop.collect(if (a == b) "Equal" else "NotEqual") {
      1 ==== 1
    }
  }
}
Dave Stevens
@drstevens

It seems I was missing display()

import org.scalacheck.{Gen, Prop}
import org.specs2.ScalaCheck
import org.specs2.mutable.Specification

class FooSpec extends Specification with ScalaCheck {
  "Some test" >> Prop
    .forAll(Gen.choose[Int](0, 2), Gen.choose[Int](0, 2)) { (a, b) =>
      Prop.collect(if (a == b) "Equal" else "NotEqual") {
        1 ==== 1
      }
    }.display()
}

results in

[info] FooSpec
[info] + Some test
[info] OK, passed 100 tests.
[info] > Collected test data:
[info] 67% NotEqual
[info] 33% Equal
[info] Total for specification FooSpec
Eric Torreborre
@etorreborre
Sorry I just saw your message now, glad you found it!
Brian P. Holt
@bpholt
I'm having trouble finding ScalaJS artifacts for specs2-cats later than 4.3.5. It doesn't look like the catsJS subproject is part of the main aggregate in the specs2 build.sbt—is that intentional?
Eric Torreborre
@etorreborre
Brian P. Holt
@bpholt
That’s 4.3.5, but I didn’t see anything newer than that (including any Scala 2.13 artifacts)
Eric Torreborre
@etorreborre
Sorry I can’t read messages… I’ll investigate tomorrow
Eric Torreborre
@etorreborre
@bpholt here you go: https://repo1.maven.org/maven2/org/specs2/specs2-cats_sjs0.6_2.12/4.8.0. I think cats was temporarily removed because it wasn’t compiling with 2.13
Brian P. Holt
@bpholt
:tada: thanks!
Mohamedali10
@Mohamedali10
Hello, How to test the hiearachy of an xml element, for example:
   val xmlToTest =
      <project>
        <theme id="1">
          <numbering>1</numbering>
          <name>theme1</name>
          <path>/1</path>
          <subject id="1.1">
            <numbering>1.1.1</numbering>
            <name>subject2</name>
            <path>/1/1.1</path>
          </subject>
        </theme>
        <theme id="2">
          <numbering>2</numbering>
          <name>theme2</name>
          <path>/2</path>
          <subject id="2.1">
            <numbering>2.1.1</numbering>
            <name>subject2</name>
            <path>/2/2.1</path>
          </subject>
        </theme>
      </project>

    xmlToTest must \\("subject", "id"->"2.1")
  I want not only to verify  the existance of subject with id 2 but also its existance under theme with id 2
Eric Torreborre
@etorreborre
This should work
xmlToTest must \\("theme", "id"->"2") \\("subject", "id"->"2.1”)
Mohamedali10
@Mohamedali10
that works thanks :)
Mohamedali10
@Mohamedali10

Hello, I want to verify for the xmlToTest variable (shown above) that the name node: subject2, the path node: \2.1.1 and the numbering node: 2.1.1 belongs to the subject node with id ="2", I tried the following:

 xmlToTest must \\("theme", "id"->"2") \\("subject", "id"->"2.1")\\("numbering")\>("2.1.1") and \\ ("name")\>("subject2") and \\("path")\>("2.2.1")

this works but not like I wanted since the and \\ will look anywhere in the xmlToTest node and I just wanted to look in the theme id ="2" node.

Matthew de Detrich
@mdedetrich
How does binary compatibility work with specs2, i.e. is specs2 4.8.0 binary compatible with specs2 4.7.0?
Eric Torreborre
@etorreborre
I don’t have a good story for binary compatibility because I never implemented something like MiMa. That being said 4.8.0 should be binary compatible with 4.7.0.
Matthew de Detrich
@mdedetrich
Seems to be the case, many thanks!
Eric Torreborre
@etorreborre
@Mohamedali10 I don’t think the current matchers support this use case. You can try to factor out val matchPath = \\("theme", "id"->"2”) and then write 2 assertions xmtToTest must matchPath \\("subject", "id"->"2.1")\\("numbering")\>("2.1.1”) and matchPath \\("name")\>("subject2") and matchPath \\("path")\>("2.2.1”) (If I understand correctly)
Mohamedali10
@Mohamedali10
@etorreborre thanks I found a way for that, Ihave anohter question please:
How to test the content of a zip file rendered by a rest call, for example test a call that downloads zip file?
Christian Kaps
@akkie

Is it possible to extend a ForEach[A] context with another ForEach[B] context. I would like to build a new context based on the Play ForServer context. Something like this:


final case class TestEnvironment(runningServer: RunningServer, processEngine: ProcessEngine)

trait WithProcessEngine extends ForEach[TestEnvironment] with ServerGrpcClient {
  self: ForServer =>
  def foreach[R: AsResult](f: TestEnvironment => R): Result = {
    self.foreach { rs: RunningServer =>
      val processEngine = rs.app.injector.instanceOf[ProcessEngine]
      val environment = TestEnvironment(rs, processEngine)
      f(environment)
    }
  }
}

Problem is that the code doesn't compile because of a missing implicit:

could not find implicit value for evidence parameter of type org.specs2.specification.core.AsExecution[test.TestEnvironment => org.specs2.matcher.MatchResult[Option[io.setu.caribou.grpc.deployment.Deployment]]]
I think the error comes from the fact that two ForEachcontexts are in scope. Is there another way to handle such scenario?
Eric Torreborre
@etorreborre

Hi Christian, here is a reduced example which might help:

package org.specs2
package specification

import execute._

class EachContextSpec extends Specification with TransactionContext { def is = s2"""

  A Foreach context can be used directly in a specification $e1
  A Foreach context can reuse another one for its definition $e2

"""

  lazy val databaseContext = new DatabaseContext {}

  def e1 = databaseContext.foreach { t: Database =>
    success
  }

  def e2 = { t: Transaction =>
    success
  }

}

case class Database() {
  def newTransaction: Transaction = Transaction()
}
case class Transaction()

trait DatabaseContext extends ForEach[Database] {
  def foreach[R: AsResult](f: Database => R): Result = {
    val database = openDatabase
    try AsResult(f(database))
    finally closeDatabase(database)
  }

  def openDatabase: Database = Database()
  def closeDatabase(db: Database) = ()
}

trait TransactionContext extends ForEach[Transaction] {
  private lazy val databaseContext = new DatabaseContext {}

  def foreach[R: AsResult](f: Transaction => R): Result =
    databaseContext.foreach(db => f(db.newTransaction))
}

If the ForEach definitions can be instantiated as stand-alone objects, they can be used explicitely in a spec or to define other ForEach contexts.

@Mohamedali10

How to test the content of a zip file rendered by a rest call, for example test a call that downloads zip file?
Well I think that can be tedious but you need to do exactly what you describe: set-up a file on the server, call the function to download it as a zip file, unzip it in a temp directory, read the file contents and check that it is correct. This is more or less all using regular Scala code, except for an assertion on strings at the end to check the content.

Mohamedali10
@Mohamedali10
@etorreborre I resolved like you said thanks
Matthew de Detrich
@mdedetrich
So I just upgraded to Specs 2 4.8.0 and I am getting this error
[error] Note that implicit conversions are not applicable because they are ambiguous:
[error]  both method theValue in trait MustExpectations1 of type [T](t: => T)org.specs2.matcher.MustExpectable[T]
[error]  and method thisValue in trait ShouldExpectations of type [T](t: => T)org.specs2.matcher.ShouldExpectable[T]
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