Package

org.scalatest

enablers

Permalink

package enablers

Visibility
  1. Public
  2. All

Type Members

  1. trait Aggregating[-A] extends AnyRef

    Permalink

    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 type A in such a way that relevant contain matcher syntax can be used with type A. An A 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 the Aggregating 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 by Aggregating on your own type U by defining an Aggregating[U] for the type and making it available implicitly.

    Note, for an explanation of the difference between Containing and Aggregating, both of which enable contain matcher syntax, see the Containing versus Aggregating section of the main documentation for trait Containing.

  2. trait Collecting[E, C] extends AnyRef

    Permalink

    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 type C in such a way that loneElement syntax can be used with type C. A C can be any type of "collecting", a type that in some way collects or brings together elements of type E. ScalaTest provides implicit implementations for several types. You can enable the contain matcher syntax on your own type U by defining an Collecting[E, U] for the type and making it available implicitly.

    ScalaTest provides implicit Collecting instances for scala.collection.GenTraversable, Array, java.util.Collection and java.util.Map in the Collecting companion object.

  3. trait Containing[-C] extends AnyRef

    Permalink

    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 type C in such a way that relevant contain matcher syntax can be used with type C. A C 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 the contain matcher syntax on your own type U by defining an Containing[U] for the type and making it available implicitly.

    ScalaTest provides implicit Containing instances for scala.collection.GenTraversable, java.util.Collection, java.util.Map, String, Array, and scala.Option in the Containing companion object.

    Containing versus Aggregating

    The difference between Containing and Aggregating is that Containing enables contain matcher syntax that makes sense for "box" types that can contain at most one value (for example, scala.Option), whereas Aggregating enables contain 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 by Containing, for scala.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 via Aggregation:

    // 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 by Aggregating, and ScalaTest provides no implicit Aggregating instance for type scala.Option.

  4. trait Definition[-T] extends AnyRef

    Permalink

    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 type S in such a way that be defined matcher syntax can be used with type T. A T can be any type for which the concept of being defined makes sense, such as scala.Option. ScalaTest provides implicit implementation for scala.Option. You can enable the be defined matcher syntax on your own type U by defining a Definition[U] for the type and making it available implicitly.

    ScalaTest provides an implicit Definition instance for scala.Option, arbitary object with isDefined() or isDefined in the Definition companion object.

  5. trait Emptiness[-T] extends AnyRef

    Permalink

    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 type T in such a way that be empty matcher syntax can be used with type T. A T can be any type that in some way can be empty. ScalaTest provides implicit implementations for several types. You can enable the be empty matcher syntax on your own type U by defining an Emptiness[U] for the type and making it available implicitly.

    ScalaTest provides implicit Emptiness instances for scala.collection.GenTraversable, java.util.Collection, java.util.Map, String, Array, and scala.Option in the Emptiness companion object.

  6. trait Existence[-S] extends AnyRef

    Permalink

    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 type S in such a way that exist matcher syntax can be used with type S. A S can be any type for which the concept of existence makes sense, such as java.io.File. ScalaTest provides implicit implementations for java.io.File. You can enable the exist matcher syntax on your own type U by defining a Existence[U] for the type and making it available implicitly.

    ScalaTest provides an implicit Existence instance for java.io.File in the Existence companion object.

  7. trait KeyMapping[-M] extends AnyRef

    Permalink

    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 type M in such a way that contain key matcher syntax can be used with type M. A M can be any type for which contain key syntax makes sense. ScalaTest provides implicit implementations for scala.collection.GenMap and java.util.Map. You can enable the contain key matcher syntax on your own type U by defining a KeyMapping[U] for the type and making it available implicitly.

    ScalaTest provides implicit KeyMapping instances for scala.collection.GenMap, and java.util.Map in the KeyMapping companion object.

  8. trait Length[T] extends AnyRef

    Permalink

    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 implicit Length[T] is available can be used with the should have length syntax. In other words, this trait enables you to use the length checking syntax with arbitrary objects. As an example, consider java.net.DatagramPacket, which has a getLength method. By default, this can't be used with ScalaTest's have length syntax.

    scala> import java.net.DatagramPacket
    import java.net.DatagramPacket
    
    scala> import org.scalatest.Matchers._
    import org.scalatest.Matchers._
    
    scala> val dp = new DatagramPacket(Array(0x0, 0x1, 0x2, 0x3), 4)
    dp: java.net.DatagramPacket = java.net.DatagramPacket@54906181
    
    scala> dp.getLength
    res0: Int = 4
    
    scala> dp should have length 4
    :13: error: could not find implicit value for parameter ev: org.scalatest.matchers.ShouldMatchers.Extent[java.net.DatagramPacket]
             dp should have length 4
                ^
    
    scala> implicit val lengthOfDatagramPacket =
        |   new Length[DatagramPacket] {
        |     def lengthOf(dp: DatagramPacket): Long = dp.getLength
        |   }
    lengthOfDatagramPacket: java.lang.Object with org.scalatest.matchers.ShouldMatchers.Length[java.net.DatagramPacket] = $anon$1@550c6b37
    
    scala> dp should have length 4
    
    scala> dp should have length 3
    org.scalatest.exceptions.TestFailedException:  java.net.DatagramPacket@54906181 had length 4, not length 3
    

  9. trait Messaging[T] extends AnyRef

    Permalink

    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 implicit Messaging[T] is available can be used with the should have message syntax. You can enable the have message matcher syntax on your own type U by defining a Messaging[U] for the type and making it available implicitly.

    ScalaTest provides an implicit Messaging instance for java.lang.Throwable and arbitary object with message(), message, getMessage() or getMessage method in the Messaging companion object.

  10. trait Readability[-T] extends AnyRef

    Permalink

    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 type T in such a way that be readable matcher syntax can be used with type T. A T can be any type for which the concept of being readable makes sense, such as java.io.File. You can enable the be readable matcher syntax on your own type U by defining a Readability[U] for the type and making it available implicitly.

    ScalaTest provides an implicit Readability instance for java.io.File and arbitary object with isReadable() or isReadable in the Readability companion object.

  11. trait Sequencing[-S] extends AnyRef

    Permalink

    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 type A in such a way that relevant contain matcher syntax can be used with type A. An A 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 the Sequencing 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 by Sequencing on your own type U by defining an Sequencing[U] for the type and making it available implicitly.

  12. trait Size[T] extends AnyRef

    Permalink

    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 implicit Size[T] is available can be used with the should have size syntax. In other words, this trait enables you to use the size checking syntax with arbitrary objects. As an example, consider java.net.DatagramPacket, which has a getSize method. By default, this can't be used with ScalaTest's have size syntax.

    scala> import java.awt.image.DataBufferByte
    import java.awt.image.DataBufferByte
    
    scala> import org.scalatest.matchers.ShouldMatchers._
    import org.scalatest.matchers.ShouldMatchers._
    
    scala> val db = new DataBufferByte(4)
    db: java.awt.image.DataBufferByte = java.awt.image.DataBufferByte@33d5e94f
    
    scala> db.getSize
    res0: Int = 4
    
    scala> db should have size 4
    :17: error: could not find implicit value for parameter ev: org.scalatest.matchers.ShouldMatchers.Extent[java.awt.image.DataBufferByte]
                  db should have size 4
                     ^
    scala> implicit val sizeOfDataBufferByte =
         |   new Size[DataBufferByte] {
         |     def sizeOf(db: DataBufferByte): Long = db.getSize
         |   }
    sizeOfDataBufferByte: java.lang.Object with org.scalatest.matchers.ShouldMatchers.Size[java.awt.image.DataBufferByte] = $anon$1@4c69bdf8
    
    scala> db should have size 4
    
    scala> db should have size 3
    org.scalatest.exceptions.TestFailedException:  java.awt.image.DataBufferByte@33d5e94f had size 4, not size 3
    

  13. trait Sortable[-S] extends AnyRef

    Permalink

    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 type S in such a way that be sorted matcher syntax can be used with type S. An S 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 the be sorted matcher syntax on your own type U by defining a Sortable[U] for the type and making it available implicitly.

    ScalaTest provides an implicit Sortable instance for types out of the box in the Sortable companion object:

    • scala.collection.GenSeq
    • Array
    • java.util.List
  14. trait ValueMapping[-M] extends AnyRef

    Permalink

    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 type M in such a way that contain value matcher syntax can be used with type M. An M can be any type for which contain value syntax makes sense. ScalaTest provides implicit implementations for scala.collection.GenMap and java.util.Map. You can enable the contain value matcher syntax on your own type U by defining a ValueMapping[U] for the type and making it available implicitly.

    ScalaTest provides implicit ValueMapping instances for scala.collection.GenMap, and java.util.Map in the ValueMapping companion object.

  15. trait Writability[-T] extends AnyRef

    Permalink

    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 type T in such a way that be writable matcher syntax can be used with type T. A T can be any type for which the concept of being writable makes sense, such as java.io.File. ScalaTest provides implicit implementation for java.io.File. You can enable the be writable matcher syntax on your own type U by defining a Writability[U] for the type and making it available implicitly.

    ScalaTest provides an implicit Writability instance for java.io.File and arbitary object with isWritable() or isWritable in the Writability companion object.

Value Members

  1. object Aggregating

    Permalink

    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
  2. object Collecting

    Permalink

    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
  3. object Containing

    Permalink

    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
  4. object Definition

    Permalink

    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 returns Boolean
    • arbitary object with a parameterless isDefined method that returns Boolean
  5. object Emptiness

    Permalink

    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 returns Boolean
    • arbitary object with a parameterless isEmpty method that returns Boolean
  6. object Existence

    Permalink

    Companion object for Existence that provides implicit implementations for java.io.File.

    Companion object for Existence that provides implicit implementations for java.io.File.

  7. object KeyMapping

    Permalink

    Companion object for KeyMapping that provides implicit implementations for scala.collection.GenMap and java.util.Map.

    Companion object for KeyMapping that provides implicit implementations for scala.collection.GenMap and java.util.Map.

  8. object Length

    Permalink

    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 returns Int
    • arbitary object with a parameterless length method that returns Int
    • arbitary object with a getLength() method that returns Int
    • arbitary object with a parameterless getLength method that returns Int
    • arbitary object with a length() method that returns Long
    • arbitary object with a parameterless length method that returns Long
    • arbitary object with a getLength() method that returns Long
    • arbitary object with a parameterless getLength method that returns Long
  9. object Messaging

    Permalink

    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 returns String
    • arbitary object with a parameterless message method that returns String
    • arbitary object with a getMessage() method that returns String
    • arbitary object with a parameterless getMessage method that returns String
  10. object Readability

    Permalink

    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 returns Boolean
    • arbitary object with a parameterless isReadable method that returns Boolean
  11. object Sequencing

    Permalink

    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
  12. object Size

    Permalink

    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.GenTraversable
    • String
    • Array
    • java.util.Collection
    • java.util.Map
    • arbitary object with a size() method that returns Int
    • arbitary object with a parameterless size method that returns Int
    • arbitary object with a getSize() method that returns Int
    • arbitary object with a parameterless getSize method that returns Int
    • arbitary object with a size() method that returns Long
    • arbitary object with a parameterless size method that returns Long
    • arbitary object with a getSize() method that returns Long
    • arbitary object with a parameterless getSize method that returns Long
  13. object Sortable

    Permalink

    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
  14. object ValueMapping

    Permalink

    Companion object for ValueMapping that provides implicit implementations for scala.collection.GenMap and java.util.Map.

    Companion object for ValueMapping that provides implicit implementations for scala.collection.GenMap and java.util.Map.

  15. object Writability

    Permalink

    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 returns Boolean
    • arbitary object with a parameterless isWritable method that returns Boolean

Ungrouped