Using the new WebSpec

198 views
Skip to first unread message

Diego Medina

unread,
Jan 31, 2011, 2:32:48 PM1/31/11
to lif...@googlegroups.com
Hi

I'm trying to use the new WebSpec mocks do write some unit tests and I
get this error:


WebSpec is not a member of net.liftweb.mocks

This is the relevant sections on my sbt projecgt file:

===================

val liftVersion = "2.3-SNAPSHOT"
val scalaToolsSnapshots = "Scala-Tools Maven2 Snapshots Repository"
at "http://scala-tools.org/repo-snapshots"


override def libraryDependencies = Set(
"net.liftweb" %% "lift-webkit" % liftVersion % "compile->default",
"net.liftweb" %% "lift-testkit" % liftVersion % "compile->default",
"net.liftweb" %% "lift-widgets" % liftVersion % "compile->default",
"net.liftweb" %% "lift-mapper" % liftVersion % "compile->default",
"net.liftweb" %% "lift-ldap" % liftVersion % "compile->default",
"net.liftweb" %% "lift-json" % liftVersion % "compile->default",
"org.mortbay.jetty" % "jetty" % "6.1.22" % "test->default",
"junit" % "junit" % "4.5" % "test->default",
"org.mockito" % "mockito-core" % "1.8.5" % "test->default",
"org.scala-tools.testing" %% "specs" % "1.6.6" % "test->default",
"mysql" % "mysql-connector-java" % "5.1.14" % "compile->default",
"ch.qos.logback" % "logback-classic" % "0.9.26" % "compile->default",
"commons-dbcp" % "commons-dbcp" % "1.4" % "compile->default"
) ++ super.libraryDependencies

===============

Inside sbt I run:

clean
clean-lib
update
test

and here I get the error.

Thanks

Diego


--
Diego Medina
Web Developer
http://www.fmpwizard.com

Derek Chen-Becker

unread,
Jan 31, 2011, 4:29:33 PM1/31/11
to lif...@googlegroups.com
Hmm, just checking the JAR on scala-tools.org, it appears that neither MockWeb nor WebSpec are there, although they show up in my target/classes directory when I build webkit. It looks like I need to fix the configuration of the maven-bundle-plugin, but I'm not really familiar with that enough to tinker with it. Let me see if one of the Maven Wizards here can tune it so that it's actually included prior to 2.3-M1

Derek


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


David Pollak

unread,
Jan 31, 2011, 4:38:00 PM1/31/11
to lif...@googlegroups.com

Feel encouraged to skip review board and just get this into master asap.

Derek Chen-Becker

unread,
Jan 31, 2011, 5:24:56 PM1/31/11
to lif...@googlegroups.com
Playing daddy daycare until this evening, but it's my #1 priority as soon as I can get to it.

Derek




David Pollak

unread,
Jan 31, 2011, 6:50:47 PM1/31/11
to lif...@googlegroups.com
On Mon, Jan 31, 2011 at 2:24 PM, Derek Chen-Becker <dchen...@gmail.com> wrote:
Playing daddy daycare until this evening, but it's my #1 priority as soon as I can get to it.



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

Derek Chen-Becker

unread,
Jan 31, 2011, 7:17:26 PM1/31/11
to lif...@googlegroups.com
Hmmm, I had actually tried that same approach earlier and it pulls classes under net.liftweb.mocks in lift-testkit into the JAR file:

   888 Mon Jan 31 15:55:16 MST 2011 net/liftweb/mocks/DoNothingFilterChain$$anonfun$doFilter$1.class
  6154 Mon Jan 31 15:55:16 MST 2011 net/liftweb/mocks/DoNothingFilterChain.class
  1708 Mon Jan 31 15:55:16 MST 2011 net/liftweb/mocks/MockFilterConfig.class
  1123 Mon Jan 31 15:55:16 MST 2011 net/liftweb/mocks/MockHttpServletRequest$$anonfun$1.class
 17177 Mon Jan 31 15:55:16 MST 2011 net/liftweb/mocks/MockHttpServletRequest$$anonfun$2.class
etc...

If having it in the net.liftweb.mocks package will make it difficult to use I could refactor it tonight to sit in net.liftweb.webmock/mockweb or something else.

Derek

Derek Chen-Becker

unread,
Jan 31, 2011, 7:28:10 PM1/31/11
to lif...@googlegroups.com
OK, I'm going to move the MockWeb and WebSpec stuff to net.liftweb.mockweb tonight and update the Wiki. I'll update when it's all done. Sorry for the confusion/mess with the packaging.

Derek

Diego Medina

unread,
Jan 31, 2011, 7:52:18 PM1/31/11
to lif...@googlegroups.com

Thanks!

Diego Medina

>>>> ------------------------------
>>> Lift, the simply functional web framework http://liftweb.net
>>> Beginning Scala http://www.apress.com/book/view/1430219890
>>> Follow me: http://twitter.com/dpp
>>> Blog: http://goodstuff.im
>>> 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 lif...@googlegroups.com.
>>> To unsubscribe from this group, send email to

Derek Chen-Becker

unread,
Jan 31, 2011, 10:52:12 PM1/31/11
to lif...@googlegroups.com
I just pushed the changes to master (after a clean full build), so it should be available under net.liftweb.mockweb shortly.

Derek

Diego Medina

unread,
Feb 1, 2011, 12:10:12 AM2/1/11
to lif...@googlegroups.com
Thanks Derek. My initial tests are running now!

Diego

On Mon, Jan 31, 2011 at 10:52 PM, Derek Chen-Becker

Derek Chen-Becker

unread,
Feb 1, 2011, 1:24:40 AM2/1/11
to lif...@googlegroups.com
Good to hear. My priority going forward is to improve the testing experience with Lift, so any feedback on what's in place now, what is missing, and other ideas for making it better are greatly appreciated.

Derek

Diego Medina

unread,
Feb 8, 2011, 11:58:02 PM2/8/11
to lif...@googlegroups.com
Hi Derek,

On Tue, Feb 1, 2011 at 1:24 AM, Derek Chen-Becker <dchen...@gmail.com> wrote:
> Good to hear. My priority going forward is to improve the testing experience
> with Lift, so any feedback on what's in place now, what is missing, and
> other ideas for making it better are greatly appreciated.

I have added several tests that use the pattern

... withSFor(testReq) ...

and it is working real well. Very easy to setup and clear to see what
is being tested.

One thing that I'm not sure how it could be avoided or improved is
that I find myself writing tests like this:


"display the version number" withSFor(testReq) in {
val serviceManagerDetails = new ServiceManagerDetails
serviceManagerDetails.renderServiceManagerResult(
<h2>Service Manager results for version: </h2>
).toString mustEqual(<h2>Service Manager results for version:
2.4.0.1090</h2>).toString
}

(ignore the .toString for a moment, but what I see is that if on my
real html page, I change the h2 for an h3, my tests will still pass, I
would have to manually keep m tests and html pages in sync.

This is a minimalist example, but I have some tests that have a lot of
html in them. So, having some way to "use" the real html pages on my
tests would be better, but I'm not sure how to really do that.

Again, thanks for the great work you have done!

Diego

Antonio Salazar Cardozo

unread,
Feb 9, 2011, 12:29:23 AM2/9/11
to lif...@googlegroups.com
Once you have a mock S context, can't you use S.runTemplate?
Antonio

>> >> >>>> >> liftweb+u...@googlegroups.com<liftweb%2B...@googlegroups.com>
>> >> >>>>
>> >> >>>>
>> >> >>>> <liftweb%2B...@googlegroups.com<liftweb%252...@googlegroups.com>


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

>> >> >>>> liftweb+u...@googlegroups.com<liftweb%2B...@googlegroups.com>


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

>> >> >>>> liftweb+u...@googlegroups.com<liftweb%2B...@googlegroups.com>


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

>> >> >>>> liftweb+u...@googlegroups.com<liftweb%2B...@googlegroups.com>


>> >> >>>> .
>> >> >>>> For more options, visit this group at
>> >> >>>> http://groups.google.com/group/liftweb?hl=en.
>> >> >>>>
>> >> >>>
>> >> >>>
>> >> >>>
>> >> >>> --
>> >> >>> Lift, the simply functional web framework http://liftweb.net
>> >> >>> Beginning Scala http://www.apress.com/book/view/1430219890
>> >> >>> Follow me: http://twitter.com/dpp
>> >> >>> Blog: http://goodstuff.im
>> >> >>> 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 lif...@googlegroups.com.
>> >> >>> To unsubscribe from this group, send email to
>> >> >>>
>> >> >>>

>> >> >>> liftweb+u...@googlegroups.com<liftweb%2B...@googlegroups.com>

Derek Chen-Becker

unread,
Feb 9, 2011, 2:25:58 PM2/9/11
to lif...@googlegroups.com
That was what I was going to suggest. If that doesn't work let me know and I'll see what needs to happen to make runTemplate work within the mock.

Derek

Diego Medina

unread,
Feb 10, 2011, 2:07:39 PM2/10/11
to lif...@googlegroups.com
Hi,

Thanks both of you for the answer, this is what I have not, but I must
be missing something. What I have is:

val testReq =
new MockHttpServletRequest(
"http://127.0.0.1:8080/agent-details/2.4.0.1090", ""
)

"display service manager test results, all FAIL" withSFor(testReq) in {
val agentDetails = new AgentDetails
val res= Full(List(Map("N/A"->("N/A", "N/A"))))

S.runTemplate(List("agent-details.html"))

agentDetails.testResults.doWith(
Box[List[Map[String,(String, String)]]](
List(
Map("RHEL5 64bit"->("RHEL5", "FAIL")),
Map("RHEL5 64bit"->("RHEL5", "FAIL")),
Map("RHEL5 64bit"->("RHEL5", "FAIL")),
Map("RHEL5 64bit"->("RHEL5", "FAIL")),
Map("RHEL5 64bit"->("RHEL5", "FAIL")),
Map("RHEL5 64bit"->("RHEL5", "FAIL")),
Map("RHEL5 64bit"->("RHEL5", "FAIL"))
)
)
){
agentDetails.renderAgentResult mustEqual(<some html here>)

and specs fails telling me (short version)


[error] x display service manager test results, all FAIL
[error] '<[]f[u]n[c]t[]i[]o[]n[1]>[]' is not equal to 'my expected
html here'


Thanks

Diego

Derek Chen-Becker

unread,
Feb 10, 2011, 2:20:22 PM2/10/11
to lif...@googlegroups.com
I'm very confused. Are you testing the output of the "agent-details.html" template (I would recommend dropping the ".html" suffix, too) or some side effects of it running? Right now your code is going to try to run the template but then it discards the resulting Box[NodeSeq] because you're not assigning the result of S.runTemplate to anything.

Derek

Diego Medina

unread,
Feb 10, 2011, 5:21:20 PM2/10/11
to lif...@googlegroups.com
Ah, I didn;t know how to really use runTemplate. Now I get:


[error] x display service manager test results, all FAIL

[error] 'Failure(Couldn't find template
List(agent-details),Empty,Empty)' is not equal to '<html here>'
(AgentDetailsTestSpecs.scala:80)


and I have a file in

./src/main/webapp/agent-details.html
and just in case here too:
./src/main/webapp/templates-hidden/agent-details.html

What i'm trying to do is see if my snippet converts the page to what I
expect, I see that the definition of runTemplate also has a snips
parameter, which I don;t know if I'm supposed to use or not.

Later tonight I'll post a sample app so that you can see what I see,
maybe I'm omitting some important detail.

Thanks

Diego


On Thu, Feb 10, 2011 at 2:20 PM, Derek Chen-Becker

Antonio Salazar Cardozo

unread,
Feb 10, 2011, 5:41:46 PM2/10/11
to lif...@googlegroups.com
I wonder if you need to link your main/webapp to test/webapp?
Antonio

Derek Chen-Becker

unread,
Feb 10, 2011, 11:12:42 PM2/10/11
to lif...@googlegroups.com
What you're doing sounds right, but I think that Antonio might be on to something. I thought that a test would have the main/webapp path in its classpath (which is where templates are searched), but I could be wrong. If you could post a sample app I can dig into and figure out what's going on.

Derek

Diego Medina

unread,
Feb 10, 2011, 11:57:32 PM2/10/11
to lif...@googlegroups.com
Hi,

Ok, sample app is here:

https://github.com/fmpwizard/specs-lift

run

git clone git://github.com/fmpwizard/specs-lift.git

cd specs-lift
sbt
update
~test-only code.snippet.AgentDetailsTestSpecs

and you will see

[error] x AgentDetails should


[error] x display service manager test results, all FAIL
[error] 'Failure(Couldn't find template

List(agent-details),Empty,Empty)' is not equal to 'temp'
(AgentDetailsTestSpecs.scala:70)

I copied the agent-details.html file to the test/webapp folder and I
still get the error :(


Thanks for looking into this

Diego
On Thu, Feb 10, 2011 at 11:12 PM, Derek Chen-Becker

Derek Chen-Becker

unread,
Feb 11, 2011, 3:08:51 PM2/11/11
to lif...@googlegroups.com
OK, I think that this is an issue with how SBT does the classpath and not with your code. If I symlink the agent-details.html into src/test/resources then it works. I'm going to have to dig into how SBT sets the classpath during the test phase, but hopefully it's configurable to include src/main/webapp.

Derek


derek@rocky /home/software/testProjects/specs-lift ±master⚡ » cd src/test/resources
derek@rocky /home/software/testProjects/specs-lift/src/test/resources ±master⚡ » ln -s ../../main/webapp/agent-details.html
derek@rocky /home/software/testProjects/specs-lift/src/test/resources ±master⚡ » cd ../../..
derek@rocky /home/software/testProjects/specs-lift ±master⚡ » sbt
[info] Building project QA Dashboard 0.1 against Scala 2.8.1
[info]    using LiftProject with sbt 0.7.4 and Scala 2.7.7
> ~test-only code.snippet.AgentDetailsTestSpecs
[info]
[info] == compile ==
[info]   Source analysis: 0 new/modified, 0 indirectly invalidated, 0 removed.
[info] Compiling main sources...
[info] Nothing to compile.
[info]   Post-analysis: 36 classes.
[info] == compile ==
[info]
[info] == test-compile ==
[info]   Source analysis: 0 new/modified, 0 indirectly invalidated, 0 removed.
[info] Compiling test sources...
[info] Nothing to compile.
[info]   Post-analysis: 27 classes.
[info] == test-compile ==
[info]
[info] == copy-resources ==
[info] == copy-resources ==
[info]
[info] == copy-test-resources ==
[info] == copy-test-resources ==
[info]
[info] == test-start ==
[info] == test-start ==
[info]
[info] == code.snippet.AgentDetailsTestSpecs ==
13:07:28.834 [Thread-6] DEBUG code.snippet.AgentDetails - 2.3.4.0.1099
13:07:29.027 [Thread-6] DEBUG code.snippet.AgentDetails - 2.3.4.0.1099
13:07:29.063 [Thread-6] DEBUG code.lib.GridRenderHelper - Map(N/A -> TestRow(Map(0 -> Some(Result(N/A,false)))))

[error] x AgentDetails should
[error]   x display service manager test results, all FAIL
[error]     'Full(
[error]   <div class="colborder ">
[error]     <hr class="space"></hr>
[error]    
[error]    
[error]    
[error]       <h2>Agent results for version: 2.3.4.0.1099</h2>
[error]       <table>
[error]   <tr>
[error]           <th>Platform</th>
[error]           <th>NO SSL</th>
[error]           <th>SSL</th>
[error]           <th>Agent, Proxy <br></br>(No SSL, QUAN)</th>
[error]           <th>Agent, Proxy <br></br>(SSL, QUAN)</th>
[error]           <th>200 Agent scalability</th>
[error]   </tr>
[error]  
[error]  
[error]   <tr id="row">
[error]           <td id="col">N/A</td><td class="error">N/A</td>
[error]          
[error]          
[error]          
[error]          
[error]          
[error]   </tr>
[error]  
[error]        
[error]  
[error]        
[error]       </table>
[error]    
[error]   </div>
[error]
[error]
[error] )' is not equal to 'temp' (AgentDetailsTestSpecs.scala:70)
[info] == code.snippet.AgentDetailsTestSpecs ==
[info]
[info] == test-finish ==
[error] Failed: : Total 2, Failed 2, Errors 0, Passed 0, Skipped 0
[info] == test-finish ==
[info]
[info] == test-cleanup ==
[info] == test-cleanup ==
[error] Error running code.snippet.AgentDetailsTestSpecs: Test FAILED
[error] Error running test-only: One or more subtasks failed
[info]
[info] Total time: 2 s, completed Feb 11, 2011 1:07:29 PM
1. Waiting for source changes... (press enter to interrupt)

> exit
[info]
[info] Total session time: 11 s, completed Feb 11, 2011 1:07:35 PM
[success] Build completed successfully.

Derek Chen-Becker

unread,
Feb 11, 2011, 3:24:09 PM2/11/11
to lif...@googlegroups.com
OK, it's just this simple. Add the following line to your SBT project source:

override def testClasspath  = super.testClasspath +++ ("src" / "main" / "webapp")
 
Please let me know if this work for you and then I'll put this up on the Wiki.

Derek

Diego Medina

unread,
Feb 11, 2011, 5:45:16 PM2/11/11
to lif...@googlegroups.com

Thanks !
I'll try it later tonight.

Diego Medina

Diego Medina

unread,
Feb 11, 2011, 11:24:08 PM2/11/11
to lif...@googlegroups.com
Derek, It worked perfectly!

Thanks very much.

Diego

Derek Chen-Becker

unread,
Feb 12, 2011, 1:03:52 PM2/12/11
to lif...@googlegroups.com
Cool! I'll update the Wiki. Also, I'm trying to think if there might be cleaner ways to unit test a template (perhaps withTemplateFor(...)?) that would wrap S.runTemplate and in the future hopefully run through LiftRules hooks for the template once we sort out LiftRules scoping. Any thoughts?

Derek

Diego Medina

unread,
Feb 12, 2011, 10:29:46 PM2/12/11
to lif...@googlegroups.com
On Sat, Feb 12, 2011 at 1:03 PM, Derek Chen-Becker
<dchen...@gmail.com> wrote:
> Cool! I'll update the Wiki. Also, I'm trying to think if there might be
> cleaner ways to unit test a template (perhaps withTemplateFor(...)?) that
> would wrap S.runTemplate and in the future hopefully run through LiftRules
> hooks for the template once we sort out LiftRules scoping. Any thoughts?
>

That sounds like a great addition, would it be possible to combine it
with a withSFor(...) as well?

something along the lines of:


"my simple test" withTemplateFor("html-template") withSFor(testReq) in {
val snippet = new SnippetClass
snippet.renderMethod mustEqual(<complete html template parsed by lift>)
}

Thanks

Diego

Derek Chen-Becker

unread,
Feb 19, 2011, 8:47:51 AM2/19/11
to lif...@googlegroups.com, Diego Medina
I was actually thinking that it would look like

"some test" withTemplateFor(request and/or String URL) in {
  templateResults => ... // We pass the resulting markup here, and S is initialized as well
}

So, for example

"must say hello" withTemplateFor("http://foo.com/helloWorld") in {
  _ must_== ...<span>Hello World!</span>...
}

Would that work or were you thinking of a different approach?

Derek

Timothy Perrett

unread,
Feb 19, 2011, 7:31:40 PM2/19/11
to lif...@googlegroups.com
This would be sweet!

Cheers, Tim
Reply all
Reply to author
Forward
0 new messages