These are chat archives for etorreborre/specs2

3rd
Jun 2016
Marcin Cylke
@zygm0nt
Jun 03 2016 07:06
Hi, I've got a problem with converting from specs2-2.x to specs2-3.x - this matcher does not work:
rejections must contain(exactly(expectedRejections: _*))
giving me an error saying no `: _*' annotation allowed here (such annotations are only allowed in arguments to *-parameters)
however rejections and expectedRejections are both Traversable
Eric Torreborre
@etorreborre
Jun 03 2016 07:31
@zygm0nt I cannot reproduce your error with specs2 3.8.3. But I get a compilation error if I use Traversable for expectedRejections. If I make it a Seq everything works fine.
Marcin Cylke
@zygm0nt
Jun 03 2016 07:33
well, rejections is a List and expectedRejections a Seq
Eric Torreborre
@etorreborre
Jun 03 2016 07:34
that works for me. Which specs2 version do you have exactly?
can you try 3.8.3?
Marcin Cylke
@zygm0nt
Jun 03 2016 07:34
I'm on that exact version
Eric Torreborre
@etorreborre
Jun 03 2016 07:36
and I guess rejections are like Spray Rejections?
Marcin Cylke
@zygm0nt
Jun 03 2016 07:36
yes, but I have the same compile error with a simple Seq[(String, Double)]
Eric Torreborre
@etorreborre
Jun 03 2016 07:37
can you check that the exactly method comes from TraversableMatchers?
and paste its signature here?
Marcin Cylke
@zygm0nt
Jun 03 2016 07:38
it does, the signature is
  def exactly[T](checks: ValueCheck[T]*): ContainWithResultSeq[T] = new ContainWithResultSeq(checks).exactly
Eric Torreborre
@etorreborre
Jun 03 2016 07:39
are you using that code inside a Specification or outside in another trait?
can you paste the smallest spec showing the issue?
Marcin Cylke
@zygm0nt
Jun 03 2016 07:40
I'm using it in a specification
I'm currently creating a snippet
Marcin Cylke
@zygm0nt
Jun 03 2016 08:00
unfortunately I can't produce a simple example for that :(
there may be some issue with spray interaction
Eric Torreborre
@etorreborre
Jun 03 2016 08:03
That’s what I’m thinking, there might be some implicits not playing well here. In particular, you need to go from Seq[Rejection] to Seq[ValueCheck[Rejection]]. Try to force that conversion by doing contains(exactly(expectedRejections.map(ValueCheck.typedValueCheck _):_*))
Marcin Cylke
@zygm0nt
Jun 03 2016 08:07
trying this right now
well, this worked
Eric Torreborre
@etorreborre
Jun 03 2016 08:10
This means that there must be some interaction with a Spray implicit somewhere but I am not sure what it is really
Marcin Cylke
@zygm0nt
Jun 03 2016 08:10
could you suggest how to find implicits responsible for that?
ah, ok
Eric Torreborre
@etorreborre
Jun 03 2016 08:11
or there is another overloaded exactly method somewhere which is picked up by the compiler
Do you add other specs2 traits on top of your Specification?
Marcin Cylke
@zygm0nt
Jun 03 2016 08:18
Hmm it seems Mockito is causing this behavior:
class ExactlyMatcherSpec extends Specification with Mockito {

  "this" should {
    "show the error" in {
      val expectedValues = Seq(("a", 0.2), ("b", 3.0), ("c", 4.0))
      List(("a", 3.0), ("b", 3.0), ("c", 3.0)) must contain(exactly(expectedValues: _*))
    }
  }

}
this does not compile and throws the mentioned error
Eric Torreborre
@etorreborre
Jun 03 2016 08:21
There is still another implicit messing up because your spec works for me
Sorry it works with 3.8 not 3.8.3
Marcin Cylke
@zygm0nt
Jun 03 2016 08:23
my only imports are
import org.specs2.mock.Mockito
import org.specs2.mutable.Specification
Eric Torreborre
@etorreborre
Jun 03 2016 08:27
So I suppose that the compiler is not able to solve the overloading of the exactly method for traversable matchers and the one from Mockito. So you have to desambiguate by hand
Marcin Cylke
@zygm0nt
Jun 03 2016 08:28
sad thing :worried:
moreover this somehow worked in previous version, but ok, I'll use ValueCheck
Eric Torreborre
@etorreborre
Jun 03 2016 08:30
I don’t think there were ValueChecks in the < 3.x version maybe that’s why
Marcin Cylke
@zygm0nt
Jun 03 2016 08:33
I see
thanks for helping me out with that
Eric Torreborre
@etorreborre
Jun 03 2016 09:27
You’re welcome, sorry about the disturbance, 3.x was a big leap
Marius B. Kotsbak
@mkotsbak
Jun 03 2016 11:48
Hi
How is the recommended way of reusing test for different data/implementations of the same interface?
I could not find anything in the docs
Eric Torreborre
@etorreborre
Jun 03 2016 13:28
@mkotsbak You can define specification “Fragments” taking an object as a parameter
def specFor(component: Component) = s2”””
   it should do this ${doThis(component)}
   it should do that ${doThat(component)}

class MySpec extends Specification { def is = s2”””
    tests for component A ${specFor(componentA)}
    tests for component B ${specFor(componentB)}
“”"
Another approach is to use the ForEach[T] trait
and run the same test passing different implementations of T
this is all done in the foreach method of ForEach[T] and then you have to decide on the strategy you want for failures. Stop after the first one or accumulate them.