org.specs.literate.LiterateShortcuts.scala Maven / Gradle / Ivy
/**
* Copyright (c) 2007-2009 Eric Torreborre
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software. Neither the name of specs nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written permission.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package org.specs.literate
import org.specs.specification._
import org.specs.execute._
import org.specs._
/**
* This trait adds shortcut methods to define expectations, to silence expressions
*/
trait LiterateShortcuts extends BaseSpecification with ExpectableFactory with FailOrSkip {
/**
* This method is used to silence the result of a call in an action. For example:
* The timer should be stopped {timer.stop.shh}
*
. This will not output the result of the stop method
*/
implicit def anyToShh(a: Any) = new Silenced
class Silenced {
def shh = ()
/** the pipe bar must be interpreted visually as a stop and the < sign as a pike. */
def <| = shh
}
/** This silence function allows to silence calls with this style: shh { a call } */
def shh(a: =>Any) = { a; () }
/**
* Create an anonymous example with a function on a System,
* giving it a number depending on the existing created examples
*/
def eg[S](function: S => Any): Unit = (forExample in function).shh
/** embeddeds a test into a new example and silence the result */
def eg(test: =>Any): Unit = (forExample in test).shh
/** create an anonymous example which will be skipped until it is implemented */
def notImplemented = forExample in { skip("PENDING: not yet implemented") }
/** return a String containing the output messages from the console with a given padding such as a newline for instance */
def consoleOutput(pad: String, messages: Seq[String]): String = { pad + consoleOutput(messages) }
/** return a String containing the output messages from the console */
def consoleOutput(messages: Seq[String]): String = messages.map("> " + _.toString).mkString("\n")
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy