Test failing with 2.3.11

368 views
Skip to first unread message

Mario Camou

unread,
Apr 22, 2014, 7:30:46 PM4/22/14
to specs2...@googlegroups.com
Hi all,

The following test (using Specs2RouteTest from Spray):

"Return a List of groups IDs with no parameter" in {
      Get("/group") ~> route ~> check {
                                        val resp = responseAs[Seq[Map[String,String]]]
                                        groups.map { g =>
                                          resp must contain(havePairs("id" -> g.id,
                                                                      "name" -> g.name))
                                                   }
                                      }

 passes correctly in 2.3.10 but fails to compile correctly in 2.3.11 with the following error:

Error:(25, 53) could not find implicit value for evidence parameter of type org.specs2.execute.AsResult[List[org.specs2.matcher.MatchResult[Seq[Map[String,String]]]]]
    "Return a List of groups IDs with no parameter" in {
                                                    ^

groups is a List[Group] (where Group is a case class I have defined in my project).

Any ideas?

Mario Camou

unread,
Apr 22, 2014, 7:41:51 PM4/22/14
to specs2...@googlegroups.com
This with Scala 2.10.4 and Spray 1.3.1

etorreborre

unread,
Apr 22, 2014, 7:43:55 PM4/22/14
to specs2...@googlegroups.com
A few implicit definitions have been moved around in 2.3.11 to simplify things and I don't know why this is not working anymore really.

What you need is an implicit like that to transform the list of results to one single result:

import org.specs2.execute._

implicit def resultsSeq[R : AsResult]: AsResult[Seq[R]] = new AsResult[Seq[R]] {
   def asResult(seq: Seq[R]) = 
      if (seq.isEmpty) Success()
      else seq.map(AsResult.apply).reduce(_ and _)
}

You need to test that code and possibly specialise it from Seq to List to make things work.

Eric.

Mario Camou

unread,
Jun 3, 2014, 7:08:55 AM6/3/14
to specs2...@googlegroups.com
Sorry it took so long to reply. I got swamped by work and left specs2 2.3.10 in until I resolved the issue.

The example you sent gave me some trouble with implicits, but it put me on the right track. In the end I lifted the following from the org.specs2.matcher.MatchResult object (which is marked as private) and specialized the Seq to List to make it work:

trait SpecsUtil {
  implicit def matchResultListAsResult[T]: AsResult[List[MatchResult[T]]] = new AsResult[List[MatchResult[T]]] {
    def asResult(t: =>List[MatchResult[T]]): Result = t.foldLeft(StandardResults.success: Result)(_ and _.toResult)
  }
}

I then mixed in the trait into my Specifications and everything seems to work fine with specs2 2.3.12.

Thanks for your help,
-Mario.

-Mario.

--
I want to change the world but they won't give me the source code.


--
You received this message because you are subscribed to a topic in the Google Groups "specs2-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/specs2-users/TYmmWtC4frc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to specs2-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jamie Swain

unread,
Dec 30, 2014, 9:55:22 PM12/30/14
to specs2...@googlegroups.com
I'm trying to build a working test with specs2 and the lift web framework that will test some RestHelper endpoints.
I'm trying to use this code here:
to make web testing work with specs2

I came across the example in the previous message, but it doesn't seem to be working with specs 2.3.12.  
It looks like the "and" in your function is private in the specs framework.  
Any idea how to work around this?

etorreborre

unread,
Dec 31, 2014, 4:23:32 AM12/31/14
to specs2...@googlegroups.com
If you import the functions in the org.specs2.execute.ResultLogicalCombinators object then you should have access to the "and" method.

That being said, the org.specs2.matcher.MatchResult object contains an implicit def for AsResult[Seq[MatchResult[T]]] (at least in the most recent specs2 version which is 2.4.15):

/** implicit typeclass instance to create examples from a sequence of MatchResults */
implicit def matchResultSeqAsResult[T]: AsResult[Seq[MatchResult[T]]] = new AsResult[Seq[MatchResult[T]]] {
def asResult(t: =>Seq[MatchResult[T]]): Result = t.foldLeft(StandardResults.success: Result)(_ and _.toResult)
}

Eric.

Jamie Swain

unread,
Dec 31, 2014, 1:23:26 PM12/31/14
to specs2...@googlegroups.com
Hi Eric,

Thanks so much for the quick response!  I actually realized late last night that I was overlooking an obvious thing--that the WebSpec extensions for Lift were now available as a Lift module, and that works correctly with Specs2.  (My mistake was thinking I needed to use the one from that gist myself, that was for in the past before Lift had it integrated.)  Sorry for the inconvenience!!  I'm really enjoying Specs2 but still stumbling thru it b/c it's all new to me.

Thanks and happy new year!

Jamie
Reply all
Reply to author
Forward
0 new messages