package enablers
Classes, traits, and objects for typeclasses that enable ScalaTest's DSLs.
This package is released as part of the scalatest-core
module.
- Source
- package.scala
- Alphabetic
- By Inheritance
- enablers
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- trait Aggregating[-A] extends AnyRef
Typeclass that enables for aggregations certain
contain
syntax in the ScalaTest matchers DSL.Typeclass that enables for aggregations certain
contain
syntax in the ScalaTest matchers DSL.An
Aggregating[A]
provides access to the "aggregating nature" of typeA
in such a way that relevantcontain
matcher syntax can be used with typeA
. AnA
can be any type of aggregation—an object that in some way aggregates or brings together other objects. ScalaTest provides implicit implementations for several types out of the box in theAggregating
companion object:scala.collection.GenTraversable
String
Array
java.util.Collection
java.util.Map
The
contain
syntax enabled by this trait is:result
should
contain
atLeastOneOf
(1, 2, 3)
result
should
contain
atMostOneOf
(1, 2, 3)
result
should
contain
only
(1, 2, 3)
result
should
contain
allOf
(1, 2, 3)
result
should
contain
theSameElementsAs
(List(1, 2, 3))
You can enable the
contain
matcher syntax enabled byAggregating
on your own typeU
by defining anAggregating[U]
for the type and making it available implicitly.Note, for an explanation of the difference between
Containing
andAggregating
, both of which enablecontain
matcher syntax, see the Containing versus Aggregating section of the main documentation for traitContaining
. - trait AggregatingHighPriorityImplicits extends AggregatingStandardImplicits
- trait AggregatingImpls extends AnyRef
- trait AggregatingJavaImplicits extends AggregatingImpls
- trait AggregatingStandardImplicits extends AggregatingJavaImplicits
- trait Collecting[E, C] extends AnyRef
Supertrait for typeclasses that enable
loneElement
and inspectors syntax for collections.Supertrait for typeclasses that enable
loneElement
and inspectors syntax for collections.A
Collecting[E, C]
provides access to the "collecting nature" of typeC
in such a way thatloneElement
syntax can be used with typeC
. AC
can be any type of "collecting", a type that in some way collects or brings together elements of typeE
. ScalaTest provides implicit implementations for several types. You can enable thecontain
matcher syntax on your own typeU
by defining anCollecting[E, U]
for the type and making it available implicitly.ScalaTest provides implicit
Collecting
instances forscala.collection.GenTraversable
,Array
,java.util.Collection
andjava.util.Map
in theCollecting
companion object. - trait Containing[-C] extends AnyRef
Supertrait for typeclasses that enable certain
contain
matcher syntax for containers.Supertrait for typeclasses that enable certain
contain
matcher syntax for containers.A
Containing[C]
provides access to the "containing nature" of typeC
in such a way that relevantcontain
matcher syntax can be used with typeC
. AC
can be any type of "container," a type that in some way can contains one or more other objects. ScalaTest provides implicit implementations for several types. You can enable thecontain
matcher syntax on your own typeU
by defining anContaining[U]
for the type and making it available implicitly.ScalaTest provides implicit
Containing
instances forscala.collection.GenTraversable
,java.util.Collection
,java.util.Map
,String
,Array
, andscala.Option
in theContaining
companion object.Containing
versusAggregating
The difference between
Containing
andAggregating
is thatContaining
enablescontain
matcher syntax that makes sense for "box" types that can contain at most one value (for example,scala.Option
), whereasAggregating
enablescontain
matcher syntax for full-blown collections and other aggregations of potentially more than one object. For example, it makes sense to make assertions like these, which are enabled byContaining
, forscala.Option
:val option: Option[Int] = Some(7) option should contain (7) option should contain oneOf (6, 7, 8) option should contain noneOf (3, 4, 5)
However, given a
scala.Option
can only ever contain at most one object, it doesn't make sense to make assertions like the following, which are enabled viaAggregation
:// Could never succeed, so does not compile option should contain allOf (6, 7, 8)
The above assertion could never succceed, because an option cannot contain more than one value. By default the above statement does not compile, because
contain
allOf
is enabled byAggregating
, and ScalaTest provides no implicitAggregating
instance for typescala.Option
. - trait ContainingHighPriorityImplicits extends ContainingStandardImplicits
- trait ContainingImpls extends AnyRef
- trait ContainingStandardImplicits extends JavaContainingImplicits
- trait Definition[-T] extends AnyRef
Supertrait for typeclasses that enable the
be defined
matcher syntax.Supertrait for typeclasses that enable the
be defined
matcher syntax.A
Definition[T]
provides access to the "definition nature" of typeS
in such a way thatbe defined
matcher syntax can be used with typeT
. AT
can be any type for which the concept of being defined makes sense, such asscala.Option
. ScalaTest provides implicit implementation forscala.Option
. You can enable thebe defined
matcher syntax on your own typeU
by defining aDefinition[U]
for the type and making it available implicitly.ScalaTest provides an implicit
Definition
instance forscala.Option
, arbitary object withisDefined()
orisDefined
in theDefinition
companion object. - trait Emptiness[-T] extends AnyRef
Supertrait for typeclasses that enable
be empty
matcher syntax.Supertrait for typeclasses that enable
be empty
matcher syntax.An
Emptiness[T]
provides access to the "emptiness" of typeT
in such a way thatbe empty
matcher syntax can be used with typeT
. AT
can be any type that in some way can be empty. ScalaTest provides implicit implementations for several types. You can enable thebe empty
matcher syntax on your own typeU
by defining anEmptiness[U]
for the type and making it available implicitly.ScalaTest provides implicit
Emptiness
instances forscala.collection.GenTraversable
,java.util.Collection
,java.util.Map
,String
,Array
, andscala.Option
in theEmptiness
companion object. - trait Existence[-S] extends AnyRef
Supertrait for typeclasses that enable the
exist
matcher syntax.Supertrait for typeclasses that enable the
exist
matcher syntax.An
Existence[S]
provides access to the "existence nature" of typeS
in such a way thatexist
matcher syntax can be used with typeS
. AS
can be any type for which the concept of existence makes sense, such asjava.io.File
. ScalaTest provides implicit implementations forjava.io.File
. You can enable theexist
matcher syntax on your own typeU
by defining aExistence[U]
for the type and making it available implicitly.ScalaTest provides an implicit
Existence
instance forjava.io.File
in theExistence
companion object. - abstract class ExpectationWheneverAsserting extends UnitWheneverAsserting
Abstract class that in the future will hold an intermediate priority
WheneverAsserting
implicit, which will enable inspector expressions that have result typeExpectation
, a more composable form of assertion that returns a result instead of throwing an exception when it fails. - trait Futuristic[T] extends AnyRef
Supertrait for
Futureistic
typeclasses.Supertrait for
Futureistic
typeclasses.Trait
Futureistic
is a typeclass trait for objects that can be used with thecomplete
-lastly
syntax of traitCompleteLastly
. - trait InspectorAsserting[T] extends AnyRef
Supertrait for
InspectorAsserting
typeclasses, which are used to implement and determine the result type ofInspectors
methods such asforAll
,forBetween
, etc.Supertrait for
InspectorAsserting
typeclasses, which are used to implement and determine the result type ofInspectors
methods such asforAll
,forBetween
, etc.Currently, an inspector expression will have result type
Assertion
, if the function passed has result typeAssertion
, else it will have result typeUnit
. - trait JavaContainingImplicits extends ContainingImpls
- trait KeyMapping[-M] extends AnyRef
Supertrait for typeclasses that enable
contain key
matcher syntax.Supertrait for typeclasses that enable
contain key
matcher syntax.A
KeyMapping[M]
provides access to the "key mapping nature" of typeM
in such a way thatcontain key
matcher syntax can be used with typeM
. AM
can be any type for whichcontain key
syntax makes sense. ScalaTest provides implicit implementations forscala.collection.GenMap
andjava.util.Map
. You can enable thecontain key
matcher syntax on your own typeU
by defining aKeyMapping[U]
for the type and making it available implicitly.ScalaTest provides implicit
KeyMapping
instances forscala.collection.GenMap
, andjava.util.Map
in theKeyMapping
companion object. - trait Length[T] extends AnyRef
Supertrait for
Length
typeclasses.Supertrait for
Length
typeclasses.Trait
Length
is a typeclass trait for objects that can be queried for length. Objects of type T for which an implicitLength[T]
is available can be used with theshould have length
syntax. In other words, this trait enables you to use the length checking syntax with arbitrary objects. As an example, the followingBridge
class:scala> import org.scalatest._ import org.scalatest._ scala> import enablers.Length import enablers.Length scala> import Matchers._ import Matchers._ scala> case class Bridge(span: Int) defined class Bridge
Out of the box you can't use the
should have length
syntax withBridge
, because ScalaTest doesn't know that a bridge's span means its length:scala> val bridge = new Bridge(2000) bridge: Bridge = Bridge(2000) scala> bridge should have length 2000 <console>:34: error: could not find implicit value for parameter len: org.scalatest.enablers.Length[Bridge] bridge should have length 2000 ^
You can teach this to ScalaTest, however, by defining an implicit
Length[Bridge]
.scala> implicit val lengthOfBridge: Length[Bridge] = | new Length[Bridge] { | def lengthOf(b: Bridge): Long = b.span | } lengthOfBridge: org.scalatest.enablers.Length[Bridge] = $anon$1@3fa27a4a
With the implicit
Length[Bridge]
in scope, you can now use ScalaTest'sshould have length
syntax withBridge
instances:scala> bridge should have length 2000 res4: org.scalatest.Assertion = Succeeded scala> bridge should have length 2001 org.scalatest.exceptions.TestFailedException: Bridge(2000) had length 2000 instead of expected length 2001 at org.scalatest.MatchersHelper$.newTestFailedException(MatchersHelper.scala:148) at org.scalatest.MatchersHelper$.indicateFailure(MatchersHelper.scala:366) at org.scalatest.Matchers$ResultOfHaveWordForExtent.length(Matchers.scala:2720) ... 43 elided
- trait Messaging[T] extends AnyRef
Supertrait for
Messaging
typeclasses.Supertrait for
Messaging
typeclasses.Trait
Messaging
is a typeclass trait for objects that can be queried for message. Objects of type T for which an implicitMessaging[T]
is available can be used with theshould have message
syntax. You can enable thehave message
matcher syntax on your own typeU
by defining aMessaging[U]
for the type and making it available implicitly.ScalaTest provides an implicit
Messaging
instance forjava.lang.Throwable
and arbitary object withmessage()
,message
,getMessage()
orgetMessage
method in theMessaging
companion object. - trait Readability[-T] extends AnyRef
Supertrait for typeclasses that enable the
be readable
matcher syntax.Supertrait for typeclasses that enable the
be readable
matcher syntax.A
Readability[T]
provides access to the "readable nature" of typeT
in such a way thatbe readable
matcher syntax can be used with typeT
. AT
can be any type for which the concept of being readable makes sense, such asjava.io.File
. You can enable thebe readable
matcher syntax on your own typeU
by defining aReadability[U]
for the type and making it available implicitly.ScalaTest provides an implicit
Readability
instance forjava.io.File
and arbitary object withisReadable()
orisReadable
in theReadability
companion object. - trait Retrying[T] extends AnyRef
Supertrait for
Retrying
typeclasses, which are used to implement and determine the behavior ofEventually
methods.Supertrait for
Retrying
typeclasses, which are used to implement and determine the behavior ofEventually
methods.Currently, implementations for anything type
T
andFuture[T]
is provided. - trait Sequencing[-S] extends AnyRef
Typeclass that enables for sequencing certain
contain
syntax in the ScalaTest matchers DSL.Typeclass that enables for sequencing certain
contain
syntax in the ScalaTest matchers DSL.An
Sequencing[A]
provides access to the "sequenching nature" of typeA
in such a way that relevantcontain
matcher syntax can be used with typeA
. AnA
can be any type of sequencing—an object that in some way brings together other objects in order. ScalaTest provides implicit implementations for several types out of the box in theSequencing
companion object:scala.collection.GenSeq
scala.collection.SortedSet
scala.collection.SortedMap
Array
java.util.List
java.util.SortedSet
java.util.SortedMap
String
The
contain
syntax enabled by this trait is:result should contain inOrder (1, 2, 3)
result should contain inOrderOnly (1, 2, 3)
result should contain theSameElementsInOrderAs List(1, 2, 3)
You can enable the
contain
matcher syntax enabled bySequencing
on your own typeU
by defining anSequencing[U]
for the type and making it available implicitly. - trait Size[T] extends AnyRef
Supertrait for
Size
typeclasses.Supertrait for
Size
typeclasses.Trait
Size
is a typeclass trait for objects that can be queried for size. Objects of type T for which an implicitSize[T]
is available can be used with theshould have size
syntax. In other words, this trait enables you to use the size checking syntax with arbitrary objects. As an example, the followingBridge
class:scala> import org.scalatest._ import org.scalatest._ scala> import enablers.Size import enablers.Size scala> import Matchers._ import Matchers._ scala> case class Bridge(span: Int) defined class Bridge
Out of the box you can't use the
should have size
syntax withBridge
, because ScalaTest doesn't know that a bridge's span means its size:scala> val bridge = new Bridge(2000) bridge: Bridge = Bridge(2000) scala> bridge should have size 2000 <console>:34: error: could not find implicit value for parameter sz: org.scalatest.enablers.Size[Bridge] bridge should have size 2000 ^
You can teach this to ScalaTest, however, by defining an implicit
Size[Bridge]
.scala> implicit val sizeOfBridge: Size[Bridge] = | new Size[Bridge] { | def sizeOf(b: Bridge): Long = b.span | } sizeOfBridge: org.scalatest.enablers.Size[Bridge] = $anon$1@3fa27a4a
With the implicit
Size[Bridge]
in scope, you can now use ScalaTest'sshould have size
syntax withBridge
instances:scala> bridge should have size 2000 res4: org.scalatest.Assertion = Succeeded scala> bridge should have size 2001 org.scalatest.exceptions.TestFailedException: Bridge(2000) had size 2000 instead of expected size 2001 at org.scalatest.MatchersHelper$.newTestFailedException(MatchersHelper.scala:148) at org.scalatest.MatchersHelper$.indicateFailure(MatchersHelper.scala:366) at org.scalatest.Matchers$ResultOfHaveWordForExtent.size(Matchers.scala:2720) ... 43 elided
- trait Sortable[-S] extends AnyRef
Supertrait for typeclasses that enable the
be
sorted
matcher syntax.Supertrait for typeclasses that enable the
be
sorted
matcher syntax.A
Sortable[S]
provides access to the "sortable nature" of typeS
in such a way thatbe
sorted
matcher syntax can be used with typeS
. AnS
can be any type for which the concept of being sorted makes sense, such as sequences. ScalaTest provides implicit implementations for several types. You can enable thebe
sorted
matcher syntax on your own typeU
by defining aSortable[U]
for the type and making it available implicitly.ScalaTest provides an implicit
Sortable
instance for types out of the box in theSortable
companion object:scala.collection.GenSeq
Array
java.util.List
- trait TableAsserting[ASSERTION] extends AnyRef
Supertrait for
TableAsserting
typeclasses, which are used to implement and determine the result type of TableDrivenPropertyChecks'sforAll
,forEvery
andexists
method.Supertrait for
TableAsserting
typeclasses, which are used to implement and determine the result type of TableDrivenPropertyChecks'sforAll
,forEvery
andexists
method.Currently, an TableDrivenPropertyChecks expression will have result type
Assertion
, if the function passed has result typeAssertion
, else it will have result typeUnit
. - trait Timed[T] extends AnyRef
Trait that provides a
timeoutAfter
construct, which allows you to specify a timeout for an operation passed as a by-name parameter, as well as a way to signal/interrupt it if the operation exceeds its time limit. - abstract class UnitInspectorAsserting extends AnyRef
Class holding lowest priority
InspectorAsserting
implicit, which enables inspector expressions that have result typeUnit
. - abstract class UnitTableAsserting extends AnyRef
Class holding lowest priority
TableAsserting
implicit, which enables TableDrivenPropertyChecks expressions that have result typeUnit
. - abstract class UnitWheneverAsserting extends AnyRef
Class holding lowest priority
WheneverAsserting
implicit, which enables Whenever expressions that have result typeUnit
. - trait ValueMapping[-M] extends AnyRef
Supertrait for typeclasses that enable
contain value
matcher syntax.Supertrait for typeclasses that enable
contain value
matcher syntax.A
ValueMapping[M]
provides access to the "value mapping nature" of typeM
in such a way thatcontain
value
matcher syntax can be used with typeM
. AnM
can be any type for whichcontain
value
syntax makes sense. ScalaTest provides implicit implementations forscala.collection.GenMap
andjava.util.Map
. You can enable thecontain
value
matcher syntax on your own typeU
by defining aValueMapping[U]
for the type and making it available implicitly.ScalaTest provides implicit
ValueMapping
instances forscala.collection.GenMap
, andjava.util.Map
in theValueMapping
companion object. - trait WheneverAsserting[T] extends AnyRef
Supertrait for
WheneverAsserting
typeclasses, which are used to implement and determine the result type of Whenever'swhenever
method. - trait Writability[-T] extends AnyRef
Supertrait for typeclasses that enable the
be
writable
matcher syntax.Supertrait for typeclasses that enable the
be
writable
matcher syntax.A
Writability[T]
provides access to the "writable nature" of typeT
in such a way thatbe
writable
matcher syntax can be used with typeT
. AT
can be any type for which the concept of being writable makes sense, such asjava.io.File
. ScalaTest provides implicit implementation forjava.io.File
. You can enable thebe
writable
matcher syntax on your own typeU
by defining aWritability[U]
for the type and making it available implicitly.ScalaTest provides an implicit
Writability
instance forjava.io.File
and arbitary object withisWritable()
orisWritable
in theWritability
companion object.
Value Members
- object Aggregating extends AggregatingHighPriorityImplicits
Companion object for
Aggregating
that provides implicit implementations for the following types:Companion object for
Aggregating
that provides implicit implementations for the following types:scala.collection.GenTraversable
String
Array
java.util.Collection
java.util.Map
- object Collecting
Companion object for
Collecting
that provides implicit implementations for the following types:Companion object for
Collecting
that provides implicit implementations for the following types:scala.collection.GenTraversable
Array
java.util.Collection
java.util.Map
- object Containing extends ContainingHighPriorityImplicits
Companion object for
Containing
that provides implicit implementations for the following types:Companion object for
Containing
that provides implicit implementations for the following types:scala.collection.GenTraversable
String
Array
scala.Option
java.util.Collection
java.util.Map
- object Definition
Companion object for
Definition
that provides implicit implementations for the following types:Companion object for
Definition
that provides implicit implementations for the following types:scala.Option
- arbitary object with a
isDefined()
method that returnsBoolean
- arbitary object with a parameterless
isDefined
method that returnsBoolean
- object Emptiness
Companion object for
Emptiness
that provides implicit implementations for the following types:Companion object for
Emptiness
that provides implicit implementations for the following types:scala.collection.GenTraversable
String
Array
scala.Option
java.util.Collection
java.util.Map
- arbitary object with a
isEmpty()
method that returnsBoolean
- arbitary object with a parameterless
isEmpty
method that returnsBoolean
- object Existence
Companion object for
Existence
that provides implicit implementations forjava.io.File
. - object Futuristic
Companion object for trait
Futuristic
that contains implicitFuturistic
providers forFutureOutcome
andFuture[T]
for any typeT
. - object InspectorAsserting extends UnitInspectorAsserting
Companion object to
InspectorAsserting
that provides two implicit providers, a higher priority one for passed functions that have result typeAssertion
, which also yields result typeAssertion
, and one for any other type, which yields result typeUnit
. - object KeyMapping
Companion object for
KeyMapping
that provides implicit implementations forscala.collection.GenMap
andjava.util.Map
. - object Length
Companion object for
Length
that provides implicit implementations for the following types:Companion object for
Length
that provides implicit implementations for the following types:scala.collection.GenSeq
String
Array
java.util.Collection
- arbitary object with a
length()
method that returnsInt
- arbitary object with a parameterless
length
method that returnsInt
- arbitary object with a
getLength()
method that returnsInt
- arbitary object with a parameterless
getLength
method that returnsInt
- arbitary object with a
length()
method that returnsLong
- arbitary object with a parameterless
length
method that returnsLong
- arbitary object with a
getLength()
method that returnsLong
- arbitary object with a parameterless
getLength
method that returnsLong
- object Messaging
Companion object for
Messaging
that provides implicit implementations for the following types:Companion object for
Messaging
that provides implicit implementations for the following types:java.lang.Throwable
- arbitary object with a
message()
method that returnsString
- arbitary object with a parameterless
message
method that returnsString
- arbitary object with a
getMessage()
method that returnsString
- arbitary object with a parameterless
getMessage
method that returnsString
- object Readability
Companion object for
Readability
that provides implicit implementations for the following types:Companion object for
Readability
that provides implicit implementations for the following types:java.io.File
- arbitary object with a
isReadable()
method that returnsBoolean
- arbitary object with a parameterless
isReadable
method that returnsBoolean
- object Retrying
Companion object that provides
Retrying
implementations forT
andFuture[T]
. - object Sequencing
Companion object for
Sequencing
that provides implicit implementations for the following types:Companion object for
Sequencing
that provides implicit implementations for the following types:scala.collection.GenSeq
scala.collection.SortedSet
scala.collection.SortedMap
Array
java.util.List
java.util.SortedSet
java.util.SortedMap
String
- object Size
Companion object for
Size
that provides implicit implementations for the following types:Companion object for
Size
that provides implicit implementations for the following types:scala.collection.GenTraversable
String
Array
java.util.Collection
java.util.Map
- arbitary object with a
size()
method that returnsInt
- arbitary object with a parameterless
size
method that returnsInt
- arbitary object with a
getSize()
method that returnsInt
- arbitary object with a parameterless
getSize
method that returnsInt
- arbitary object with a
size()
method that returnsLong
- arbitary object with a parameterless
size
method that returnsLong
- arbitary object with a
getSize()
method that returnsLong
- arbitary object with a parameterless
getSize
method that returnsLong
- object Sortable
Companion object for
Sortable
that provides implicit implementations for the following types:Companion object for
Sortable
that provides implicit implementations for the following types:scala.collection.GenSeq
Array
java.util.List
- object TableAsserting extends UnitTableAsserting
Companion object to
TableAsserting
that provides two implicit providers, a higher priority one for passed functions that have result typeAssertion
, which also yields result typeAssertion
, and one for any other type, which yields result typeUnit
. - object Timed
Companion object for
Timed
typeclass that offers three implicit providers: one forFutureOutcome
, one forFuture
of any type, and one for any other type.Companion object for
Timed
typeclass that offers three implicit providers: one forFutureOutcome
, one forFuture
of any type, and one for any other type.The details are in the documentation for the implicit providers themselves (methods
timed
,timedFutureOf
, andtimedFutureOutcome
), but in short if a time limit is exceeded:- if the type
T
inTimed[T]
isFutureOutcome
theFutureOutcome
returned bytimeoutAfter
will result in eitherFailed
orCanceled
- if the type is
Future[U]
, theFuture[U]
returned bytimeoutAfter
will fail with either aTestFailedDueToTimeoutException
or aTestCanceledException
. - otherwise, the
timeoutAfter
method will itself complete abruptly with eitherTestFailedDueToTimeoutException
orTestCanceledException.
- if the type
- object ValueMapping
Companion object for
ValueMapping
that provides implicit implementations forscala.collection.GenMap
andjava.util.Map
. - object WheneverAsserting extends ExpectationWheneverAsserting
Companion object to
WheneverAsserting
that provides two implicit providers, a higher priority one for passed functions that have result typeAssertion
, which also yields result typeAssertion
, and one for any other type, which yields result typeUnit
. - object Writability
Companion object for
Writability
that provides implicit implementations for the following types:Companion object for
Writability
that provides implicit implementations for the following types:java.io.File
- arbitary object with a
isWritable()
method that returnsBoolean
- arbitary object with a parameterless
isWritable
method that returnsBoolean