/scalate-core/src/test/scala/org/fusesource/scalate/FunSuiteSupport.scala

http://github.com/scalate/scalate · Scala · 66 lines · 30 code · 10 blank · 26 comment · 1 complexity · 6298b99cf962a7c7164ce243281f4b82 MD5 · raw file

  1. /**
  2. * Copyright (C) 2009-2011 the original author or authors.
  3. * See the notice.md file distributed with this work for additional
  4. * information regarding copyright ownership.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. package org.fusesource.scalate
  19. import java.io.File
  20. import org.fusesource.scalate.scuery.XmlHelper._
  21. import org.fusesource.scalate.util.Log
  22. import org.junit.runner.RunWith
  23. import org.scalatest.junit.JUnitRunner
  24. import org.scalatest.{ BeforeAndAfterAllConfigMap, ConfigMap, FunSuite }
  25. import scala.xml.NodeSeq
  26. /**
  27. * @version $Revision : 1.1 $
  28. */
  29. @RunWith(classOf[JUnitRunner])
  30. abstract class FunSuiteSupport extends FunSuite with Log with BeforeAndAfterAllConfigMap {
  31. protected var _basedir = "."
  32. /**
  33. * Returns the base directory of the current project
  34. */
  35. def baseDir = new File(_basedir)
  36. override protected def beforeAll(map: ConfigMap): Unit = {
  37. _basedir = map.get("basedir") match {
  38. case Some(basedir) => basedir.toString
  39. case _ => System.getProperty("basedir", ".")
  40. }
  41. debug("using basedir: %s", _basedir)
  42. }
  43. def assertSize(selector: String, result: NodeSeq, expected: Int): Unit = {
  44. assertResult(expected, "number of elements matching: " + selector) { result.$(selector).size }
  45. }
  46. /**
  47. * Asserts that the text value of the given selector matches the expected string
  48. */
  49. def assertText(selector: String, result: NodeSeq, expected: String): Unit = {
  50. assertResult(expected, "text of elements matching: " + selector) { result.$(selector).text }
  51. }
  52. def assertType(anyRef: AnyRef, expectedClass: Class[_]): Unit = {
  53. assert(anyRef != null, "expected instance of " + expectedClass.getName)
  54. assertResult(expectedClass) { anyRef.getClass }
  55. }
  56. }