Using Specs 1.6:

object HelloWorldTestSpecs extends Specification {  val session = new
LiftSession("", randomString(20), Empty)
  val stableTime = now

  override def executeExpectations(ex: Examples, t: =>Any): Any = {
    S.initIfUninitted(session) {
      ... put your User init here.  The User.logUserIn will be within the
context of a session and thus session (and request) vars will be valid
    }
  }

  "HelloWorld Snippet" should {
    "Put the time in the node" in {
      ... do testing here
    }
  }
}


Hope this helps.

On Thu, Oct 1, 2009 at 8:55 AM, rstradling <ryanstradl...@gmail.com> wrote:

>
> I have a class called
> class Trainer {
>   def showPeople(xhtml : Group) : NodeSeq = {
>      val user : User = User.currentUser.open_!
>      ...
>   }
> }
>
> I then want to write a unit test to test that returns proper xml.
>
> The test is written as so
>  def testValue() = {
>    val xml =
>        <xml:group>
>          <tr>
>              <td>
>                  <p:fullName>My Name</p:fullName>
>              </td>
>              <td>
>                  <p:style>Fighter Style</p:style>
>              </td>
>              <td>
>                  <p:weight>Weight</p:weight>
>              </td>
>          </tr>
>        </xml:group>
>    val trainer = new Trainer()
>    val output = trainer.showPeople(xml)
>    ()
>  }
>
> The User object inherits from MegaProtoUser.
>
> The problem is I am not sure how to create a mock user and sign them
> in.
> I have tried in my unit test
> override def setUp : Unit = {
>   val user = User.create
>   user.firstName("XXX")
>   user.lastName("YYY")
>   user.save
>   User.logUserIn(user)
> }
>
> The mock user log-in *seems* to work fine but when
> User.currentUser.open_! is called it throws an exception on trying to
> open an empty box.
>
> So either how do I do this or how do others do this type of testing.
> I am sure I am missing something simple.
>
> Thanks,
> ryan
>
>
>
>
>
> >
>


-- 
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to