Specs2 在 lift 中看不到定义的 class

Specs2 can't see a defined class in lift

这是代码(来自 Lift Framework Cookbook):

package code.snippet

import scala.xml.Text
import net.liftweb.util.Helpers._

/**
 * Created by kaiyin on 20/06/15.
 */
class Animals {
  def list = {
    val animals = List(
      ("Dog", "(Canis lupus)"),
      ("Cat", "(Felis catus)"),
      ("Giraffe", "(Giraffa camelopardalis)"),
      ("Lion", "(Panthera leo)"),
      ("Horse", "(Equus ferus caballus)")
    )
    "li *" #> animals.map{
      a =>
        ".name *" #> Text(a._1) &
        ".sname *" #> Text(a._2)
    }
  }
}

package code.snippet

/**
 * Created by kaiyin on 20/06/15.
 */

import org.specs2.mutable._

class AnimalsSpec extends Specification {
  "Animals list" should {
    "contains 5 animals" in {

      val result = <ul>
        <li><span class="name">Dog</span> - <span class="sname">(Canis lupus familiaris)</span> </li>
        <li><span class="name">Cat</span> - <span class="sname">(Felis catus)</span></li>
        <li><span class="name">Giraffe</span> - <span class="sname">(Giraffa camelopardalis)</span></li>
        <li><span class="name">Lion</span> - <span class="sname">(Panthera leo)</span></li>
        <li><span class="name">Horse</span> - <span class="sname">(Equus ferus caballus)</span></li>
      </ul>

      val nodeSeq = Animals.list(<ul><li><span class="name"></span> - <span class="sname"></span></li></ul>)
      nodeSeq.toString must ==/ (result)
//      result.toString must ==/ (result.toString)
    }
//    "trivial" in {
//      "what" must ==/ ("what")
//    }
  }
}

当我在sbt中test时,我得到一个错误:

[error] /private/tmp/lift-lift_26_sbt-d71cccf/scala_211/contacts-app/src/test/scala/code/snippet/AnimalsSpec.scala:21: not found: value Animals
[error]       val nodeSeq = Animals.list(<ul><li><span class="name"></span> - <span class="sname"></span></li></ul>)
[error]                     ^
[error] one error found
[error] (test:compile) Compilation failed
[error] Total time: 0 s, completed Jun 21, 2015 12:14:12 AM

似乎specs2无法识别Animals的存在class。

目录结构:

.
├── build.sbt
├── console.devmode.log
├── project
│   ├── build.properties
│   ├── plugins.sbt
│   ├── project
│   │   └── target
│   │       └── config-classes
│   │           ├── e6a7b084670fb8947b9$.class
│   │           ├── e6a7b084670fb8947b9.cache
│   │           ├── e6a7b084670fb8947b9.class
│   │           ├── ee94f9a958d7b2659d3$.class
│   │           ├── ee94f9a958d7b2659d3.cache
│   │           ├── ee94f9a958d7b2659d3.class
│   │           ├── $f7c7d83ab25f0dfdaa50$.class
│   │           ├── $f7c7d83ab25f0dfdaa50.cache
│   │           └── $f7c7d83ab25f0dfdaa50.class
│   └── target
│       ├── config-classes
│       │   ├── 49881d22cdcd44948f$$anonfun$$sbtdef.class
│       │   ├── 49881d22cdcd44948f$.class
│       │   ├── 49881d22cdcd44948f.cache
│       │   ├── 49881d22cdcd44948f.class
│       │   ├── 9c304e0f040361c72d$$anonfun$$sbtdef.class
│       │   ├── 9c304e0f040361c72d$.class
│       │   ├── 9c304e0f040361c72d.cache
│       │   ├── 9c304e0f040361c72d.class
│       │   ├── a1513b04e5e84f6d714$$anonfun$$sbtdef.class
│       │   ├── a1513b04e5e84f6d714$.class
│       │   ├── a1513b04e5e84f6d714.cache
│       │   ├── a1513b04e5e84f6d714.class
│       │   ├── 67d2a3c14aabb8a3f0$$anonfun$$sbtdef.class
│       │   ├── 67d2a3c14aabb8a3f0$.class
│       │   ├── 67d2a3c14aabb8a3f0.cache
│       │   ├── 67d2a3c14aabb8a3f0.class
│       │   ├── a0715de5358d1f4e97f$$anonfun$$sbtdef.class
│       │   ├── a0715de5358d1f4e97f$.class
│       │   ├── a0715de5358d1f4e97f.cache
│       │   ├── a0715de5358d1f4e97f.class
│       │   ├── ef5cf155e942bdbe26$$anonfun$$sbtdef.class
│       │   ├── ef5cf155e942bdbe26$.class
│       │   ├── ef5cf155e942bdbe26.cache
│       │   ├── ef5cf155e942bdbe26.class
│       │   ├── 96ca6e6d83674bcec7$$anonfun$$sbtdef.class
│       │   ├── 96ca6e6d83674bcec7$.class
│       │   ├── 96ca6e6d83674bcec7.cache
│       │   ├── 96ca6e6d83674bcec7.class
│       │   ├── 247c8be4b0760fec21$$anonfun$$sbtdef.class
│       │   ├── 247c8be4b0760fec21$.class
│       │   ├── 247c8be4b0760fec21.cache
│       │   ├── 247c8be4b0760fec21.class
│       │   ├── $ad1c698366eb4866d3f8$$anonfun$$sbtdef.class
│       │   ├── $ad1c698366eb4866d3f8$.class
│       │   ├── $ad1c698366eb4866d3f8.cache
│       │   ├── $ad1c698366eb4866d3f8.class
│       │   ├── $b5fc3f4c63982e743df0$$anonfun$$sbtdef.class
│       │   ├── $b5fc3f4c63982e743df0$.class
│       │   ├── $b5fc3f4c63982e743df0.cache
│       │   ├── $b5fc3f4c63982e743df0.class
│       │   ├── $cec870caf77a892e02d5$$anonfun$$sbtdef$$anonfun$apply.class
│       │   ├── $cec870caf77a892e02d5$$anonfun$$sbtdef.class
│       │   ├── $cec870caf77a892e02d5$.class
│       │   ├── $cec870caf77a892e02d5.cache
│       │   ├── $cec870caf77a892e02d5.class
│       │   ├── $e22cedfd25e30fceaff3$.class
│       │   ├── $e22cedfd25e30fceaff3.cache
│       │   ├── $e22cedfd25e30fceaff3.class
│       │   ├── $e73abf325c03d09873ef$$anonfun$$sbtdef.class
│       │   ├── $e73abf325c03d09873ef$.class
│       │   ├── $e73abf325c03d09873ef.cache
│       │   └── $e73abf325c03d09873ef.class
│       ├── resolution-cache
│       │   ├── default
│       │   │   └── contacts-app-build
│       │   │       └── scala_2.10
│       │   │           └── sbt_0.13
│       │   │               └── 0.1-SNAPSHOT
│       │   │                   ├── resolved.xml.properties
│       │   │                   └── resolved.xml.xml
│       │   └── reports
│       │       ├── default-contacts-app-build-compile-internal.xml
│       │       ├── default-contacts-app-build-compile.xml
│       │       ├── default-contacts-app-build-docs.xml
│       │       ├── default-contacts-app-build-optional.xml
│       │       ├── default-contacts-app-build-plugin.xml
│       │       ├── default-contacts-app-build-pom.xml
│       │       ├── default-contacts-app-build-provided.xml
│       │       ├── default-contacts-app-build-runtime-internal.xml
│       │       ├── default-contacts-app-build-runtime.xml
│       │       ├── default-contacts-app-build-scala-tool.xml
│       │       ├── default-contacts-app-build-sources.xml
│       │       ├── default-contacts-app-build-test-internal.xml
│       │       ├── default-contacts-app-build-test.xml
│       │       ├── ivy-report.css
│       │       └── ivy-report.xsl
│       ├── scala-2.10
│       │   └── sbt-0.13
│       └── streams
│           ├── $global
│           │   ├── $global
│           │   │   └── $global
│           │   │       └── out
│           │   ├── ivyConfiguration
│           │   │   └── $global
│           │   │       └── out
│           │   ├── ivySbt
│           │   │   └── $global
│           │   │       └── out
│           │   ├── projectDescriptors
│           │   │   └── $global
│           │   │       └── out
│           │   └── update
│           │       └── $global
│           │           ├── inputs
│           │           ├── out
│           │           └── output
│           ├── compile
│           │   ├── $global
│           │   │   └── $global
│           │   │       └── data
│           │   ├── compile
│           │   │   └── $global
│           │   │       ├── export
│           │   │       └── out
│           │   ├── copyResources
│           │   │   └── $global
│           │   │       ├── copy-resources
│           │   │       └── out
│           │   ├── definedSbtPlugins
│           │   │   └── $global
│           │   │       └── out
│           │   ├── dependencyClasspath
│           │   │   └── $global
│           │   │       └── export
│           │   ├── exportedProducts
│           │   │   └── $global
│           │   │       └── export
│           │   ├── externalDependencyClasspath
│           │   │   └── $global
│           │   │       └── export
│           │   ├── incCompileSetup
│           │   │   └── $global
│           │   ├── internalDependencyClasspath
│           │   │   └── $global
│           │   │       └── export
│           │   ├── managedClasspath
│           │   │   └── $global
│           │   │       └── export
│           │   ├── unmanagedClasspath
│           │   │   └── $global
│           │   │       └── export
│           │   └── unmanagedJars
│           │       └── $global
│           │           └── export
│           └── runtime
│               ├── dependencyClasspath
│               │   └── $global
│               │       └── export
│               ├── exportedProducts
│               │   └── $global
│               │       └── export
│               ├── externalDependencyClasspath
│               │   └── $global
│               │       └── export
│               ├── fullClasspath
│               │   └── $global
│               │       └── export
│               ├── internalDependencyClasspath
│               │   └── $global
│               │       └── export
│               ├── managedClasspath
│               │   └── $global
│               │       └── export
│               ├── unmanagedClasspath
│               │   └── $global
│               │       └── export
│               └── unmanagedJars
│                   └── $global
│                       └── export
├── sbt
├── sbt-launch-0.13.1.jar
├── sbt.bat
├── src
│   ├── main
│   │   ├── resources
│   │   │   ├── logback.xml
│   │   │   ├── props
│   │   │   │   └── default.props
│   │   │   ├── resources.properties
│   │   │   ├── resources_de.properties
│   │   │   └── resources_fr_FR.properties
│   │   ├── scala
│   │   │   ├── bootstrap
│   │   │   │   └── liftweb
│   │   │   │       └── Boot.scala
│   │   │   └── code
│   │   │       ├── comet
│   │   │       ├── lib
│   │   │       │   └── SendEmail.scala
│   │   │       ├── model
│   │   │       ├── snippet
│   │   │       │   ├── Animals.scala
│   │   │       │   ├── Calculator.scala
│   │   │       │   ├── EmailSnippet.scala
│   │   │       │   ├── HelloWorld.scala
│   │   │       │   ├── Inner.scala
│   │   │       │   ├── ListUser.scala
│   │   │       │   ├── Localization.scala
│   │   │       │   ├── Outer.scala
│   │   │       │   └── Table.scala
│   │   │       └── view
│   │   └── webapp
│   │       ├── WEB-INF
│   │       │   └── web.xml
│   │       ├── contacts
│   │       │   ├── create.html
│   │       │   ├── delete.html
│   │       │   ├── edit.html
│   │       │   ├── list.html
│   │       │   └── view.html
│   │       ├── images
│   │       │   └── ajax-loader.gif
│   │       ├── index.html
│   │       ├── send.html
│   │       ├── static
│   │       │   └── index.html
│   │       └── templates-hidden
│   │           ├── default.html
│   │           └── wizard-all.html
│   └── test
│       ├── resources
│       │   └── logback-test.xml
│       └── scala
│           ├── RunWebApp.scala
│           └── code
│               └── snippet
│                   └── AnimalsSpec.scala
└── target
    ├── resolution-cache
    │   ├── net.liftweb
    │   │   └── lift-2-6-starter-template_2.11
    │   │       └── 0.0.4
    │   │           ├── resolved.xml.properties
    │   │           └── resolved.xml.xml
    │   └── reports
    │       ├── ivy-report.css
    │       ├── ivy-report.xsl
    │       ├── net.liftweb-lift-2-6-starter-template_2.11-compile-internal.xml
    │       ├── net.liftweb-lift-2-6-starter-template_2.11-compile.xml
    │       ├── net.liftweb-lift-2-6-starter-template_2.11-container.xml
    │       ├── net.liftweb-lift-2-6-starter-template_2.11-docs.xml
    │       ├── net.liftweb-lift-2-6-starter-template_2.11-optional.xml
    │       ├── net.liftweb-lift-2-6-starter-template_2.11-plugin.xml
    │       ├── net.liftweb-lift-2-6-starter-template_2.11-pom.xml
    │       ├── net.liftweb-lift-2-6-starter-template_2.11-provided.xml
    │       ├── net.liftweb-lift-2-6-starter-template_2.11-runtime-internal.xml
    │       ├── net.liftweb-lift-2-6-starter-template_2.11-runtime.xml
    │       ├── net.liftweb-lift-2-6-starter-template_2.11-scala-tool.xml
    │       ├── net.liftweb-lift-2-6-starter-template_2.11-sources.xml
    │       ├── net.liftweb-lift-2-6-starter-template_2.11-test-internal.xml
    │       └── net.liftweb-lift-2-6-starter-template_2.11-test.xml
    ├── scala-2.11
    │   ├── classes
    │   │   ├── bootstrap
    │   │   │   └── liftweb
    │   │   │       ├── Boot$$anonfun.class
    │   │   │       ├── Boot$$anonfun.class
    │   │   │       ├── Boot$$anonfun.class
    │   │   │       ├── Boot$$anonfun.class
    │   │   │       ├── Boot$$anonfun.class
    │   │   │       ├── Boot$$anonfun.class
    │   │   │       ├── Boot$$anonfun.class
    │   │   │       ├── Boot$$anonfun$$anonfun$apply$mcZ$sp.class
    │   │   │       ├── Boot$$anonfun$$anonfun$apply$mcZ$sp.class
    │   │   │       ├── Boot$$anonfun.class
    │   │   │       ├── Boot$$anonfun.class
    │   │   │       ├── Boot$$anonfun.class
    │   │   │       ├── Boot$$anonfun.class
    │   │   │       ├── Boot$$anonfun.class
    │   │   │       ├── Boot$$anonfun.class
    │   │   │       ├── Boot$$anonfun.class
    │   │   │       ├── Boot$$anonfun.class
    │   │   │       ├── Boot$$anonfun$boot.class
    │   │   │       ├── Boot$$anonfun$boot.class
    │   │   │       ├── Boot$$anonfun$boot.class
    │   │   │       ├── Boot$$anonfun$configureMailer$$anonfun$apply$$anon.class
    │   │   │       ├── Boot$$anonfun$configureMailer$$anonfun$apply.class
    │   │   │       ├── Boot$$anonfun$configureMailer.class
    │   │   │       └── Boot.class
    │   │   ├── code
    │   │   │   ├── lib
    │   │   │   │   ├── SendEmail$.class
    │   │   │   │   └── SendEmail.class
    │   │   │   └── snippet
    │   │   │       ├── Animals$$anonfun$list$$anonfun$apply$$anonfun$apply.class
    │   │   │       ├── Animals$$anonfun$list$$anonfun$apply$$anonfun$apply.class
    │   │   │       ├── Animals$$anonfun$list$$anonfun$apply.class
    │   │   │       ├── Animals$$anonfun$list.class
    │   │   │       ├── Animals.class
    │   │   │       ├── Calculator$$anonfun$plus.class
    │   │   │       ├── Calculator.class
    │   │   │       ├── EmailSnippet$$anonfun$sendEmail$$anonfun$apply.class
    │   │   │       ├── EmailSnippet$$anonfun$sendEmail.class
    │   │   │       ├── EmailSnippet$$anonfun$sendNow.class
    │   │   │       ├── EmailSnippet.class
    │   │   │       ├── HelloWorld$$anonfun$howdy.class
    │   │   │       ├── HelloWorld.class
    │   │   │       ├── Inner$$anonfun$logged.class
    │   │   │       ├── Inner$$anonfun$nonlogged.class
    │   │   │       ├── Inner.class
    │   │   │       ├── ListUser$$anonfun$list.class
    │   │   │       ├── ListUser$$anonfun$list$$anonfun$apply.class
    │   │   │       ├── ListUser$$anonfun$list.class
    │   │   │       ├── ListUser$$anonfun$log.class
    │   │   │       ├── ListUser$$anonfun$log.class
    │   │   │       ├── ListUser$$anonfun$log.class
    │   │   │       ├── ListUser.class
    │   │   │       ├── Localization$$anonfun$dynamic.class
    │   │   │       ├── Localization.class
    │   │   │       ├── Outer$$anonfun.class
    │   │   │       ├── Outer$$anonfun$choose.class
    │   │   │       ├── Outer$$anonfun$choose.class
    │   │   │       ├── Outer.class
    │   │   │       ├── Table$$anonfun$$anonfun$apply.class
    │   │   │       ├── Table$$anonfun.class
    │   │   │       ├── Table$$anonfun$dynamic.class
    │   │   │       ├── Table$$anonfun$dynamic.class
    │   │   │       ├── Table$$anonfun$dynamic$$anonfun$apply$$anonfun$apply.class
    │   │   │       ├── Table$$anonfun$dynamic$$anonfun$apply$$anonfun$apply.class
    │   │   │       ├── Table$$anonfun$dynamic$$anonfun$apply.class
    │   │   │       ├── Table$$anonfun$dynamic.class
    │   │   │       └── Table.class
    │   │   ├── logback.xml
    │   │   ├── props
    │   │   │   └── default.props
    │   │   ├── resources.properties
    │   │   ├── resources_de.properties
    │   │   └── resources_fr_FR.properties
    │   └── test-classes
    │       ├── RunWebApp$.class
    │       ├── RunWebApp$delayedInit$body.class
    │       ├── RunWebApp.class
    │       ├── WEB-INF
    │       │   └── web.xml
    │       ├── code
    │       │   └── snippet
    │       │       ├── AnimalsSpec$$anonfun$$anonfun$apply$$anonfun$apply.class
    │       │       ├── AnimalsSpec$$anonfun$$anonfun$apply$$anonfun$apply.class
    │       │       ├── AnimalsSpec$$anonfun$$anonfun$apply.class
    │       │       ├── AnimalsSpec$$anonfun$$anonfun$apply$$anonfun$apply.class
    │       │       ├── AnimalsSpec$$anonfun$$anonfun$apply$$anonfun$apply.class
    │       │       ├── AnimalsSpec$$anonfun$$anonfun$apply.class
    │       │       ├── AnimalsSpec$$anonfun.class
    │       │       └── AnimalsSpec.class
    │       ├── contacts
    │       │   ├── create.html
    │       │   ├── delete.html
    │       │   ├── edit.html
    │       │   ├── list.html
    │       │   └── view.html
    │       ├── images
    │       │   └── ajax-loader.gif
    │       ├── index.html
    │       ├── logback-test.xml
    │       ├── send.html
    │       ├── static
    │       │   └── index.html
    │       └── templates-hidden
    │           ├── default.html
    │           └── wizard-all.html
    ├── specs2-reports
    │   └── stats
    │       └── code.snippet.AnimalsSpec.stats
    └── streams
        ├── $global
        │   ├── $global
        │   │   └── $global
        │   │       └── out
        │   ├── ivyConfiguration
        │   │   └── $global
        │   │       └── out
        │   ├── ivySbt
        │   │   └── $global
        │   │       └── out
        │   ├── projectDescriptors
        │   │   └── $global
        │   │       └── out
        │   └── update
        │       └── $global
        │           ├── inputs
        │           ├── out
        │           └── output
        ├── compile
        │   ├── $global
        │   │   └── $global
        │   │       └── data
        │   ├── compile
        │   │   └── $global
        │   │       ├── export
        │   │       └── out
        │   ├── copyResources
        │   │   └── $global
        │   │       ├── copy-resources
        │   │       └── out
        │   ├── dependencyClasspath
        │   │   └── $global
        │   │       └── export
        │   ├── exportedProducts
        │   │   └── $global
        │   │       └── export
        │   ├── externalDependencyClasspath
        │   │   └── $global
        │   │       └── export
        │   ├── incCompileSetup
        │   │   └── $global
        │   │       └── inc_compile
        │   ├── internalDependencyClasspath
        │   │   └── $global
        │   │       └── export
        │   ├── managedClasspath
        │   │   └── $global
        │   │       └── export
        │   ├── unmanagedClasspath
        │   │   └── $global
        │   │       └── export
        │   └── unmanagedJars
        │       └── $global
        │           └── export
        ├── container
        │   └── $global
        │       └── $global
        │           └── data
        ├── runtime
        │   ├── dependencyClasspath
        │   │   └── $global
        │   │       └── export
        │   ├── exportedProducts
        │   │   └── $global
        │   │       └── export
        │   ├── externalDependencyClasspath
        │   │   └── $global
        │   │       └── export
        │   ├── fullClasspath
        │   │   └── $global
        │   │       └── export
        │   ├── internalDependencyClasspath
        │   │   └── $global
        │   │       └── export
        │   ├── managedClasspath
        │   │   └── $global
        │   │       └── export
        │   ├── unmanagedClasspath
        │   │   └── $global
        │   │       └── export
        │   └── unmanagedJars
        │       └── $global
        │           └── export
        └── test
            ├── $global
            │   └── $global
            │       └── data
            ├── compile
            │   └── $global
            │       ├── export
            │       └── out
            ├── copyResources
            │   └── $global
            │       ├── copy-resources
            │       └── out
            ├── definedTests
            │   └── $global
            │       └── out
            ├── dependencyClasspath
            │   └── $global
            │       └── export
            ├── exportedProducts
            │   └── $global
            │       └── export
            ├── externalDependencyClasspath
            │   └── $global
            │       └── export
            ├── fullClasspath
            │   └── $global
            │       └── export
            ├── incCompileSetup
            │   └── $global
            │       └── inc_compile
            ├── internalDependencyClasspath
            │   └── $global
            │       └── export
            ├── loadedTestFrameworks
            │   └── $global
            │       └── out
            ├── managedClasspath
            │   └── $global
            │       └── export
            ├── test
            │   ├── $global
            │   │   ├── out
            │   │   └── succeeded_tests
            │   └── isModule=false\ name=code.snippet.AnimalsSpec
            │       └── out
            ├── unmanagedClasspath
            │   └── $global
            │       └── export
            └── unmanagedJars
                └── $global
                    └── export

204 directories, 304 files

目前没有编译器,但是你不应该使用 new 因为它是 class 而不是对象吗?

val nodeSeq = Animals.list(...)

应该是

val nodeSeq = new Animals.list(...)

或者您可以将 class Animals 更改为 object Animals