PageRenderTime 15ms CodeModel.GetById 11ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/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 */
18package org.fusesource.scalate
19
20import java.io.File
21
22import org.fusesource.scalate.scuery.XmlHelper._
23import org.fusesource.scalate.util.Log
24import org.junit.runner.RunWith
25import org.scalatest.junit.JUnitRunner
26import org.scalatest.{ BeforeAndAfterAllConfigMap, ConfigMap, FunSuite }
27
28import scala.xml.NodeSeq
29
30/**
31 * @version $Revision : 1.1 $
32 */
33@RunWith(classOf[JUnitRunner])
34abstract class FunSuiteSupport extends FunSuite with Log with BeforeAndAfterAllConfigMap {
35
36  protected var _basedir = "."
37
38  /**
39   * Returns the base directory of the current project
40   */
41  def baseDir = new File(_basedir)
42
43  override protected def beforeAll(map: ConfigMap): Unit = {
44    _basedir = map.get("basedir") match {
45      case Some(basedir) => basedir.toString
46      case _ => System.getProperty("basedir", ".")
47    }
48    debug("using basedir: %s", _basedir)
49  }
50
51  def assertSize(selector: String, result: NodeSeq, expected: Int): Unit = {
52    assertResult(expected, "number of elements matching: " + selector) { result.$(selector).size }
53  }
54
55  /**
56   * Asserts that the text value of the given selector matches the expected string
57   */
58  def assertText(selector: String, result: NodeSeq, expected: String): Unit = {
59    assertResult(expected, "text of elements matching: " + selector) { result.$(selector).text }
60  }
61
62  def assertType(anyRef: AnyRef, expectedClass: Class[_]): Unit = {
63    assert(anyRef != null, "expected instance of " + expectedClass.getName)
64    assertResult(expectedClass) { anyRef.getClass }
65  }
66}