From 762f7463cd7708fe69d033190aa619ee014c34b6 Mon Sep 17 00:00:00 2001 From: Naftoli Gugenheim Date: Mon, 30 Jul 2012 21:11:58 -0400 Subject: [PATCH] lift-webkit --- .../http/testing/MockHttpRequestSpec.scala | 5 +- .../scala/net/liftweb/mockweb/MockWeb.scala | 2 +- .../scala/net/liftweb/mockweb/WebSpec.scala | 38 +++++-------- .../net/liftweb/builtin/snippet/MsgSpec.scala | 6 ++- .../liftweb/builtin/snippet/MsgsSpec.scala | 6 ++- .../scala/net/liftweb/http/BindingsSpec.scala | 7 +-- .../net/liftweb/http/FactoryMakerSpec.scala | 5 +- .../liftweb/http/NamedCometPerTabSpec.scala | 10 ++-- .../test/scala/net/liftweb/http/ReqSpec.scala | 12 ++--- .../net/liftweb/http/ResourceServerSpec.scala | 6 ++- .../scala/net/liftweb/http/SHtmlSpec.scala | 9 ++-- .../scala/net/liftweb/http/SnippetSpec.scala | 8 ++- .../scala/net/liftweb/http/js/JsExpSpec.scala | 6 ++- .../js/extcore/ExtCoreArtifactsSpec.scala | 5 +- .../net/liftweb/http/rest/XMLApiSpec.scala | 16 +++--- .../net/liftweb/mockweb/MockWebSpec.scala | 10 ++-- .../net/liftweb/mockweb/WebSpecSpec.scala | 29 +++++----- .../scala/net/liftweb/sitemap/LocSpec.scala | 5 +- .../net/liftweb/sitemap/MenuDSLSpec.scala | 5 +- .../liftweb/webapptest/JettyTestServer.scala | 2 +- .../net/liftweb/webapptest/MemoizeSpec.scala | 8 +-- .../net/liftweb/webapptest/OneShot.scala | 13 ++--- .../net/liftweb/webapptest/ToHeadUsages.scala | 53 ++++++++----------- .../scala/net/liftweb/wizard/WizardSpec.scala | 5 +- 24 files changed, 136 insertions(+), 135 deletions(-) diff --git a/web/testkit/src/test/scala/net/liftweb/http/testing/MockHttpRequestSpec.scala b/web/testkit/src/test/scala/net/liftweb/http/testing/MockHttpRequestSpec.scala index 094c740836..29bcdd376b 100644 --- a/web/testkit/src/test/scala/net/liftweb/http/testing/MockHttpRequestSpec.scala +++ b/web/testkit/src/test/scala/net/liftweb/http/testing/MockHttpRequestSpec.scala @@ -16,7 +16,7 @@ package net.liftweb package mocks -import org.specs.Specification +import org.specs2.mutable.Specification import json.JsonDSL._ @@ -24,7 +24,8 @@ import json.JsonDSL._ /** * System under specification for MockHttpRequest. */ -object MockHttpRequestSpec extends Specification("MockHttpRequest Specification") { +object MockHttpRequestSpec extends Specification { + "MockHttpRequest Specification".title val IF_MODIFIED_HEADER = "If-Modified-Since" val TEST_URL = "https://foo.com/test/this/page?a=b&b=a&a=c" diff --git a/web/webkit/src/main/scala/net/liftweb/mockweb/MockWeb.scala b/web/webkit/src/main/scala/net/liftweb/mockweb/MockWeb.scala index 62ac97d946..021c240924 100644 --- a/web/webkit/src/main/scala/net/liftweb/mockweb/MockWeb.scala +++ b/web/webkit/src/main/scala/net/liftweb/mockweb/MockWeb.scala @@ -29,7 +29,7 @@ import net.liftweb.mocks.MockHttpServletRequest import scala.xml.{MetaData,Null} -import org.specs._ +import org.specs2.mutable._ /** * The MockWeb object contains various methods to simplify diff --git a/web/webkit/src/main/scala/net/liftweb/mockweb/WebSpec.scala b/web/webkit/src/main/scala/net/liftweb/mockweb/WebSpec.scala index eb64c0ebef..fbb1d6d3c9 100644 --- a/web/webkit/src/main/scala/net/liftweb/mockweb/WebSpec.scala +++ b/web/webkit/src/main/scala/net/liftweb/mockweb/WebSpec.scala @@ -20,13 +20,13 @@ import javax.servlet.http.HttpServletRequest import scala.xml.NodeSeq -import org.specs._ +import org.specs2.mutable._ +import org.specs2.execute.Result import common.{Box,Empty,Full} import http._ -import json.JsonAST._ +import net.liftweb.json.JsonAST._ import mocks.MockHttpServletRequest -import specification.Example /** @@ -191,11 +191,8 @@ abstract class WebSpec(boot : () => Any = () => {}) extends Specification { def this (description : String, url : String, session : Box[LiftSession], contextPath : String) = this(description, new MockHttpServletRequest(url, contextPath), session) - def in [T](expectations : => T)(implicit m : scala.reflect.ClassManifest[T]) = { - val example = exampleContainer.createExample(description) - if (sequential) example.setSequential() - - example.in { + def in(expectations : => Result) = + exampleFactory newExample(description, { LiftRulesMocker.devTestLiftRulesInstance.doWith(liftRules) { MockWeb.useLiftRules.doWith(true) { MockWeb.testS(req, session) { @@ -203,8 +200,7 @@ abstract class WebSpec(boot : () => Any = () => {}) extends Specification { } } } - }(m) - } + }) } /** @@ -216,18 +212,14 @@ abstract class WebSpec(boot : () => Any = () => {}) extends Specification { def this (description : String, url : String, contextPath : String) = this(description, new MockHttpServletRequest(url, contextPath)) - def in [T](expectations : Req => T)(implicit m : scala.reflect.ClassManifest[T]) = { - val example = exampleContainer.createExample(description) - if (sequential) example.setSequential() - - example.in { + def in(expectations : Req => Result) = + exampleFactory newExample(description, { LiftRulesMocker.devTestLiftRulesInstance.doWith(liftRules) { MockWeb.useLiftRules.doWith(true) { MockWeb.testReq(req)(expectations) } } - }(m) - } + }) } /** @@ -240,23 +232,19 @@ abstract class WebSpec(boot : () => Any = () => {}) extends Specification { def this (description : String, url : String, session : Box[LiftSession], contextPath : String) = this(description, new MockHttpServletRequest(url, contextPath), session) - def in [T](expectations : Box[NodeSeq] => T)(implicit m : scala.reflect.ClassManifest[T]) = { - val example = exampleContainer.createExample(description) - if (sequential) example.setSequential() - - example.in { + def in(expectations : Box[NodeSeq] => Result) = + exampleFactory.newExample(description, { LiftRulesMocker.devTestLiftRulesInstance.doWith(liftRules) { MockWeb.useLiftRules.doWith(true) { MockWeb.testS(req, session) { S.request match { case Full(sReq) => expectations(S.runTemplate(sReq.path.partPath)) - case other => fail("Error: withTemplateFor call did not result in " + + case other => failure("Error: withTemplateFor call did not result in " + "request initialization (S.request = " + other + ")") } } } } - }(m) - } + }) } } diff --git a/web/webkit/src/test/scala/net/liftweb/builtin/snippet/MsgSpec.scala b/web/webkit/src/test/scala/net/liftweb/builtin/snippet/MsgSpec.scala index 9351c5d9bd..5dc335b037 100644 --- a/web/webkit/src/test/scala/net/liftweb/builtin/snippet/MsgSpec.scala +++ b/web/webkit/src/test/scala/net/liftweb/builtin/snippet/MsgSpec.scala @@ -18,7 +18,7 @@ package net.liftweb package builtin.snippet import xml._ -import org.specs.Specification +import org.specs2.mutable.Specification import common._ import http._ @@ -27,7 +27,9 @@ import http._ /** * System under specification for Msg. */ -object MsgSpec extends Specification("Msg Specification") { +object MsgSpec extends Specification { + "Msg Specification".title + def withSession[T](f: => T) : T = S.initIfUninitted(new LiftSession("test", "", Empty))(f) diff --git a/web/webkit/src/test/scala/net/liftweb/builtin/snippet/MsgsSpec.scala b/web/webkit/src/test/scala/net/liftweb/builtin/snippet/MsgsSpec.scala index fe2034f3c2..338f50be38 100644 --- a/web/webkit/src/test/scala/net/liftweb/builtin/snippet/MsgsSpec.scala +++ b/web/webkit/src/test/scala/net/liftweb/builtin/snippet/MsgsSpec.scala @@ -18,7 +18,7 @@ package net.liftweb package builtin.snippet import xml.XML -import org.specs.Specification +import org.specs2.mutable.Specification import common._ import http._ @@ -27,7 +27,8 @@ import http._ /** * System under specification for Msgs. */ -object MsgsSpec extends Specification("Msgs Specification") { +object MsgsSpec extends Specification { + "Msgs Specification".title def withSession[T](f: => T) : T = S.initIfUninitted(new LiftSession("test", "", Empty))(f) @@ -68,6 +69,7 @@ object MsgsSpec extends Specification("Msgs Specification") { "Properly render AJAX content" in { // TODO : Figure out how to test this + pending } } } diff --git a/web/webkit/src/test/scala/net/liftweb/http/BindingsSpec.scala b/web/webkit/src/test/scala/net/liftweb/http/BindingsSpec.scala index 6c6d64d437..d9898729b2 100644 --- a/web/webkit/src/test/scala/net/liftweb/http/BindingsSpec.scala +++ b/web/webkit/src/test/scala/net/liftweb/http/BindingsSpec.scala @@ -18,7 +18,7 @@ package net.liftweb package http import xml.{NodeSeq, Text} -import org.specs.Specification +import org.specs2.mutable.Specification import common._ import util.Helpers._ @@ -28,7 +28,8 @@ import Bindings._ /** * System under specification for Bindings. */ -object BindingsSpec extends Specification("Bindings Bindings") { +object BindingsSpec extends Specification { + "Bindings Bindings".title case class MyClass(str: String, i: Int, other: MyOtherClass) case class MyOtherClass(foo: String) @@ -73,7 +74,7 @@ object BindingsSpec extends Specification("Bindings Bindings") { "Bindings.binder with an available implicit databinding" should { "allow the application of that databinding to an appropriate object" in { - MyClass("hi", 1, MyOtherClass("bar")).bind(template) must equalIgnoreSpace(expected) + MyClass("hi", 1, MyOtherClass("bar")).bind(template) must beEqualToIgnoringSpace(expected) } } diff --git a/web/webkit/src/test/scala/net/liftweb/http/FactoryMakerSpec.scala b/web/webkit/src/test/scala/net/liftweb/http/FactoryMakerSpec.scala index c6d8cf96d1..9cb911838f 100644 --- a/web/webkit/src/test/scala/net/liftweb/http/FactoryMakerSpec.scala +++ b/web/webkit/src/test/scala/net/liftweb/http/FactoryMakerSpec.scala @@ -17,7 +17,7 @@ package net.liftweb package http -import _root_.org.specs.Specification +import org.specs2.mutable.Specification import common._ @@ -25,7 +25,8 @@ import common._ /** * System under specification for FactoryMaker. */ -object FactoryMakerSpec extends Specification("FactoryMaker Specification") { +object FactoryMakerSpec extends Specification { + "FactoryMaker Specification".title object MyFactory extends Factory { diff --git a/web/webkit/src/test/scala/net/liftweb/http/NamedCometPerTabSpec.scala b/web/webkit/src/test/scala/net/liftweb/http/NamedCometPerTabSpec.scala index e4be5435e6..47dd58ae47 100644 --- a/web/webkit/src/test/scala/net/liftweb/http/NamedCometPerTabSpec.scala +++ b/web/webkit/src/test/scala/net/liftweb/http/NamedCometPerTabSpec.scala @@ -19,14 +19,15 @@ package http import js.JsCmds import xml._ -import org.specs.Specification +import org.specs2.mutable.Specification import common._ /** * System under specification for NamedComet* files. */ -object NamedCometPerTabSpec extends Specification("NamedCometPerTabSpec Specification") { +object NamedCometPerTabSpec extends Specification { + "NamedCometPerTabSpec Specification".title class CometA extends NamedCometActorTrait{ override def lowPriority = { @@ -38,7 +39,7 @@ object NamedCometPerTabSpec extends Specification("NamedCometPerTabSpec Specific } "A NamedCometDispatcher" should { - doBefore { + step { val cometA= new CometA{override def name= Full("1")} cometA.localSetup @@ -50,16 +51,19 @@ object NamedCometPerTabSpec extends Specification("NamedCometPerTabSpec Specific NamedCometListener.getDispatchersFor(Full("1")).foreach( actor => actor.map(_.toString must startWith("net.liftweb.http.NamedCometDispatcher")) ) + success } "be created even if no comet is present when calling getOrAddDispatchersFor" in { NamedCometListener.getOrAddDispatchersFor(Full("3")).foreach( actor => actor.toString must startWith("net.liftweb.http.NamedCometDispatcher") ) + success } "not be created for a non existing key" in { NamedCometListener.getDispatchersFor(Full("2")).foreach( actor => actor must_== Empty ) + success } } diff --git a/web/webkit/src/test/scala/net/liftweb/http/ReqSpec.scala b/web/webkit/src/test/scala/net/liftweb/http/ReqSpec.scala index ba415081a4..8773c9f95b 100644 --- a/web/webkit/src/test/scala/net/liftweb/http/ReqSpec.scala +++ b/web/webkit/src/test/scala/net/liftweb/http/ReqSpec.scala @@ -17,7 +17,7 @@ package net.liftweb package http -import org.specs.Specification +import org.specs2.mutable.Specification import common._ @@ -25,7 +25,8 @@ import common._ /** * System under specification for Req. */ -object ReqSpec extends Specification("Req Specification") { +object ReqSpec extends Specification { + "Req Specification".title private val iPhoneUserAgents = List("Mozilla/5.0 (iPhone Simulator; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16", @@ -40,17 +41,15 @@ object ReqSpec extends Specification("Req Specification") { val uac = new UserAgentCalculator { def userAgent = Full("Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-HK) AppleWebKit/533.18.1 (KHTML, like Gecko) Version/5.0.2 Safari/533.18.5") } - uac.safariVersion.open_! must_== 5 } "Do the right thing with iPhone" in { - iPhoneUserAgents.foreach { + iPhoneUserAgents map { agent => { val uac = new UserAgentCalculator { def userAgent = Full(agent) } - uac.isIPhone must_== true uac.isIPad must_== false } @@ -58,12 +57,11 @@ object ReqSpec extends Specification("Req Specification") { } "Do the right thing with iPad" in { - iPadUserAgents.foreach { + iPadUserAgents map { agent => { val uac = new UserAgentCalculator { def userAgent = Full(agent) } - uac.isIPhone must_== false uac.isIPad must_== true } diff --git a/web/webkit/src/test/scala/net/liftweb/http/ResourceServerSpec.scala b/web/webkit/src/test/scala/net/liftweb/http/ResourceServerSpec.scala index c896a5140d..c7a34db924 100644 --- a/web/webkit/src/test/scala/net/liftweb/http/ResourceServerSpec.scala +++ b/web/webkit/src/test/scala/net/liftweb/http/ResourceServerSpec.scala @@ -17,12 +17,14 @@ package net.liftweb package http -import org.specs.Specification +import org.specs2.mutable.Specification /** * System under specification for ResourceServer. */ -object ResourceServerSpec extends Specification("ResourceServer Specification") { +object ResourceServerSpec extends Specification { + "ResourceServer Specification".title + "ResourceServer.pathRewriter" should { "default jquery.js to jquery-1.3.2" in { ResourceServer.pathRewriter("jquery.js"::Nil) must_== List("jquery-1.3.2-min.js") diff --git a/web/webkit/src/test/scala/net/liftweb/http/SHtmlSpec.scala b/web/webkit/src/test/scala/net/liftweb/http/SHtmlSpec.scala index 0e210fe463..1ff04b3b67 100644 --- a/web/webkit/src/test/scala/net/liftweb/http/SHtmlSpec.scala +++ b/web/webkit/src/test/scala/net/liftweb/http/SHtmlSpec.scala @@ -17,17 +17,18 @@ package net.liftweb package http -import org.specs.Specification +import org.specs2.mutable.Specification import util._ import Helpers._ import net.liftweb.mockweb.MockWeb._ -object SHtmlSpec extends Specification("NamedCometPerTabSpec Specification") { +object SHtmlSpec extends Specification { + "NamedCometPerTabSpec Specification".title val html1= val inputField1= testS("/")( ("#number" #> SHtml.number(0, println(_), 0, 100))(html1) ) - val inputField2= testS("/")( ("#number" #> SHtml.number(0, println(_), 0, 100, 0.1))(html1) ) - val inputField3= testS("/")( ("#number" #> SHtml.number(0, println(_), 0, 100, 1))(html1) ) + val inputField2= testS("/")( ("#number" #> SHtml.number(0, println(_: Double), 0, 100, 0.1))(html1) ) + val inputField3= testS("/")( ("#number" #> SHtml.number(0, println(_: Double), 0, 100, 1))(html1) ) "SHtml" should { "create a number input field" in { diff --git a/web/webkit/src/test/scala/net/liftweb/http/SnippetSpec.scala b/web/webkit/src/test/scala/net/liftweb/http/SnippetSpec.scala index fd7bf1753d..287cf6f88d 100644 --- a/web/webkit/src/test/scala/net/liftweb/http/SnippetSpec.scala +++ b/web/webkit/src/test/scala/net/liftweb/http/SnippetSpec.scala @@ -18,7 +18,7 @@ package net.liftweb package http import xml._ -import org.specs.Specification +import org.specs2.mutable.Specification import common._ import util.Helpers._ @@ -27,7 +27,9 @@ import util.Helpers._ /** * System under specification for SnippetSpec. */ -object SnippetSpec extends Specification("SnippetSpec Specification") { +object SnippetSpec extends Specification { + "SnippetSpec Specification".title + def makeReq = new Req(Req.NilPath, "", GetRequest, Empty, null, System.nanoTime, System.nanoTime, false, () => ParamCalcInfo(Nil, Map.empty, Nil, Empty), Map()) @@ -366,6 +368,7 @@ object SnippetSpec extends Specification("SnippetSpec Specification") { ret.open_! must ==/ () */ + pending } "Check snippets via run" in { @@ -381,6 +384,7 @@ object SnippetSpec extends Specification("SnippetSpec Specification") { (ret.open_! \ "@name").text.length must be > 0 */ + pending } diff --git a/web/webkit/src/test/scala/net/liftweb/http/js/JsExpSpec.scala b/web/webkit/src/test/scala/net/liftweb/http/js/JsExpSpec.scala index a67362ee60..6f29a1ec70 100644 --- a/web/webkit/src/test/scala/net/liftweb/http/js/JsExpSpec.scala +++ b/web/webkit/src/test/scala/net/liftweb/http/js/JsExpSpec.scala @@ -18,7 +18,7 @@ package net.liftweb package http package js -import org.specs.Specification +import org.specs2.mutable.Specification import common._ import json._ @@ -29,7 +29,9 @@ import util.Helpers._ /** * System under specification for JsExp. */ -object JsExpSpec extends Specification("JsExp Specification") { +object JsExpSpec extends Specification { + "JsExp Specification".title + "JsExp" should { "Deal with lift-json" in { val json = ("a" -> 4) ~ ("b" -> 44) diff --git a/web/webkit/src/test/scala/net/liftweb/http/js/extcore/ExtCoreArtifactsSpec.scala b/web/webkit/src/test/scala/net/liftweb/http/js/extcore/ExtCoreArtifactsSpec.scala index 7c88e8c4c3..c17a6656b2 100755 --- a/web/webkit/src/test/scala/net/liftweb/http/js/extcore/ExtCoreArtifactsSpec.scala +++ b/web/webkit/src/test/scala/net/liftweb/http/js/extcore/ExtCoreArtifactsSpec.scala @@ -19,13 +19,14 @@ package http package js package extcore -import org.specs.Specification +import org.specs2.mutable.Specification /** * System under specification for ExtCoreArtifacts. */ -object ExtCoreArtifactsSpec extends Specification("ExtCoreArtifacts Specification") { +object ExtCoreArtifactsSpec extends Specification { + "ExtCoreArtifacts Specification".title "ExtCoreArtifacts.toggle" should { "return the correct javascript expression" in { diff --git a/web/webkit/src/test/scala/net/liftweb/http/rest/XMLApiSpec.scala b/web/webkit/src/test/scala/net/liftweb/http/rest/XMLApiSpec.scala index 4a746edb62..87f6e2251e 100644 --- a/web/webkit/src/test/scala/net/liftweb/http/rest/XMLApiSpec.scala +++ b/web/webkit/src/test/scala/net/liftweb/http/rest/XMLApiSpec.scala @@ -20,8 +20,8 @@ package rest import xml._ -import org.specs.Specification -import org.specs.matcher.Matcher +import org.specs2.mutable.Specification +import org.specs2.matcher.Matcher import common._ import util.ControlHelpers.tryo @@ -29,7 +29,8 @@ import util.ControlHelpers.tryo /** * System under specification for XMLApi. */ -object XmlApiSpec extends Specification("XMLApi Specification") { +object XmlApiSpec extends Specification { + "XMLApi Specification".title object XMLApiExample extends XMLApiHelper { // Define our root tag @@ -83,17 +84,18 @@ object XmlApiSpec extends Specification("XMLApi Specification") { // A helper to simplify the specs matching case class matchXmlResponse(expected : Node) extends Matcher[LiftResponse] { - def apply (response : => LiftResponse) = response match { + def apply[T <: LiftResponse](response : org.specs2.matcher.Expectable[T]) = response.value match { case x : XmlResponse => { /* For some reason, the UnprefixedAttributes that Lift uses to merge in * new attributes makes comparison fail. Instead, we simply stringify and * reparse the response contents and that seems to fix the issue. */ val converted = XML.loadString(x.xml.toString) - (converted == expected, + result(converted == expected, "%s matches %s".format(converted,expected), - "%s does not match %s".format(converted, expected)) + "%s does not match %s".format(converted, expected), + response) } - case other => (false,"matches","not an XmlResponse") + case other => result(false,"matches","not an XmlResponse", response) } } diff --git a/web/webkit/src/test/scala/net/liftweb/mockweb/MockWebSpec.scala b/web/webkit/src/test/scala/net/liftweb/mockweb/MockWebSpec.scala index 1bce0b7a47..dbbefee878 100644 --- a/web/webkit/src/test/scala/net/liftweb/mockweb/MockWebSpec.scala +++ b/web/webkit/src/test/scala/net/liftweb/mockweb/MockWebSpec.scala @@ -18,7 +18,7 @@ package mockweb import scala.xml.{Null,Text,UnprefixedAttribute} -import org.specs.Specification +import org.specs2.mutable.Specification import common._ import util._ @@ -31,7 +31,9 @@ import mocks.MockHttpServletRequest * System under specification for MockWeb. This does the double duty as both a spec * against the MockWeb object as well as an example of how to use it. */ -object MockWebSpec extends Specification("MockWeb Specification") { +object MockWebSpec extends Specification { + "MockWeb Specification".title + import MockWeb._ /** We can create our own LiftRules instance for the purpose of this spec. In the @@ -73,8 +75,6 @@ object MockWebSpec extends Specification("MockWeb Specification") { } "MockWeb" should { - shareVariables() // Avoid setting up LiftRules multiple times - "provide a Req corresponding to a string url" in { testReq("http://foo.com/test/this?a=b&a=c", "/test") { req => @@ -144,6 +144,7 @@ object MockWebSpec extends Specification("MockWeb Specification") { } } } + success } "process S with stateful rewrites" in { @@ -154,6 +155,7 @@ object MockWebSpec extends Specification("MockWeb Specification") { } } } + success } "emulate a snippet invocation" in { diff --git a/web/webkit/src/test/scala/net/liftweb/mockweb/WebSpecSpec.scala b/web/webkit/src/test/scala/net/liftweb/mockweb/WebSpecSpec.scala index f8f3c67783..96296eba8d 100644 --- a/web/webkit/src/test/scala/net/liftweb/mockweb/WebSpecSpec.scala +++ b/web/webkit/src/test/scala/net/liftweb/mockweb/WebSpecSpec.scala @@ -69,9 +69,9 @@ object WebSpecSpecRest extends RestHelper { * WebSpec trait as well as an example of how to use it. */ class WebSpecSpec extends WebSpec(WebSpecSpecBoot.boot _) { - "WebSpec" should { - setSequential() // This is important for using SessionVars, etc. + sequential // This is important for using SessionVars, etc. + "WebSpec" should { val testUrl = "http://foo.com/test/stateless" val testReq = @@ -87,7 +87,7 @@ class WebSpecSpec extends WebSpec(WebSpecSpecBoot.boot _) { "properly set up S with a String url" withSFor(testUrl) in { S.request match { case Full(req) => req.path.partPath must_== List("stateless", "works") - case _ => fail("No request in S") + case _ => failure("No request in S") } } @@ -123,7 +123,7 @@ class WebSpecSpec extends WebSpec(WebSpecSpecBoot.boot _) { req.post_? must_== true req.body match { case Full(body) => (new String(body)) must_== "This is a test" - case _ => fail("No body set") + case _ => failure("No body set") } } @@ -133,18 +133,17 @@ class WebSpecSpec extends WebSpec(WebSpecSpecBoot.boot _) { req.put_? must_== true req.json match { case Full(jval) => jval must_== JObject(List(JField("name", JString("Joe")))) - case _ => fail("No body set") + case _ => failure("No body set") } } "properly set an XML body" withSFor(testUrl) withPost() in { S.request match { - case Full(req) => { + case Full(req) => req.xml_? must_== true req.post_? must_== true req.xml must_== Full() - } - case _ => fail("No request found in S") + case _ => failure("No request found in S") } } @@ -154,16 +153,14 @@ class WebSpecSpec extends WebSpec(WebSpecSpecBoot.boot _) { "process a JSON RestHelper Request" withReqFor("http://foo.com/api/info.json") in { req => (WebSpecSpecRest(req)() match { - case Full(JsonResponse(_, _, _, 200)) => true - case other => fail("Invalid response : " + other); false - }) must_== true + case Full(JsonResponse(_, _, _, 200)) => success + case other => failure("Invalid response : " + other) + }) } - "properly process a template" withTemplateFor("http://foo.com/net/liftweb/mockweb/webspecspectemplate") in ({ + "properly process a template" withTemplateFor("http://foo.com/net/liftweb/mockweb/webspecspectemplate") in { case Full(template) => template.toString.contains("Hello, WebSpec!") must_== true - case other => { - fail("Error on template : " + other) - } - } : PartialFunction[Box[NodeSeq],Unit]) + case other => failure("Error on template : " + other) + } } } diff --git a/web/webkit/src/test/scala/net/liftweb/sitemap/LocSpec.scala b/web/webkit/src/test/scala/net/liftweb/sitemap/LocSpec.scala index 8d1ccd9a53..d7e35281e5 100644 --- a/web/webkit/src/test/scala/net/liftweb/sitemap/LocSpec.scala +++ b/web/webkit/src/test/scala/net/liftweb/sitemap/LocSpec.scala @@ -18,13 +18,14 @@ package net.liftweb package sitemap import common._ -import org.specs.Specification +import org.specs2.mutable.Specification /** * Systems under specification for Loc. */ -object LocSpec extends Specification("Loc Specification") { +object LocSpec extends Specification { + "Loc Specification".title case class Param(s: String) diff --git a/web/webkit/src/test/scala/net/liftweb/sitemap/MenuDSLSpec.scala b/web/webkit/src/test/scala/net/liftweb/sitemap/MenuDSLSpec.scala index 0f7561f0d0..704c0ad6a2 100644 --- a/web/webkit/src/test/scala/net/liftweb/sitemap/MenuDSLSpec.scala +++ b/web/webkit/src/test/scala/net/liftweb/sitemap/MenuDSLSpec.scala @@ -17,13 +17,14 @@ package net.liftweb package sitemap -import org.specs.Specification +import org.specs2.mutable.Specification /** * Systems under specification for Menu DSL. */ -object MenuDslSpec extends Specification("Menu DSL Specification") { +object MenuDslSpec extends Specification { + "Menu DSL Specification".title "The Menu DSL" should { "allow basic menu definition via '/ path'" in { diff --git a/web/webkit/src/test/scala/net/liftweb/webapptest/JettyTestServer.scala b/web/webkit/src/test/scala/net/liftweb/webapptest/JettyTestServer.scala index 4c26440df5..75ea89d3fd 100644 --- a/web/webkit/src/test/scala/net/liftweb/webapptest/JettyTestServer.scala +++ b/web/webkit/src/test/scala/net/liftweb/webapptest/JettyTestServer.scala @@ -61,7 +61,7 @@ final class JettyTestServer(baseUrlBox: Box[URL]) { def running = server_.isRunning - def browse(startPath: String, f:(WebTester) => Unit) { + def browse[A](startPath: String, f:(WebTester) => A): A = { val wc = new WebTester() try { wc.setScriptingEnabled(false) diff --git a/web/webkit/src/test/scala/net/liftweb/webapptest/MemoizeSpec.scala b/web/webkit/src/test/scala/net/liftweb/webapptest/MemoizeSpec.scala index b8e5ce308e..f8d85b21b9 100644 --- a/web/webkit/src/test/scala/net/liftweb/webapptest/MemoizeSpec.scala +++ b/web/webkit/src/test/scala/net/liftweb/webapptest/MemoizeSpec.scala @@ -17,7 +17,7 @@ package net.liftweb package webapptest -import org.specs.Specification +import org.specs2.mutable.Specification import common._ import util._ @@ -35,9 +35,11 @@ object SessionInfo { /** * System under specification for Memoize. */ -object MemoizeSpec extends Specification("Memoize Specification") { - import SessionInfo._ +object MemoizeSpec extends Specification { + "Memoize Specification".title + sequential + import SessionInfo._ "Memoize" should { "Session memo should default to empty" >> { diff --git a/web/webkit/src/test/scala/net/liftweb/webapptest/OneShot.scala b/web/webkit/src/test/scala/net/liftweb/webapptest/OneShot.scala index 29c181a28c..baa0865510 100644 --- a/web/webkit/src/test/scala/net/liftweb/webapptest/OneShot.scala +++ b/web/webkit/src/test/scala/net/liftweb/webapptest/OneShot.scala @@ -17,7 +17,7 @@ package net.liftweb package webapptest -import org.specs.Specification +import org.specs2.mutable.Specification import util._ import http._ @@ -31,6 +31,7 @@ import snippet.Counter object OneShot extends Specification with RequestKit { + sequential private def reachableLocalAddress = { val l = InetAddress.getLocalHost @@ -49,12 +50,9 @@ object OneShot extends Specification with RequestKit { def baseUrl = jetty.baseUrl.toString - doBeforeSpec(jetty.start()) + step(jetty.start()) "ContainerVars" should { - - setSequential() - "have correct int default" in { val tmp = LiftRules.sessionCreator try { @@ -136,9 +134,6 @@ object OneShot extends Specification with RequestKit { } "OneShot" should { - - setSequential() - "fire once for oneshot" in { Counter.x = 0 @@ -175,7 +170,7 @@ object OneShot extends Specification with RequestKit { } } - doAfterSpec { + step { tryo { jetty.stop() } diff --git a/web/webkit/src/test/scala/net/liftweb/webapptest/ToHeadUsages.scala b/web/webkit/src/test/scala/net/liftweb/webapptest/ToHeadUsages.scala index 8c9d22b0ad..af08439c09 100644 --- a/web/webkit/src/test/scala/net/liftweb/webapptest/ToHeadUsages.scala +++ b/web/webkit/src/test/scala/net/liftweb/webapptest/ToHeadUsages.scala @@ -19,7 +19,7 @@ package webapptest import java.net.{URL, InetAddress} -import org.specs.Specification +import org.specs2.mutable.Specification import common.Full import util._ @@ -29,7 +29,9 @@ import Helpers.tryo /** * System under specification for ToHeadUsages. */ -object ToHeadUsages extends Specification("ToHeadUsages Specification") { +object ToHeadUsages extends Specification { + "ToHeadUsages Specification".title + sequential private def reachableLocalAddress = { val l = InetAddress.getLocalHost @@ -46,53 +48,50 @@ object ToHeadUsages extends Specification("ToHeadUsages Specification") { private lazy val jetty = new JettyTestServer(Full(baseUrl_)) - doBeforeSpec(jetty.start()) + step(jetty.start()) "lift merger" should { - setSequential() - "merge from html fragment" in { jetty.browse( "/htmlFragmentWithHead", html => - html.getElementByXPath("/html/head/script[@id='fromFrag']") must notBeNull.when(jetty.running) - ) + html.getElementByXPath("/html/head/script[@id='fromFrag']") must not(beNull when jetty.running)) } "merge from html fragment does not include head element in body" in { jetty.browse( "/htmlFragmentWithHead", html => - html.getElementsByXPath("/html/body/script[@id='fromFrag']").size must be_==(0).when(jetty.running) + html.getElementsByXPath("/html/body/script[@id='fromFrag']").size must (be_==(0) when jetty.running) ) } "merge from snippet" in { jetty.browse( "/htmlSnippetWithHead", html => - html.getElementByXPath("/html/head/script[@src='snippet.js']") must notBeNull.when(jetty.running) + html.getElementByXPath("/html/head/script[@src='snippet.js']") must not(beNull when jetty.running) ) } "not merge for bodyless html" in { jetty.browse( - "/basicDiv",html => { - html.getElementById("fruit") must notBeNull.when(jetty.running) - html.getElementById("bat") must notBeNull.when(jetty.running) + "/basicDiv", html => { + html.getElementById("fruit") must not(beNull when jetty.running) + html.getElementById("bat") must not(beNull when jetty.running) } ) } "not merge for headless bodyless html" in { jetty.browse( - "/h1",html => { - html.getElementById("h1") must notBeNull.when(jetty.running) + "/h1", html => { + html.getElementById("h1") must not(beNull when jetty.running) } ) } "not merge for headless body html" in { jetty.browse( - "/body_no_head",html => { + "/body_no_head", html => { // Note: The XPath expression "html/body/head/div" fails here with // HtmlUnit 2.5 since "head" is not recognized as a XHTML element // due to its incorrect position (under body instead of directly under html) @@ -103,8 +102,8 @@ object ToHeadUsages extends Specification("ToHeadUsages Specification") { "not merge non-html" in { jetty.browse( - "/non_html",html => { - html.getElementById("frog") must notBeNull.when(jetty.running) + "/non_html", html => { + html.getElementById("frog") must not(beNull when jetty.running) } ) } @@ -112,9 +111,6 @@ object ToHeadUsages extends Specification("ToHeadUsages Specification") { } "pages " should { - - setSequential() - "Templates should recognize entities" in { val ns = Templates(List("index")).open_! val str = AltXML.toXML(ns(0), false, false, false) @@ -144,29 +140,26 @@ object ToHeadUsages extends Specification("ToHeadUsages Specification") { } "deferred snippets" should { - - setSequential() - "render" in { jetty.browse( - "/deferred",html => { - html.getElementById("second") must notBeNull.when(jetty.running) + "/deferred", html => { + html.getElementById("second") must not(beNull when jetty.running) } ) } "not deferred not in actor" in { jetty.browse( - "/deferred",html => { - html.getElementByXPath("/html/body/span[@id='whack1']/span[@id='actor_false']") must notBeNull.when(jetty.running) + "/deferred", html => { + html.getElementByXPath("/html/body/span[@id='whack1']/span[@id='actor_false']") must not(beNull when jetty.running) } ) } "deferred in actor" in { jetty.browse( - "/deferred",html => { - html.getElementByXPath("/html/body/span[@id='whack2']/span[@id='actor_true']") must notBeNull.when(jetty.running) + "/deferred", html => { + html.getElementByXPath("/html/body/span[@id='whack2']/span[@id='actor_true']") must not(beNull when jetty.running) } ) } @@ -197,7 +190,7 @@ object ToHeadUsages extends Specification("ToHeadUsages Specification") { } } - doAfterSpec { + step { tryo { jetty.stop() } diff --git a/web/wizard/src/test/scala/net/liftweb/wizard/WizardSpec.scala b/web/wizard/src/test/scala/net/liftweb/wizard/WizardSpec.scala index eecaf25280..a967dda940 100644 --- a/web/wizard/src/test/scala/net/liftweb/wizard/WizardSpec.scala +++ b/web/wizard/src/test/scala/net/liftweb/wizard/WizardSpec.scala @@ -17,7 +17,7 @@ package net.liftweb package wizard -import org.specs.Specification +import org.specs2.mutable.Specification import common._ import util._ @@ -26,7 +26,8 @@ import http._ /** * System under specification for Wizard. */ -object WizardSpec extends Specification("Wizard Specification") { +object WizardSpec extends Specification { + "Wizard Specification".title val session: LiftSession = new LiftSession("", Helpers.randomString(20), Empty)