Skip to content

Instantly share code, notes, and snippets.

@slorber
Last active August 29, 2015 14:07
Show Gist options
  • Save slorber/83b3b3a672dac9604b6e to your computer and use it in GitHub Desktop.
Save slorber/83b3b3a672dac9604b6e to your computer and use it in GitHub Desktop.
[stample-web] $ it:testOnly *CategoryService*
Extract /home/sebastien/.embedmongo/linux/mongodb-linux-x86_64-2.4.10.tgz START
Extract /home/sebastien/.embedmongo/linux/mongodb-linux-x86_64-2.4.10.tgz DONE
Oct 16, 2014 10:43:24 AM MongodExecutable start
INFO: de.flapdoodle.embed.mongo.config.MongodConfigBuilder$ImmutableMongodConfig@27514bba
STARTED EMBEDDED MONGODB
[info] service.CategoryServiceTest
[info] CategoryServiceTest
[info]
[info] CategoryService service getSubCategories(user,categoryId) should
[info] + get the subcategories for category owner
[info] + not get the subcategories for a random user
[info] + get the subcategories for an user having category permission, with breadcrumb not including non-shared categories
[info]
[info] CategoryService moveCategoryV2 should
[info] + permit to move a category inside another
[info] + permit to move a category inside a deep category
[info] + permit to move a deep category to the root
[info] + not permit to move a category inside itself
[info] + not permit to move a category inside its parent (as it's already there!)
[info] + not permit to move a category inside one of its childs
[info] + permit to move a shared category's child to another category's child
[info] + permit to move a shared category's child in another shared category
[info] + permit to move a shared category's child in another shared category's child
[info] x not permit to move a shared category in another shared category
[error] 'Right([Category=543f8530327c21efa8d458d2 - [Home>Sub Home>Sub Home]])' is not Left (CategoryServiceTest.scala:251)
[info]
[info] x not permit to move a shared category in another shared category's child
[error] 'Right([Category=543f8530327c21efa8d458e8 - [Home>Sub Home>Sub Sub Home>Sub Home]])' is not Left (CategoryServiceTest.scala:263)
[info]
[info] + not permit to move my category to an unshared category of another user
[info] + not permit to another user's unshared category to my category
[info] + not permit to move home into another user's shared category with READ permissions
[info] + not permit to move home into another user's shared category with WRITE permissions
[info] + not permit to move home into another user's shared category with MANAGE permissions
[info] + not permit to move home (with shared childs) into another user's shared category with READ permissions
[info] + not permit to move home (with shared childs) into another user's shared category with WRITE permissions
[info] + not permit to move home (with shared childs) into another user's shared category with MANAGE permissions
[info] + not permit to move my category into another user's shared category with READ permissions
[info] + permit to move my category into another user's shared category with WRITE permissions
[info] + permit to move my category into another user's shared category with MANAGE permissions
[info] + not permit to move my shared category into another user's shared category with READ permissions
[info] x not permit to move my shared category into another user's shared category with WRITE permissions
[error] 'Right([Category=543f8531327c21efa8d45a70 - [Home>Sub Home>Sub Home]])' is not Left (CategoryServiceTest.scala:311)
[info]
[info] x not permit to move my shared category into another user's shared category with MANAGE permissions
[error] 'Right([Category=543f8531327c21efa8d45a90 - [Home>Sub Home>Sub Home]])' is not Left (CategoryServiceTest.scala:311)
[info]
[info] + not permit to move my shared category's child into another user's shared category with READ permissions
[info] + permit to move my shared category's child into another user's shared category with WRITE permissions
[info] + permit to move my shared category into another user's shared category with MANAGE permissions
[info] + not permit to move my category containing shared childs into another user's shared category with READ permissions
[info] x not permit to move my category containing shared childs into another user's shared category with WRITE permissions
[error] 'Right([Category=543f8532327c21efa8d45b34 - [Home>Sub Home>Sub Home]])' is not Left (CategoryServiceTest.scala:311)
[info]
[info] x not permit to move my category containing shared childs into another user's shared category with MANAGE permissions
[error] 'Right([Category=543f8532327c21efa8d45b55 - [Home>Sub Home>Sub Home]])' is not Left (CategoryServiceTest.scala:311)
[info]
[info] + not permit to move a shared category of another user with READ permission
[info] x not permit to move a shared category of another user with WRITE permission
[error] 'Right([Category=543f8532327c21efa8d45b9e - [Home>Sub Home]])' is not Left (CategoryServiceTest.scala:486)
[info]
[info] x not permit to move a shared category of another user with MANAGE permission
[error] 'Right([Category=543f8532327c21efa8d45bbd - [Home>Sub Home]])' is not Left (CategoryServiceTest.scala:486)
[info]
[info] + not permit to move a shared category's child of another user that he created, with READ permission
[info] + permit to move a shared category's child of another user that he created, with WRITE permission
[info] + permit to move a shared category's child of another user that he created, with MANAGE permission
[info] + not permit to move a shared category's child of another user I he created, with READ permission
[info] + permit to move a shared category's child of another user that I created, with WRITE permission
[info] + permit to move a shared category's child of another user that I created, with MANAGE permission
[info]
[info] Total for specification CategoryServiceTest
[info] Finished in 6 seconds, 611 ms
[info] 43 examples, 8 failures, 0 error
[info] + service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info] x service.CategoryServiceTest
[info] x service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info] x service.CategoryServiceTest
[info] x service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info] x service.CategoryServiceTest
[info] x service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info] x service.CategoryServiceTest
[info] x service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info] + service.CategoryServiceTest
[info]
[info]
[info] Total for test service.CategoryServiceTest
[info] Finished in 7.543 seconds
[info] 43 tests, 8 failures, 0 errors
SHUTDOWN EMBEDDED MONGODB
Oct 16, 2014 10:43:31 AM de.flapdoodle.embed.mongo.AbstractMongoProcess stopInternal
INFO: try to stop mongod
Oct 16, 2014 10:43:31 AM de.flapdoodle.embed.process.io.file.Files forceDelete
INFO: Could delete /tmp/embedmongo-db-86c3cd73-72fb-4f25-9a98-10f68b2c8a79
Oct 16, 2014 10:43:31 AM de.flapdoodle.embed.process.io.file.Files forceDelete
INFO: Could delete /tmp/extract-sebastien-mongod.pid
[error] Failed: Total 43, Failed 8, Errors 0, Passed 35
[error] Failed tests:
[error] service.CategoryServiceTest
[error] (stample-web/it:testOnly) sbt.TestsFailedException: Tests unsuccessful
[error] Total time: 10 s, completed Oct 16, 2014 10:43:31 AM
[stample-web] $ Oct 16, 2014 10:43:32 AM de.flapdoodle.embed.process.io.file.Files forceDelete
INFO: Could delete /tmp/extract-sebastien-mongod
[stample-web] $ it:testOnly *CategoryService* -- -ex ".*"
Extract /home/sebastien/.embedmongo/linux/mongodb-linux-x86_64-2.4.10.tgz START
Extract /home/sebastien/.embedmongo/linux/mongodb-linux-x86_64-2.4.10.tgz DONE
Oct 16, 2014 10:44:40 AM MongodExecutable start
INFO: de.flapdoodle.embed.mongo.config.MongodConfigBuilder$ImmutableMongodConfig@467a68f5
STARTED EMBEDDED MONGODB
[info] service.CategoryServiceTest
[info] CategoryServiceTest
[info]
[info]
[info] CategoryService service getSubCategories(user,categoryId) should
[info]
[info]
[info]
[info]
[info] CategoryService moveCategoryV2 should
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info]
[info] Total for specification CategoryServiceTest
[info] Finished in 221 ms
[info] 0 example, 0 failure, 0 error
[info]
[info]
[info] Total for test service.CategoryServiceTest
[info] Finished in 1.042 seconds
[info] 0 tests, 0 failures, 0 errors
SHUTDOWN EMBEDDED MONGODB
Oct 16, 2014 10:44:42 AM de.flapdoodle.embed.mongo.AbstractMongoProcess stopInternal
INFO: try to stop mongod
Oct 16, 2014 10:44:42 AM de.flapdoodle.embed.process.io.file.Files forceDelete
INFO: Could delete /tmp/embedmongo-db-ab3f9072-d17d-4dd6-8a0f-35adaaf719d5
Oct 16, 2014 10:44:42 AM de.flapdoodle.embed.process.io.file.Files forceDelete
INFO: Could delete /tmp/extract-sebastien-mongod.pid
[info] Passed: Total 0, Failed 0, Errors 0, Passed 0
[success] Total time: 3 s, completed Oct 16, 2014 10:44:42 AM
[stample-web] $ Oct 16, 2014 10:44:49 AM de.flapdoodle.embed.process.io.file.Files forceDelete
INFO: Could delete /tmp/extract-sebastien-mongod
@slorber
Copy link
Author

slorber commented Oct 16, 2014

I'm using a multi-project build (using project stample-web before the tests) and running the test with the it sbt config for integration tests, but I reproduced the same problem with regular unit tests.

I've tried different versions of specs2 and get the same issue.
Note that I was not able to use specs2 > 2.4.2 as I get this SBT dependency issue:
[error] (stample-web/*:update) sbt.ResolveException: unresolved dependency: org.scalaz.stream#scalaz-stream_2.10;0.5a: not found
Perhaps it's because I already have a version of Scalaz in my classpath?

    "org.specs2" %% "specs2" % "2.4.2" % "test,it",
    "org.scalaz" %% "scalaz-core" % "7.0.6",

There seems to be an empty log line for every exemple of my spec, so it seems like Specs2 is swallowing some internal error and not failing fast, with a fallback to empty string or something?

Note that I reproduce this issue on all tests with testOnly * -- -ex ".*", even on this one:

class UsernameUtilsTest extends Specification {

  "The username" should {

    "be valid when only lowercase chars and numbers" in {
      UsernameUtils.isValid("sebastien123toto2") must beTrue
    }
    "be invalid when having uppercase chars" in {
      UsernameUtils.isValid("sebasTien123toto2") must beFalse
    }
    "be invalid when having too much characters" in {
      UsernameUtils.isValid("sebastien123toto2qsdqdqskljjklsjeksjklgslkjskhkj") must beFalse
    }
    "be invalid when having too few characters" in {
      UsernameUtils.isValid("se") must beFalse
    }
    "be invalid when having space" in {
      UsernameUtils.isValid("sebastien 123toto2") must beFalse
    }
    "be invalid when having diacritics (accents)" in {
      UsernameUtils.isValid("sébastien 123toto2") must beFalse
    }
  }

}

So I guess my project "layout" can be responsible of this problem. I have 2 test folders: test/unit and test/integration with the following SBT config:

  lazy val stampleWebProject = play.Project("stample-web", appVersion, appDependencies,path = file("stample-web"),settings = playSettings)
    .dependsOn(stampleSearchProject)
    .settings(defaultScalaSettings:_*)
    .settings(
      scalacOptions ++= Seq("-Xmax-classfile-name", "140"),
      ideaExcludeFolders := ideaFoldersToExclude,
      // logBuffered in Test := false,
      scalaSource in Test <<= baseDirectory / "test/unit",
      javaSource in Test <<= baseDirectory / "test/unit",
      sourceDirectory in Test <<= baseDirectory / "test/unit",
      parallelExecution in Test := false, // TODO should be removed for unit tests i guess!
      testOptions in Test += Tests.Argument("sequential")
      //javaOptions in Test += "-Xmx256m -XX:MaxPermSize=256m"
    )
    .configs(IntegrationTest)
    .settings( Defaults.itSettings : _*)
    .settings(
      // logBuffered in IntegrationTest := false,
      testOptions in IntegrationTest += Tests.Setup( () => StampleBuildTools.setupMongo() ),
      testOptions in IntegrationTest += Tests.Cleanup( () => StampleBuildTools.shutdownMongo ),
      scalaSource in IntegrationTest <<= baseDirectory / "test/integration",
      javaSource in IntegrationTest <<= baseDirectory / "test/integration",
      sourceDirectory in IntegrationTest <<= baseDirectory / "test/integration",
      parallelExecution in IntegrationTest := false,
      testOptions in IntegrationTest += Tests.Argument("sequential") ,

      routesImport += "_root_.utils.binders._",
      routesImport += "org.bson.types.ObjectId"
      //javaOptions in IntegrationTest += "-Xmx256m -XX:MaxPermSize=256m"
    )

@etorreborre
Copy link

Two things here:

1. you can solve the scalaz-stream issue by either
- just using specs2-core instead of specs2 as your dependency
- add the bintray resolver

lazy val resolversSettings = resolvers ++=
    Seq(Resolver.sonatypeRepo("releases"), 
        Resolver.sonatypeRepo("snapshots"),
        Resolver.typesafeIvyRepo("releases"),
        "scalaz-bintray" at "http://dl.bintray.com/scalaz/releases")

2. For the arguments I suggest that you try the following

  • no quotes test-only * -- -ex .*
  • no "dash ex" test-only * -- ex .*
  • additional double-dashes test-only * -- -ex .* --

The third case is something that I observed on another project. When using Tests.Arguments in the sbt configuration then -ex arguments fail to be properly parsed. If I remember correctly using -- right after helped.

@slorber
Copy link
Author

slorber commented Oct 16, 2014

No quotes: test-only * -- -ex .*diacritics.*: NOK
No dash: test-only * -- ex .*diacritics.*: OK
Additional double-dash: test-only * -- -ex .*diacritics.* --: OK

No quotes: it:test-only *CategoryService* -- -ex .*deep.*: NOK
No dash: it:test-only *CategoryService* -- ex .*deep.*: OK
Additional double-dash: test-only *CategoryService* -- -ex .*deep.* --: OK

So it seems weird but the last solution does not work with my it config.
The "no dash" solution works fine with both configs, and works with quotes too (however I'm not sure of the behavior I see when using spaces in the regex)

Thanks :)

@etorreborre
Copy link

Good to know that you have a solution. Just a note: arguments passing is a bit ad-hoc and primitive in specs2. Historically only ex was there but you could not use spaces (I actually think it is a bug now I should look into it). Then I added -ex aaaa bbb ccc where aaaa bbb ccc would be caught as the argument for -ex and if you wanted to add other arguments you would have to add --: -ex aaaa bbb ccc -- sequential. I'll put a note for myself to at least document that in the next version.

@slorber
Copy link
Author

slorber commented Oct 16, 2014

but it is kind of hard to match exemples with spaces.

it:test-only service.CategoryServiceTest -- ex "not permit to move a category inside itself"

It seems like it matches on .*not.*, only the first term is taken.

I have to do:
it:test-only service.CategoryServiceTest -- ex "not\\spermit\\sto\\smove\\sa\\scategory\\sinside\\sitself"

So for long strings where many special regex chars, it forces me to add some "key" to my exemples to be able to match them easily.

So I think it may be cool to have some feature, a bit like pendingUntilFixed but the opposite, something like executeThisExempleButNotOthers.
This would be cool to easily be able to focus on a given test to debug it.

You have to recompile the test, but at least it would be easier than having to find the appropriate regexp in some cases.

@etorreborre
Copy link

Note that a very low-tech alternative to this is to add on special character to your description, like @ and go test-only -- ex @.

@slorber
Copy link
Author

slorber commented Oct 17, 2014

Note that moving from dependency specs2 to specs2-core has broken my unit tests (but not my integration tests).

java.lang.NoSuchMethodError: org.specs2.runner.Fingerprints$.fp1()Lorg/specs2/runner/SpecificationFingerprint;
    at org.specs2.runner.Specs2Framework.fingerprints(SbtRunner.scala:23)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)

Any idea?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment