org.specs.Contexts

trait Contexts

trait Contexts

 extends SpecificationStructure


This traits adds before / after capabilities to specifications, so that a context can be defined for each system under test being specified.


Source: Context.scala(17)

Direct Known Subclasses

Specification,

Nested Classes

ShortActions, ToContext,

 Fields

acceptAnyTag def acceptAnyTag
reset accepted and rejected to an empty queue
Tagged Tagged
accepted val accepted
list of tags which are accepted for this element
Queue[Tag] Tagged
addExpectation def addExpectation Example ExampleExpectationsListener
afterSpec var afterSpec
the afterAllSystems function will be invoked after all systems
Option[() => Any] SpecificationStructure
allSystems def allSystems
Return all the systems for this specification, including the ones from the sub-specifications (recursively)
List[Sus] SpecificationStructure
beforeSpec var beforeSpec
the beforeAllSystems function will be invoked before all systems
Option[() => Any] SpecificationStructure
clearTags def clearTags
Clear all tags, accepted and rejected
Tagged Tagged
currentLifeCycle protected[this] def currentLifeCycle ExampleLifeCycle SpecificationStructure
currentSus protected[this] def currentSus
utility method to track the last sus being currently defined, in order to be able to add examples to it
Sus SpecificationStructure
description var description
description of the specification
String SpecificationStructure
example protected[this] var example Option[Example] ExampleLifeCycle
forExample def forExample
Create an anonymous example, giving it a number depending on the existing created examples/
Example SpecificationStructure
isAccepted def isAccepted
Return true if this Tagged element:
  • doesn't have any tags and no tags are marked as accepted
  • or doesn't have any accepted tags
  • or has at least one of the accepted tags and doesn't have any of the rejected tags
[details]
return
- true if the element can be accepted, considering the tags it owns and the accepted/rejected tags
Boolean Tagged
isSequential def isSequential Boolean ExampleLifeCycle
lastExample def lastExample
Return the example being currently executed if any
Option[Example] SpecificationStructure
name var name
name of the specification
String SpecificationStructure
rejected val rejected
list of tags which are rejected for this element
Queue[Tag] Tagged
sequential protected var sequential Boolean ExampleLifeCycle
subSpecifications var subSpecifications
specifications contained by the current specification [details]
An empty list by default
List[Specification] SpecificationStructure
systems var systems
list of systems under test
List[Sus] SpecificationStructure
tagSpec def tagSpec
[details]
return
- a description of the Tagged element showing the owned tags, the accepted and rejected tags
String Tagged
taggedComponents def taggedComponents
this method should be overriden if the Tagged element has Tagged components which should be tagged when this element is tagged
Seq[Tagged] Tagged
tags val tags
list of all tags
Queue[Tag] Tagged
until def until Boolean ExampleLifeCycle

 Methods

!= final def !=(arg0 : Any) Boolean Any
!= final def !=(arg0 : Object) Boolean AnyRef
== final def ==(arg0 : Object) Boolean AnyRef
== final def ==(arg0 : Any) Boolean Any
accept def accept(t : Tag*)
Declare that this element should be accepted only if it has one of the accepted tags [details]
This method declares the same thing for the components of this element.
Tagged Tagged
acceptTag def acceptTag(s : String*)
alias for the acceptTag method
Tagged Tagged
acceptTags def acceptTags(s : String*)
alias for the accept method with strings
Tagged Tagged
addExpectation def addExpectation[T](expectable : Option[Expectable[T]])
Add an expectation to the last created example [details]
If there is none, create a new one with the forExample function. If an expectable is given, then this expectable should be assigned the created example. This is the case when adding an expectation for a one-liner jmock expectation:
     // in the expects method a new expectation is created with isExpectation
     // see org.specs.mock.JMocker
     classOf[MyClass].expects(one(_).method) in { _.method }
   
Example ExampleExpectationsListener
addTag def addTag(t : String)
Add one tag to this element
Tagged Tagged
addTags def addTags(t : String*)
Add one or several tags to this element
Tagged Tagged
addToSusVerb def addToSusVerb(complement : String)
add a textual complement to the sus verb [details]
For example, it is possible to declare: "the system" should provide {...} if the following function is declared: def provide = addToSusVerb("provide")
(Example) => Example SpecificationStructure
afterContext def afterContext(actions : => Any)
Factory method to create a context with after only actions
Context
afterContext def afterContext(actions : => Any, predicate : => Boolean)
Factory method to create a context with after only actions and an until predicate
Context
afterExample override def afterExample(ex : Example)
override the afterExample method to execute actions after the last example of the last sus
Unit SpecificationStructure
afterTest def afterTest(ex : Example) Unit ExampleLifeCycle
anyToExpectationCounter implicit def anyToExpectationCounter[T](a : => T)
Adds an isExpectation method to any block of code (mock expectation, scalacheck property) to better count the number of expectations
ExpectationCounter[T] ExpectationsListener
areSpecifiedBy def areSpecifiedBy(specifications : Specification*)
alias for isSpecifiedBy
Unit SpecificationStructure
asInstanceOf final def asInstanceOf[T0] T0 Any
beforeContext def beforeContext(actions : => Any, predicate : => Boolean)
Factory method to create a context with before only actions and an until predicate
Context
beforeContext def beforeContext(actions : => Any)
Factory method to create a context with before only actions
Context
beforeExample override def beforeExample(ex : Example)
override the beforeExample method to execute actions before the first example of the first sus
Unit SpecificationStructure
beforeTest def beforeTest(ex : Example) Unit ExampleLifeCycle
clone protected def clone Object AnyRef
context def context(b : => Any, a : => Any, predicate : => Boolean)
Factory method to create a context with before/after actions and an until predicate
Context
context def context(b : => Any, a : => Any)
Factory method to create a context with after only actions
Context
contextFirst def contextFirst(actions : => Any)
Factory method to create a context with beforeAll only actions
Context
contextLast def contextLast(actions : => Any)
Factory method to create a context with afterAll actions
Context
createDescription def createDescription(s : String)
[details]
return
- a description from the class name, taking the last name which doesn't contain a $ or a number. For example: com.pack1.MyClass$1$ will:
  • split on $ and reverse: [1, com.pack1.MyClass]
  • drop the every element which is an integer -> [com.pack1.MyClass]
  • take the first element: com.pack1.MyClass
  • split on . and reverse: [MyClass, pack1, com]
  • take the last element: MyClass
String SpecificationStructure
declare implicit def declare(d : String)
implicit definition allowing to declare a composition inside the current specification: "A complex specification" [details]
isSpecifiedBy(spec1, spec2)
SpecificationStructure SpecificationStructure
doAfter def doAfter(actions : => Any)
adds an "after" function to the last sus being defined
Unit
doAfterSpec def doAfterSpec(actions : => Any)
adds a "afterSpec" function to the current specification
Unit
doBefore def doBefore(actions : => Any)
adds a "before" function to the last sus being defined
Unit
doBeforeSpec def doBeforeSpec(actions : => Any)
adds a "beforeSpec" function to the current specification
Unit
doFirst def doFirst(actions : => Any)
adds a "firstActions" function to the last sus being defined
Unit
doLast def doLast(actions : => Any)
adds a "lastActions" function to the last sus being defined
Unit
eq final def eq(arg0 : Object) Boolean AnyRef
equals def equals(arg0 : Any) Boolean AnyRef
exampleContainer protected[this] def exampleContainer
utility method to track the last example list being currently defined [details]

It is either the list of examples associated with the current sus, or the list of subexamples of the current example being defined
Any SpecificationStructure
executeTest def executeTest(ex : Example, t : => Any) Any ExampleLifeCycle
finalize protected def finalize Unit AnyRef
forExample implicit def forExample(desc : String)
implicit definition allowing to declare a new example described by a string desc
Usage: "return 0 when asked for (0+0)" in { [details]
..}
Alternatively, it could be created with: forExample("return 0 when asked for (0+0)").in {...}
Example SpecificationStructure
forExample def forExample[S](function : (S) => Any)
Create an anonymous example with a function on a System, giving it a number depending on the existing created examples/
Example SpecificationStructure
getClass final def getClass Class[Object] AnyRef
globalContext def globalContext(b : => Any, a : => Any)
Factory method to create a context with before/after actions
Context
hashCode def hashCode Int AnyRef
include def include(specifications : Specification*) Unit SpecificationStructure
isExpectation def isExpectation[T](a : => T)
Declares a block of code to count as an expectation
T ExpectationsListener
isInstanceOf final def isInstanceOf[T0] Boolean Any
isSpecifiedBy def isSpecifiedBy(specifications : Specification*)
this declares that a specification is composed of other specifications
Unit SpecificationStructure
makeTagged def makeTagged(s : String*)
create another tagged with this new tags
Tagged Tagged
ne final def ne(arg0 : Object) Boolean AnyRef
notify final def notify Unit AnyRef
notifyAll final def notifyAll Unit AnyRef
reject def reject(t : Tag*)
Declare that this element should be rejected if it has one of the rejected tags [details]
This method declares the same thing for the components of this element.
Tagged Tagged
rejectTag def rejectTag(s : String*)
alias for the reject method with strings
Tagged Tagged
rejectTags def rejectTags(s : String*)
alias for the reject method with several strings
Tagged Tagged
setSequential def setSequential Unit ExampleLifeCycle
specify implicit def specify[S](context : SystemContext[S], desc : String)
implicit definition allowing to declare a new system under test described by a string desc
Usage: "my system under test" should {}
Alternatively, it could be created with: specify("my system under test") [details]
should {}
Sus SpecificationStructure
specify implicit def specify(desc : String) Sus SpecificationStructure
stringToTag implicit def stringToTag(s : String)
transforms a string to a Tag object
Tag Tagged
synchronized final def synchronized[T0](arg0 : T0) T0 AnyRef
tag def tag(t : String*)
Add one or several tags to this element
Tagged Tagged
tagWith def tagWith(other : Tagged)
add the tags specification from another tagged element [details]
This is used when propagating the tags from a specification to a sus for example
Tagged Tagged
toShortActions implicit def toShortActions(actions : => Unit)
Syntactic sugar for before/after actions [details]

Usage: "a system" should { createObjects.before ...

ShortActions
toString def toString String AnyRef
until def until(predicate : => Boolean)
repeats examples according to a predicate
Unit
usingAfter def usingAfter(actions : () => Any)
[details]
deprecated
- adds an "after" function to the last sus being defined
Unit
usingBefore def usingBefore(actions : () => Any)
[details]
deprecated
- adds a "before" function to the last sus being defined
Unit
wait final def wait(arg0 : Long) Unit AnyRef
wait final def wait Unit AnyRef
wait final def wait(arg0 : Long, arg1 : Int) Unit AnyRef
when implicit def when(s : String)
Syntactic sugar to create pass a new context before creating a sus [details]

Usage: "a system" ->(context) should { ... In that case before/after actions defined in the context will be set on the defined sus.

ToContext
Copyright (c) 2007-2009. All Rights Reserved.