This is strange, this simple one-file spec & filter seem to work for me
package com.matygo.controllers.discussion
import org.scalatra.ScalatraFilter
import org.scalatra.test.specs.ScalatraSpecification
class TopicsController extends ScalatraFilter {
get("/test") {
"hi!"
}
}
class TopicsControllerTest extends ScalatraSpecification {
addFilter(classOf[TopicsController], "/*")
"TopicsController when using GET" should {
"simple test" in {
1 must be(1)
}
"simple call" in {
get("/test") {
body must be_==("hi!")
}
}
}
}
could you try this and see if it works?
The only thing that does not seem right in your code is that addFilter
should probably be called like
addFilter(classOf[TopicsController], "/*")
(notice the asterisk which is missing in your code AFAICT)
but your basic 1=1 test should still work
--
blog en: http://www.riffraff.info
blog it: http://riffraff.blogsome.com
work: http://cascaad.com
I suspect that your TopicsController is throwing an exception in its
constructor. There is a newer version of Specs (1.6.7) that gives a
nicer stack trace
(http://code.google.com/p/specs/issues/detail?id=165). I'll upgrade
the transitive dependency for scalatra-specs. In the meantime, you
can upgrade it yourself. Add this to your sbt project:
val specs = "org.scala-tools.testing" %% "specs" % "1.6.7" % "test"
Also, you almost certainly want specs, scalatra-test, scalatra-specs,
and scalatra-scalatest in the test configuration. That's what the '%
"test"' after the version number is all about. If you leave them in
the default configuration, then those libraries will be bundled with
your war. Do an 'sbt clean-lib' and 'sbt update' just to be sure that
you don't have anything stale hanging around after those changes.
--
Ross A. Baker
ba...@alumni.indiana.edu
Indianapolis, IN, USA
I got a slightly more informative exception, but still not super helpful:
The problem appears to start in the addFilter method.
[error] Could not create an instance of com.matygo.controllers.discussion.TopicsControllerTest
[error]
[error] org.eclipse.jetty.servlet.ServletContextHandler.addFilter(Lorg/eclipse/jetty/servlet/FilterHolder;Ljava/lang/String;I)V
[error]
[error] org.scalatra.test.ScalatraTests$class.addFilter(ScalatraTests.scala:80)
[error] com.matygo.controllers.discussion.TopicsControllerTest.addFilter(TopicsControllerTest.scala:12)
[error] com.matygo.controllers.discussion.TopicsControllerTest.<init>(TopicsControllerTest.scala:15)
[error] sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[error] sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
[error] sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
[error] java.lang.reflect.Constructor.newInstance(Constructor.java:513)
[error] org.specs.util.Classes$class.createInstanceFor(Classes.scala:88)
[error] org.specs.util.Classes$.createInstanceFor(Classes.scala:29)
[error] org.specs.util.Classes$class.create(Classes.scala:40)
[error] org.specs.util.Classes$.create(Classes.scala:29)
[error] org.specs.runner.TestInterfaceRunner.run(TestInterfaceRunner.scala:55)
[error] sbt.TestRunner.run(TestFramework.scala:53)
[error] sbt.TestRunner.runTest$1(TestFramework.scala:67)
[error] sbt.TestRunner.run(TestFramework.scala:76)
[error] sbt.TestFramework$$anonfun$10$$anonfun$apply$11.runTest$2(TestFramework.scala:194)
[error] sbt.TestFramework$$anonfun$10$$anonfun$apply$11$$anonfun$apply$12.apply(TestFramework.scala:205)
[error] sbt.TestFramework$$anonfun$10$$anonfun$apply$11$$anonfun$apply$12.apply(TestFramework.scala:205)
[error] sbt.NamedTestTask.run(TestFramework.scala:92)
[error] sbt.ScalaProject$$anonfun$sbt$ScalaProject$$toTask$1.apply(ScalaProject.scala:193)
[error] sbt.ScalaProject$$anonfun$sbt$ScalaProject$$toTask$1.apply(ScalaProject.scala:193)
[error] sbt.TaskManager$Task.invoke(TaskManager.scala:62)
[error] sbt.impl.RunTask.doRun$1(RunTask.scala:77)
[error] sbt.impl.RunTask.runTask(RunTask.scala:85)
[error] sbt.impl.RunTask.sbt$impl$RunTask$$runIfNotRoot(RunTask.scala:60)
[error] sbt.impl.RunTask$$anonfun$runTasksExceptRoot$2.apply(RunTask.scala:48)
[error] sbt.impl.RunTask$$anonfun$runTasksExceptRoot$2.apply(RunTask.scala:48)
[error] sbt.Distributor$Run$Worker$$anonfun$2.apply(ParallelRunner.scala:131)
[error] sbt.Distributor$Run$Worker$$anonfun$2.apply(ParallelRunner.scala:131)
[error] sbt.Control$.trapUnit(Control.scala:19)
[error] sbt.Distributor$Run$Worker.run(ParallelRunner.scala:131)
.joe
On 2011-02-27, at 11:08 AM, Ross A. Baker wrote:
Hmm... you must be using Jetty 8. ScalatraTests is build against
7.2.2.v20101205, and I see that the addFilter overload we use has been
removed. If you can, use that version of Jetty for now, and we'll add
an issue to make it compatible with both.