ScalatraSpecification problem

65 views
Skip to first unread message

Joe Gaudet

unread,
Feb 27, 2011, 5:16:05 AM2/27/11
to scalatra-user
I've been having trouble running ScalatraSpecifications

TopicsController is pretty straightforward filter, at any rate when I
run the following spec from sbt I get a huge exception trace (included
below)

I've tried updating everything, (I am using the latest snap shot of
scalatra + spec etc).

Any thoughts / help would be appreciated.

class TopicsControllerTest extends ScalatraSpecification {
addFilter(classOf[TopicsController], "/")

"TopicsController when using GET" should {
"simple test" in {
1 must be(1)
}
}
}


[error] Could not create an instance of
com.matygo.controllers.discussion.TopicsControllerTest
[error]
[error] null
[error]
[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:
78)
[error] org.specs.util.Classes$.createInstanceFor(Classes.scala:27)
[error] org.specs.util.Classes$class.create(Classes.scala:38)
[error] org.specs.util.Classes$.create(Classes.scala:27)
[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)
[error]
org.eclipse.jetty.testing.ServletTester.addFilter(ServletTester.java:
233)
[error] org.scalatra.test.ScalatraTests
$class.addFilter(ScalatraTests.scala:83)
[error]
com.matygo.controllers.discussion.TopicsControllerTest.addFilter(TopicsControllerTest.scala:
12)
[error]
com.matygo.controllers.discussion.TopicsControllerTest.<init>(TopicsControllerTest.scala:
16)
[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:
78)
[error] org.specs.util.Classes$.createInstanceFor(Classes.scala:27)
[error] org.specs.util.Classes$class.create(Classes.scala:38)
[error] org.specs.util.Classes$.create(Classes.scala:27)
[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)

gabriele renzi

unread,
Feb 27, 2011, 12:13:13 PM2/27/11
to scalat...@googlegroups.com, Joe Gaudet
On Sun, Feb 27, 2011 at 11:16 AM, Joe Gaudet <j...@matygo.com> wrote:
> I've been having trouble running ScalatraSpecifications
>
> TopicsController is pretty straightforward filter, at any rate when I
> run the following spec from sbt I get a huge exception trace (included
> below)
>
> I've tried updating everything, (I am using the latest snap shot of
> scalatra + spec etc).
>
> Any thoughts / help would be appreciated.
>
> class TopicsControllerTest extends ScalatraSpecification {
>    addFilter(classOf[TopicsController], "/")
>
>    "TopicsController when using GET" should {
>        "simple test" in {
>            1 must be(1)
>        }
>    }
> }
>

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

Ross A. Baker

unread,
Feb 27, 2011, 2:08:56 PM2/27/11
to scalat...@googlegroups.com
On Sun, Feb 27, 2011 at 5:16 AM, Joe Gaudet <j...@matygo.com> wrote:
> I've been having trouble running ScalatraSpecifications
>
> TopicsController is pretty straightforward filter, at any rate when I
> run the following spec from sbt I get a huge exception trace (included
> below)
>
> I've tried updating everything, (I am using the latest snap shot of
> scalatra + spec etc).
>
> Any thoughts / help would be appreciated.
>
> class TopicsControllerTest extends ScalatraSpecification {
>    addFilter(classOf[TopicsController], "/")
>
>    "TopicsController when using GET" should {
>        "simple test" in {
>            1 must be(1)
>        }
>    }
> }
>
>
> [error] Could not create an instance of
> com.matygo.controllers.discussion.TopicsControllerTest
> [error]
> [error]   null
> [error]
> [error]
> sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
> [error]
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:
> 39)

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

Joe Gaudet

unread,
Feb 27, 2011, 3:43:56 PM2/27/11
to scalat...@googlegroups.com
Thanks guys for your responses, I updated all the bits and moved them into the test config as you suggested.

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 Gaudet

unread,
Feb 27, 2011, 3:54:36 PM2/27/11
to scalat...@googlegroups.com
I should add that if I manually instantiate the TopicsController before hand and pass the instance of it to the addFilter routine, it still pitches a fit.

.joe


On 2011-02-27, at 11:08 AM, Ross A. Baker wrote:

Ross A. Baker

unread,
Feb 27, 2011, 4:24:07 PM2/27/11
to scalat...@googlegroups.com
On Sun, Feb 27, 2011 at 3:43 PM, Joe Gaudet <j...@matygo.com> wrote:
> Thanks guys for your responses, I updated all the bits and moved them into the test config as you suggested.
>
> 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

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.

Reply all
Reply to author
Forward
0 new messages