0

I'm trying to test a Json with Specs2 but I always get a parse error.

Maybe because I use a JObect?

val j: JObject = "hello" -> "world"
j must */("hello")

this is the error:

Search_fields

Could not parse:
JObject(List(JField(hello,JString(world))))
java.lang.Exception: Could not parse:
JObject(List(JField(hello,JString(world))))
    at net.liftweb.echidnasearch.QuerySearchSpec$$anonfun$1$$anonfun$apply$124.apply(QuerySearchSpec.scala:496)
    at net.liftweb.echidnasearch.QuerySearchSpec$$anonfun$1$$anonfun$apply$124.apply(QuerySearchSpec.scala:485)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

MatchQuery

thanks

YoBre
  • 2,520
  • 5
  • 27
  • 37

2 Answers2

1

specs2 json matchers are Matcher[String]. I suspect that what you are seeing is an attempt to parse the .toString representation of the Lift Json object which is not parseable by the specs2 matcher. You should match instead against a proper String representation of the Lift Json object.

Eric
  • 15,494
  • 38
  • 61
0

If you mean a compile error, then check all imports and try again:

import net.liftweb.json.JsonDSL._
import net.liftweb.json._
val t:JObject = ("a" -> "b")

I tried this in the console, it works:

scala> val t:JObject = ("a" -> "b")
t: net.liftweb.json.JObject = JObject(List(JField(a,JString(b))))
VasiliNovikov
  • 9,681
  • 4
  • 44
  • 62
  • i've the same situation. In compilation i don't have errors. My problem is in runtime. – YoBre Sep 27 '13 at 13:09
  • I don't know the syntax of spec2, but something like this should work: `t.\("a") should === "b"`. In your code, I see the word "world" only once (shouldn't it be compared to?), and I don't see the method ".\" at all. – VasiliNovikov Sep 27 '13 at 16:11