Navigation Menu

Skip to content

Commit

Permalink
lift-webkit
Browse files Browse the repository at this point in the history
  • Loading branch information
Naftoli Gugenheim committed Jul 31, 2012
1 parent 5ab5f45 commit 762f746
Show file tree
Hide file tree
Showing 24 changed files with 136 additions and 135 deletions.
Expand Up @@ -16,15 +16,16 @@
package net.liftweb package net.liftweb
package mocks package mocks


import org.specs.Specification import org.specs2.mutable.Specification


import json.JsonDSL._ import json.JsonDSL._




/** /**
* System under specification for MockHttpRequest. * 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 IF_MODIFIED_HEADER = "If-Modified-Since"
val TEST_URL = "https://foo.com/test/this/page?a=b&b=a&a=c" val TEST_URL = "https://foo.com/test/this/page?a=b&b=a&a=c"
Expand Down
Expand Up @@ -29,7 +29,7 @@ import net.liftweb.mocks.MockHttpServletRequest


import scala.xml.{MetaData,Null} import scala.xml.{MetaData,Null}


import org.specs._ import org.specs2.mutable._


/** /**
* The MockWeb object contains various methods to simplify * The MockWeb object contains various methods to simplify
Expand Down
38 changes: 13 additions & 25 deletions web/webkit/src/main/scala/net/liftweb/mockweb/WebSpec.scala
Expand Up @@ -20,13 +20,13 @@ import javax.servlet.http.HttpServletRequest


import scala.xml.NodeSeq import scala.xml.NodeSeq


import org.specs._ import org.specs2.mutable._
import org.specs2.execute.Result


import common.{Box,Empty,Full} import common.{Box,Empty,Full}
import http._ import http._
import json.JsonAST._ import net.liftweb.json.JsonAST._
import mocks.MockHttpServletRequest import mocks.MockHttpServletRequest
import specification.Example




/** /**
Expand Down Expand Up @@ -191,20 +191,16 @@ abstract class WebSpec(boot : () => Any = () => {}) extends Specification {
def this (description : String, url : String, session : Box[LiftSession], contextPath : String) = def this (description : String, url : String, session : Box[LiftSession], contextPath : String) =
this(description, new MockHttpServletRequest(url, contextPath), session) this(description, new MockHttpServletRequest(url, contextPath), session)


def in [T](expectations : => T)(implicit m : scala.reflect.ClassManifest[T]) = { def in(expectations : => Result) =
val example = exampleContainer.createExample(description) exampleFactory newExample(description, {
if (sequential) example.setSequential()

example.in {
LiftRulesMocker.devTestLiftRulesInstance.doWith(liftRules) { LiftRulesMocker.devTestLiftRulesInstance.doWith(liftRules) {
MockWeb.useLiftRules.doWith(true) { MockWeb.useLiftRules.doWith(true) {
MockWeb.testS(req, session) { MockWeb.testS(req, session) {
expectations expectations
} }
} }
} }
}(m) })
}
} }


/** /**
Expand All @@ -216,18 +212,14 @@ abstract class WebSpec(boot : () => Any = () => {}) extends Specification {
def this (description : String, url : String, contextPath : String) = def this (description : String, url : String, contextPath : String) =
this(description, new MockHttpServletRequest(url, contextPath)) this(description, new MockHttpServletRequest(url, contextPath))


def in [T](expectations : Req => T)(implicit m : scala.reflect.ClassManifest[T]) = { def in(expectations : Req => Result) =
val example = exampleContainer.createExample(description) exampleFactory newExample(description, {
if (sequential) example.setSequential()

example.in {
LiftRulesMocker.devTestLiftRulesInstance.doWith(liftRules) { LiftRulesMocker.devTestLiftRulesInstance.doWith(liftRules) {
MockWeb.useLiftRules.doWith(true) { MockWeb.useLiftRules.doWith(true) {
MockWeb.testReq(req)(expectations) MockWeb.testReq(req)(expectations)
} }
} }
}(m) })
}
} }


/** /**
Expand All @@ -240,23 +232,19 @@ abstract class WebSpec(boot : () => Any = () => {}) extends Specification {
def this (description : String, url : String, session : Box[LiftSession], contextPath : String) = def this (description : String, url : String, session : Box[LiftSession], contextPath : String) =
this(description, new MockHttpServletRequest(url, contextPath), session) this(description, new MockHttpServletRequest(url, contextPath), session)


def in [T](expectations : Box[NodeSeq] => T)(implicit m : scala.reflect.ClassManifest[T]) = { def in(expectations : Box[NodeSeq] => Result) =
val example = exampleContainer.createExample(description) exampleFactory.newExample(description, {
if (sequential) example.setSequential()

example.in {
LiftRulesMocker.devTestLiftRulesInstance.doWith(liftRules) { LiftRulesMocker.devTestLiftRulesInstance.doWith(liftRules) {
MockWeb.useLiftRules.doWith(true) { MockWeb.useLiftRules.doWith(true) {
MockWeb.testS(req, session) { MockWeb.testS(req, session) {
S.request match { S.request match {
case Full(sReq) => expectations(S.runTemplate(sReq.path.partPath)) 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 + ")") "request initialization (S.request = " + other + ")")
} }
} }
} }
} }
}(m) })
}
} }
} }
Expand Up @@ -18,7 +18,7 @@ package net.liftweb
package builtin.snippet package builtin.snippet


import xml._ import xml._
import org.specs.Specification import org.specs2.mutable.Specification


import common._ import common._
import http._ import http._
Expand All @@ -27,7 +27,9 @@ import http._
/** /**
* System under specification for Msg. * System under specification for Msg.
*/ */
object MsgSpec extends Specification("Msg Specification") { object MsgSpec extends Specification {
"Msg Specification".title

def withSession[T](f: => T) : T = def withSession[T](f: => T) : T =
S.initIfUninitted(new LiftSession("test", "", Empty))(f) S.initIfUninitted(new LiftSession("test", "", Empty))(f)


Expand Down
Expand Up @@ -18,7 +18,7 @@ package net.liftweb
package builtin.snippet package builtin.snippet


import xml.XML import xml.XML
import org.specs.Specification import org.specs2.mutable.Specification


import common._ import common._
import http._ import http._
Expand All @@ -27,7 +27,8 @@ import http._
/** /**
* System under specification for Msgs. * System under specification for Msgs.
*/ */
object MsgsSpec extends Specification("Msgs Specification") { object MsgsSpec extends Specification {
"Msgs Specification".title


def withSession[T](f: => T) : T = def withSession[T](f: => T) : T =
S.initIfUninitted(new LiftSession("test", "", Empty))(f) S.initIfUninitted(new LiftSession("test", "", Empty))(f)
Expand Down Expand Up @@ -68,6 +69,7 @@ object MsgsSpec extends Specification("Msgs Specification") {


"Properly render AJAX content" in { "Properly render AJAX content" in {
// TODO : Figure out how to test this // TODO : Figure out how to test this
pending
} }
} }
} }
Expand Down
7 changes: 4 additions & 3 deletions web/webkit/src/test/scala/net/liftweb/http/BindingsSpec.scala
Expand Up @@ -18,7 +18,7 @@ package net.liftweb
package http package http


import xml.{NodeSeq, Text} import xml.{NodeSeq, Text}
import org.specs.Specification import org.specs2.mutable.Specification


import common._ import common._
import util.Helpers._ import util.Helpers._
Expand All @@ -28,7 +28,8 @@ import Bindings._
/** /**
* System under specification for 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 MyClass(str: String, i: Int, other: MyOtherClass)
case class MyOtherClass(foo: String) case class MyOtherClass(foo: String)
Expand Down Expand Up @@ -73,7 +74,7 @@ object BindingsSpec extends Specification("Bindings Bindings") {


"Bindings.binder with an available implicit databinding" should { "Bindings.binder with an available implicit databinding" should {
"allow the application of that databinding to an appropriate object" in { "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)
} }
} }


Expand Down
Expand Up @@ -17,15 +17,16 @@
package net.liftweb package net.liftweb
package http package http


import _root_.org.specs.Specification import org.specs2.mutable.Specification


import common._ import common._




/** /**
* System under specification for FactoryMaker. * System under specification for FactoryMaker.
*/ */
object FactoryMakerSpec extends Specification("FactoryMaker Specification") { object FactoryMakerSpec extends Specification {
"FactoryMaker Specification".title




object MyFactory extends Factory { object MyFactory extends Factory {
Expand Down
Expand Up @@ -19,14 +19,15 @@ package http


import js.JsCmds import js.JsCmds
import xml._ import xml._
import org.specs.Specification import org.specs2.mutable.Specification


import common._ import common._


/** /**
* System under specification for NamedComet* files. * System under specification for NamedComet* files.
*/ */
object NamedCometPerTabSpec extends Specification("NamedCometPerTabSpec Specification") { object NamedCometPerTabSpec extends Specification {
"NamedCometPerTabSpec Specification".title


class CometA extends NamedCometActorTrait{ class CometA extends NamedCometActorTrait{
override def lowPriority = { override def lowPriority = {
Expand All @@ -38,7 +39,7 @@ object NamedCometPerTabSpec extends Specification("NamedCometPerTabSpec Specific
} }


"A NamedCometDispatcher" should { "A NamedCometDispatcher" should {
doBefore { step {
val cometA= new CometA{override def name= Full("1")} val cometA= new CometA{override def name= Full("1")}
cometA.localSetup cometA.localSetup


Expand All @@ -50,16 +51,19 @@ object NamedCometPerTabSpec extends Specification("NamedCometPerTabSpec Specific
NamedCometListener.getDispatchersFor(Full("1")).foreach( NamedCometListener.getDispatchersFor(Full("1")).foreach(
actor => actor.map(_.toString must startWith("net.liftweb.http.NamedCometDispatcher")) actor => actor.map(_.toString must startWith("net.liftweb.http.NamedCometDispatcher"))
) )
success
} }
"be created even if no comet is present when calling getOrAddDispatchersFor" in { "be created even if no comet is present when calling getOrAddDispatchersFor" in {
NamedCometListener.getOrAddDispatchersFor(Full("3")).foreach( NamedCometListener.getOrAddDispatchersFor(Full("3")).foreach(
actor => actor.toString must startWith("net.liftweb.http.NamedCometDispatcher") actor => actor.toString must startWith("net.liftweb.http.NamedCometDispatcher")
) )
success
} }
"not be created for a non existing key" in { "not be created for a non existing key" in {
NamedCometListener.getDispatchersFor(Full("2")).foreach( NamedCometListener.getDispatchersFor(Full("2")).foreach(
actor => actor must_== Empty actor => actor must_== Empty
) )
success

This comment has been minimized.

Copy link
@fmpwizard

fmpwizard Aug 20, 2012

Member

does the success here mean that if

         actor => actor must_== Empty

is not Empty, the test case will pass anyway?

This comment has been minimized.

Copy link
@fmpwizard

fmpwizard Aug 20, 2012

Member

I pulled this branch locally and verified that having the success is just to make specs2 happy, if there is a failure in the previous line, we get a failed test.

This comment has been minimized.

Copy link
@nafg

nafg via email Aug 23, 2012

Author Contributor
} }
} }


Expand Down
12 changes: 5 additions & 7 deletions web/webkit/src/test/scala/net/liftweb/http/ReqSpec.scala
Expand Up @@ -17,15 +17,16 @@
package net.liftweb package net.liftweb
package http package http


import org.specs.Specification import org.specs2.mutable.Specification


import common._ import common._




/** /**
* System under specification for Req. * System under specification for Req.
*/ */
object ReqSpec extends Specification("Req Specification") { object ReqSpec extends Specification {
"Req Specification".title


private val iPhoneUserAgents = 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", 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",
Expand All @@ -40,30 +41,27 @@ object ReqSpec extends Specification("Req Specification") {
val uac = new UserAgentCalculator { 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") 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 uac.safariVersion.open_! must_== 5
} }


"Do the right thing with iPhone" in { "Do the right thing with iPhone" in {
iPhoneUserAgents.foreach { iPhoneUserAgents map {
agent => { agent => {
val uac = new UserAgentCalculator { val uac = new UserAgentCalculator {
def userAgent = Full(agent) def userAgent = Full(agent)
} }

uac.isIPhone must_== true uac.isIPhone must_== true
uac.isIPad must_== false uac.isIPad must_== false
} }
} }
} }


"Do the right thing with iPad" in { "Do the right thing with iPad" in {
iPadUserAgents.foreach { iPadUserAgents map {
agent => { agent => {
val uac = new UserAgentCalculator { val uac = new UserAgentCalculator {
def userAgent = Full(agent) def userAgent = Full(agent)
} }

uac.isIPhone must_== false uac.isIPhone must_== false
uac.isIPad must_== true uac.isIPad must_== true
} }
Expand Down
Expand Up @@ -17,12 +17,14 @@
package net.liftweb package net.liftweb
package http package http


import org.specs.Specification import org.specs2.mutable.Specification


/** /**
* System under specification for ResourceServer. * System under specification for ResourceServer.
*/ */
object ResourceServerSpec extends Specification("ResourceServer Specification") { object ResourceServerSpec extends Specification {
"ResourceServer Specification".title

"ResourceServer.pathRewriter" should { "ResourceServer.pathRewriter" should {
"default jquery.js to jquery-1.3.2" in { "default jquery.js to jquery-1.3.2" in {
ResourceServer.pathRewriter("jquery.js"::Nil) must_== List("jquery-1.3.2-min.js") ResourceServer.pathRewriter("jquery.js"::Nil) must_== List("jquery-1.3.2-min.js")
Expand Down
9 changes: 5 additions & 4 deletions web/webkit/src/test/scala/net/liftweb/http/SHtmlSpec.scala
Expand Up @@ -17,17 +17,18 @@
package net.liftweb package net.liftweb
package http package http


import org.specs.Specification import org.specs2.mutable.Specification
import util._ import util._
import Helpers._ import Helpers._
import net.liftweb.mockweb.MockWeb._ import net.liftweb.mockweb.MockWeb._


object SHtmlSpec extends Specification("NamedCometPerTabSpec Specification") { object SHtmlSpec extends Specification {
"NamedCometPerTabSpec Specification".title


val html1= <span><input id="number"></input></span> val html1= <span><input id="number"></input></span>
val inputField1= testS("/")( ("#number" #> SHtml.number(0, println(_), 0, 100))(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 inputField2= testS("/")( ("#number" #> SHtml.number(0, println(_: Double), 0, 100, 0.1))(html1) )
val inputField3= testS("/")( ("#number" #> SHtml.number(0, println(_), 0, 100, 1))(html1) ) val inputField3= testS("/")( ("#number" #> SHtml.number(0, println(_: Double), 0, 100, 1))(html1) )


"SHtml" should { "SHtml" should {
"create a number input field" in { "create a number input field" in {
Expand Down
8 changes: 6 additions & 2 deletions web/webkit/src/test/scala/net/liftweb/http/SnippetSpec.scala
Expand Up @@ -18,7 +18,7 @@ package net.liftweb
package http package http


import xml._ import xml._
import org.specs.Specification import org.specs2.mutable.Specification


import common._ import common._
import util.Helpers._ import util.Helpers._
Expand All @@ -27,7 +27,9 @@ import util.Helpers._
/** /**
* System under specification for SnippetSpec. * 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, def makeReq = new Req(Req.NilPath, "", GetRequest, Empty, null,
System.nanoTime, System.nanoTime, false, System.nanoTime, System.nanoTime, false,
() => ParamCalcInfo(Nil, Map.empty, Nil, Empty), Map()) () => ParamCalcInfo(Nil, Map.empty, Nil, Empty), Map())
Expand Down Expand Up @@ -366,6 +368,7 @@ object SnippetSpec extends Specification("SnippetSpec Specification") {
ret.open_! must ==/ (<yak/>) ret.open_! must ==/ (<yak/>)
*/ */
pending
} }


"Check snippets via run" in { "Check snippets via run" in {
Expand All @@ -381,6 +384,7 @@ object SnippetSpec extends Specification("SnippetSpec Specification") {
(ret.open_! \ "@name").text.length must be > 0 (ret.open_! \ "@name").text.length must be > 0
*/ */
pending
} }




Expand Down

1 comment on commit 762f746

@fmpwizard
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Please sign in to comment.