Packages

class Expect[R] extends Expectable[R]

Source
Expect.scala
Linear Supertypes
Expectable[R], AnyRef, Any
Type Hierarchy
Ordering
  1. Grouped
  2. Alphabetic
  3. By Inheritance
Inherited
  1. Expect
  2. Expectable
  3. AnyRef
  4. Any
Implicitly
  1. by fluentToCoreExpect
  2. by any2stringadd
  3. by StringFormat
  4. by Ensuring
  5. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Expect(command: String, defaultValue: R)
  2. new Expect(command: String, defaultValue: R, config: Config)
  3. new Expect(command: String, defaultValue: R, settings: Settings)
  4. new Expect(command: Seq[String], defaultValue: R, config: Config)
  5. new Expect(command: Seq[String], defaultValue: R, settings: Settings = new Settings())

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. def +(other: String): String
    Implicit
    This member is added by an implicit conversion from Expect[R] to any2stringadd[Expect[R]] performed by method any2stringadd in scala.Predef.
    Definition Classes
    any2stringadd
  4. def ->[B](y: B): (Expect[R], B)
    Implicit
    This member is added by an implicit conversion from Expect[R] to ArrowAssoc[Expect[R]] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  5. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  6. def addExpectBlock(f: (Expect[R]) ⇒ Unit): Expect[R]

    Add arbitrary ExpectBlocks to this Expect.

    Add arbitrary ExpectBlocks to this Expect.

    This is helpful to refactor code. For example: imagine you have an error case you want to add to multiple expects. You could leverage this method to do so in the following way:

    def errorCaseExpectBlock(expect: Expect[String]): Unit {
      expect.expect
        .when("Some error")
          .returning("Got some error")
    }
    
    //Then in your expects
    def parseOutputA: Expect[String] = {
      val e = new Expect("some command", "")
      e.expect(...)
      e.expect
        .when(...)
          .action1
        .when(...)
          .action2
      e.addExpectBlock(errorCaseExpectBlock)
    }
    
    def parseOutputB: Expect[String] = {
      val e = new Expect("some command", "")
      e.expect
        .when(...)
          .action1
          .action2
        .when(...)
          .action1
      e.expect(...)
        .action2
      e.addExpectBlock(errorCaseExpectBlock)
    }
    f

    function that adds ExpectBlocks.

    returns

    this Expect.

    Definition Classes
    ExpectExpectable
  7. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  8. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  9. def collect[T](pf: PartialFunction[R, T]): core.Expect[T]

    Creates a new Expect by mapping the result of the current Expect, if the given partial function is defined at that value.

    Creates a new Expect by mapping the result of the current Expect, if the given partial function is defined at that value.

    If the current Expect contains a value for which the partial function is defined, the new Expect will also hold that value. Otherwise, the resulting Expect will fail with a NoSuchElementException.

    T

    the type of the returned Expect

    pf

    the PartialFunction to apply to the result of this Expect

    returns

    an Expect holding the result of application of the PartialFunction or a NoSuchElementException

    Implicit
    This member is added by an implicit conversion from Expect[R] to core.Expect[R] performed by method fluentToCoreExpect in work.martins.simon.expect.fluent.
    Definition Classes
    Expect
  10. val command: Seq[String]
  11. val defaultValue: R
  12. def ensuring(cond: (Expect[R]) ⇒ Boolean, msg: ⇒ Any): Expect[R]
    Implicit
    This member is added by an implicit conversion from Expect[R] to Ensuring[Expect[R]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  13. def ensuring(cond: (Expect[R]) ⇒ Boolean): Expect[R]
    Implicit
    This member is added by an implicit conversion from Expect[R] to Ensuring[Expect[R]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  14. def ensuring(cond: Boolean, msg: ⇒ Any): Expect[R]
    Implicit
    This member is added by an implicit conversion from Expect[R] to Ensuring[Expect[R]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  15. def ensuring(cond: Boolean): Expect[R]
    Implicit
    This member is added by an implicit conversion from Expect[R] to Ensuring[Expect[R]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  16. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  17. def equals(other: Any): Boolean
    Definition Classes
    Expect → AnyRef → Any
  18. def expect(from: FromInputStream): ExpectBlock[R]

    Adds an empty new ExpectBlock reading from the specified FromInputStream.

    Adds an empty new ExpectBlock reading from the specified FromInputStream.

    returns

    the new ExpectBlock.

    Definition Classes
    ExpectExpectable
  19. def expect: ExpectBlock[R]

    Adds an empty new ExpectBlock.

    Adds an empty new ExpectBlock.

    returns

    the new ExpectBlock.

    Definition Classes
    ExpectExpectable
  20. def expect(pattern: Timeout.type): TimeoutWhen[R]

    Adds, in a new ExpectBlock, a TimeoutWhen that matches whenever the read from any of the FromStreamInputs times out.

    Adds, in a new ExpectBlock, a TimeoutWhen that matches whenever the read from any of the FromStreamInputs times out. This is a shortcut to expect.when(pattern).

    pattern

    the pattern to be used in the TimeoutWhen.

    returns

    the new RegexWhen.

    Definition Classes
    Expectable
  21. def expect(pattern: EndOfFile.type, readFrom: FromInputStream): EndOfFileWhen[R]

    Adds, in a new ExpectBlock, a EndOfFileWhen that matches whenever the end of file is reached while trying to read from the specified FromInputStream.

    Adds, in a new ExpectBlock, a EndOfFileWhen that matches whenever the end of file is reached while trying to read from the specified FromInputStream. This is a shortcut to expect.when(pattern, readFrom).

    pattern

    the pattern to be used in the EndOfFileWhen.

    readFrom

    from which FromInputStream to read the output.

    returns

    the new RegexWhen.

    Definition Classes
    Expectable
  22. def expect(pattern: EndOfFile.type): EndOfFileWhen[R]

    Adds, in a new ExpectBlock, a EndOfFileWhen that matches whenever the end of file is reached while trying to read from the StdOut output.

    Adds, in a new ExpectBlock, a EndOfFileWhen that matches whenever the end of file is reached while trying to read from the StdOut output. This is a shortcut to expect.when(pattern).

    pattern

    the pattern to be used in the EndOfFileWhen.

    returns

    the new RegexWhen.

    Definition Classes
    Expectable
  23. def expect(pattern: Regex, readFrom: FromInputStream): RegexWhen[R]

    Adds, in a new ExpectBlock, a RegexWhen that matches whenever the regex pattern successfully matches against the text read from the specified FromInputStream.

    Adds, in a new ExpectBlock, a RegexWhen that matches whenever the regex pattern successfully matches against the text read from the specified FromInputStream. This is a shortcut to expect.when(pattern, readFrom).

    pattern

    the pattern to be used in the RegexWhen.

    readFrom

    from which FromInputStream to read the output.

    returns

    the new RegexWhen.

    Definition Classes
    Expectable
  24. def expect(pattern: Regex): RegexWhen[R]

    Adds, in a new ExpectBlock, a RegexWhen that matches whenever the regex pattern successfully matches against the text read from the StdOut output.

    Adds, in a new ExpectBlock, a RegexWhen that matches whenever the regex pattern successfully matches against the text read from the StdOut output. This is a shortcut to expect.when(pattern).

    pattern

    the pattern to be used in the RegexWhen.

    returns

    the new RegexWhen.

    Definition Classes
    Expectable
  25. def expect(pattern: String, readFrom: FromInputStream): StringWhen[R]

    Adds, in a new ExpectBlock, a StringWhen that matches whenever pattern is contained in the text read from the specified FromInputStream.

    Adds, in a new ExpectBlock, a StringWhen that matches whenever pattern is contained in the text read from the specified FromInputStream. This is a shortcut to expect.when(pattern, readFrom).

    pattern

    the pattern to be used in the StringWhen.

    readFrom

    from which FromInputStream to read the output.

    returns

    the new StringWhen.

    Definition Classes
    Expectable
  26. def expect(pattern: String): StringWhen[R]

    Adds, in a new ExpectBlock, a StringWhen that matches whenever pattern is contained in the text read from the StdOut output.

    Adds, in a new ExpectBlock, a StringWhen that matches whenever pattern is contained in the text read from the StdOut output. This is a shortcut to expect.when(pattern).

    pattern

    the pattern to be used in the StringWhen.

    returns

    the new StringWhen.

    Definition Classes
    Expectable
  27. var expectBlocks: Seq[ExpectBlock[R]]
    Attributes
    protected
  28. val expectableParent: Expect[R]
    Attributes
    protected
    Definition Classes
    ExpectExpectable
  29. def filter(p: (R) ⇒ Boolean): core.Expect[R]

    Creates a new Expect by filtering its result with a predicate.

    Creates a new Expect by filtering its result with a predicate.

    If the current Expect result satisfies the predicate, the new Expect will also hold that result. Otherwise, the resulting Expect will fail with a NoSuchElementException.

    p

    the predicate to apply to the result of this Expect

    Implicit
    This member is added by an implicit conversion from Expect[R] to core.Expect[R] performed by method fluentToCoreExpect in work.martins.simon.expect.fluent.
    Definition Classes
    Expect
  30. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  31. def flatMap[T](f: (R) ⇒ core.Expect[T]): core.Expect[T]

    Creates a new Expect by applying a function to the returned result of this Expect, and returns the result of the function as the new Expect.

    Creates a new Expect by applying a function to the returned result of this Expect, and returns the result of the function as the new Expect.

    T

    the type of the returned Expect

    f

    the function which will be applied to the returned result of this Expect

    returns

    the Expect returned as the result of the application of the function f

    Implicit
    This member is added by an implicit conversion from Expect[R] to core.Expect[R] performed by method fluentToCoreExpect in work.martins.simon.expect.fluent.
    Definition Classes
    Expect
  32. def flatten[T](implicit ev: <:<[R, core.Expect[T]]): core.Expect[T]

    Creates a new Expect with one level of nesting flattened, this method is equivalent to flatMap(identity).

    Creates a new Expect with one level of nesting flattened, this method is equivalent to flatMap(identity).

    T

    the type of the returned Expect

    returns

    an Expect with one level of nesting flattened

    Implicit
    This member is added by an implicit conversion from Expect[R] to core.Expect[R] performed by method fluentToCoreExpect in work.martins.simon.expect.fluent.
    Definition Classes
    Expect
  33. def formatted(fmtstr: String): String
    Implicit
    This member is added by an implicit conversion from Expect[R] to StringFormat[Expect[R]] performed by method StringFormat in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  34. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
  35. def hashCode(): Int
    Definition Classes
    Expect → AnyRef → Any
  36. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  37. def map[T](f: (R) ⇒ T): core.Expect[T]

    Creates a new Expect by applying a function to the returned result of this Expect.

    Creates a new Expect by applying a function to the returned result of this Expect.

    T

    the type of the returned Expect

    f

    the function which will be applied to the returned result of this Expect

    returns

    an Expect which will return the result of the application of the function f

    Implicit
    This member is added by an implicit conversion from Expect[R] to core.Expect[R] performed by method fluentToCoreExpect in work.martins.simon.expect.fluent.
    Definition Classes
    Expect
  38. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  39. def newExpectBlock(block: ExpectBlock[R]): ExpectBlock[R]
    Attributes
    protected
  40. final def notify(): Unit
    Definition Classes
    AnyRef
  41. final def notifyAll(): Unit
    Definition Classes
    AnyRef
  42. def run(process: RichProcess)(implicit ex: ExecutionContext): Future[R]
    Implicit
    This member is added by an implicit conversion from Expect[R] to core.Expect[R] performed by method fluentToCoreExpect in work.martins.simon.expect.fluent.
    Definition Classes
    Expect
  43. def run(settings: Settings)(implicit ex: ExecutionContext): Future[R]
    Implicit
    This member is added by an implicit conversion from Expect[R] to core.Expect[R] performed by method fluentToCoreExpect in work.martins.simon.expect.fluent.
    Definition Classes
    Expect
  44. def run(timeout: FiniteDuration = settings.timeout, charset: Charset = settings.charset)(implicit ex: ExecutionContext): Future[R]
    Implicit
    This member is added by an implicit conversion from Expect[R] to core.Expect[R] performed by method fluentToCoreExpect in work.martins.simon.expect.fluent.
    Definition Classes
    Expect
  45. val settings: Settings
  46. def structurallyEquals[RR >: R](other: core.Expect[RR]): Boolean

    Implicit
    This member is added by an implicit conversion from Expect[R] to core.Expect[R] performed by method fluentToCoreExpect in work.martins.simon.expect.fluent.
    Definition Classes
    Expect
  47. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  48. def toCore: core.Expect[R]

    returns

    the core.Expect equivalent of this fluent.Expect.

  49. def toString(): String
    Definition Classes
    Expect → AnyRef → Any
  50. def transform[T](flatMapPF: PartialFunction[R, core.Expect[T]], mapPF: PartialFunction[R, T]): core.Expect[T]

    Transform this Expect result using the following strategy:

    Transform this Expect result using the following strategy:

    • if flatMapPF isDefinedAt for this expect result then the result is flatMapped using flatMapPF.
    • otherwise, if mapPF isDefinedAt for this expect result then the result is mapped using mapPF.
    • otherwise a NoSuchElementException is thrown where the result would be expected.

    This function is very useful when we need to flatMap this Expect for some values of its result type and map this Expect for some other values of its result type.

    To ensure you don't get NoSuchElementException you should take special care in ensuring:

    domain(flatMapPF) ∪ domain(mapPF) == domain(R)

    Remember that in the domain of R the defaultValue is also included.

    T

    the type of the returned Expect

    flatMapPF

    the function that will be applied when a flatMap is needed

    mapPF

    the function that will be applied when a map is needed

    returns

    a new Expect whose result is either flatMapped or mapped according to whether flatMapPF or mapPF is defined for the given result

    Implicit
    This member is added by an implicit conversion from Expect[R] to core.Expect[R] performed by method fluentToCoreExpect in work.martins.simon.expect.fluent.
    Definition Classes
    Expect
    Example:
    1. def countFilesInFolder(folder: String): Expect[Either[String, Int]] = {
        val e = new Expect(s"ls -1 $$folder", Left("unknownError"): Either[String, Int])(
          ExpectBlock(
            StringWhen("access denied")(
              Returning(Left("Access denied"))
            ),
            RegexWhen("(?s)(.*)".r)(
              ReturningWithRegex(_.group(1).split("\n").length)
            )
          )
        )
        e
      }
      
      def ensureFolderIsEmpty(folder: String): Expect[Either[String, Unit]] = {
        countFilesInFolder(folder).transform({
          case Right(numberOfFiles) =>
            Expect(s"rm -r $$folder", Left("unknownError"): Either[String, Unit])(
              ExpectBlock(
                StringWhen("access denied")(
                  Returning(Left("Access denied"))
                ),
                EndOfFileWhen(
                  Returning(())
                )
              )
            )
        }, {
          case Left(l) => Left(l)
          case Right(numberOfFiles) if numberOfFiles == 0 => Right(())
        })
      }
  51. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  52. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  53. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  54. def withFilter(p: (R) ⇒ Boolean): core.Expect[R]

    Used by for-comprehensions.

    Used by for-comprehensions.

    Implicit
    This member is added by an implicit conversion from Expect[R] to core.Expect[R] performed by method fluentToCoreExpect in work.martins.simon.expect.fluent.
    Definition Classes
    Expect
  55. def zip[T](that: core.Expect[T]): core.Expect[(R, T)]

    Zips the results of this and that Expect, and creates a new Expect holding the tuple of their results.

    Zips the results of this and that Expect, and creates a new Expect holding the tuple of their results.

    T

    the type of the returned Expect

    that

    the other Expect

    returns

    an Expect with the results of both Expects

    Implicit
    This member is added by an implicit conversion from Expect[R] to core.Expect[R] performed by method fluentToCoreExpect in work.martins.simon.expect.fluent.
    Definition Classes
    Expect
  56. def zipWith[T, U](that: core.Expect[T])(f: (R, T) ⇒ U): core.Expect[U]

    Zips the results of this and that Expect using a function f, and creates a new Expect holding the result.

    Zips the results of this and that Expect using a function f, and creates a new Expect holding the result.

    T

    the type of the other Expect

    U

    the type of the resulting Expect

    that

    the other Expect

    f

    the function to apply to the results of this and that

    returns

    an Expect with the result of the application of f to the results of this and that

    Implicit
    This member is added by an implicit conversion from Expect[R] to core.Expect[R] performed by method fluentToCoreExpect in work.martins.simon.expect.fluent.
    Definition Classes
    Expect
  57. def [B](y: B): (Expect[R], B)
    Implicit
    This member is added by an implicit conversion from Expect[R] to ArrowAssoc[Expect[R]] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc

Shadowed Implicit Value Members

  1. val command: Seq[String]
    Implicit
    This member is added by an implicit conversion from Expect[R] to core.Expect[R] performed by method fluentToCoreExpect in work.martins.simon.expect.fluent.
    Shadowing
    This implicitly inherited member is shadowed by one or more members in this class.
    To access this member you can use a type ascription:
    (expect: core.Expect[R]).command
    Definition Classes
    Expect
  2. val defaultValue: R
    Implicit
    This member is added by an implicit conversion from Expect[R] to core.Expect[R] performed by method fluentToCoreExpect in work.martins.simon.expect.fluent.
    Shadowing
    This implicitly inherited member is shadowed by one or more members in this class.
    To access this member you can use a type ascription:
    (expect: core.Expect[R]).defaultValue
    Definition Classes
    Expect
  3. def equals(other: Any): Boolean

    Returns whether other is an Expect with the same command, the same defaultValue, the same settings and the same expects as this Expect.

    Returns whether other is an Expect with the same command, the same defaultValue, the same settings and the same expects as this Expect.

    In the cases that expects contains an Action with a function, eg. Returning, this method will return false, because equality is not defined for functions.

    The method structurallyEqual can be used to test that two expects contain the same structure.

    other

    the other Expect to compare this Expect to.

    Implicit
    This member is added by an implicit conversion from Expect[R] to core.Expect[R] performed by method fluentToCoreExpect in work.martins.simon.expect.fluent.
    Shadowing
    This implicitly inherited member is shadowed by one or more members in this class.
    To access this member you can use a type ascription:
    (expect: core.Expect[R]).equals(other)
    Definition Classes
    Expect → AnyRef → Any
  4. val expectBlocks: core.ExpectBlock[R]*
    Implicit
    This member is added by an implicit conversion from Expect[R] to core.Expect[R] performed by method fluentToCoreExpect in work.martins.simon.expect.fluent.
    Shadowing
    This implicitly inherited member is shadowed by one or more members in this class.
    To access this member you can use a type ascription:
    (expect: core.Expect[R]).expectBlocks
    Definition Classes
    Expect
  5. def hashCode(): Int
    Implicit
    This member is added by an implicit conversion from Expect[R] to core.Expect[R] performed by method fluentToCoreExpect in work.martins.simon.expect.fluent.
    Shadowing
    This implicitly inherited member is shadowed by one or more members in this class.
    To access this member you can use a type ascription:
    (expect: core.Expect[R]).hashCode()
    Definition Classes
    Expect → AnyRef → Any
  6. val settings: Settings
    Implicit
    This member is added by an implicit conversion from Expect[R] to core.Expect[R] performed by method fluentToCoreExpect in work.martins.simon.expect.fluent.
    Shadowing
    This implicitly inherited member is shadowed by one or more members in this class.
    To access this member you can use a type ascription:
    (expect: core.Expect[R]).settings
    Definition Classes
    Expect
  7. def toString(): String
    Implicit
    This member is added by an implicit conversion from Expect[R] to core.Expect[R] performed by method fluentToCoreExpect in work.martins.simon.expect.fluent.
    Shadowing
    This implicitly inherited member is shadowed by one or more members in this class.
    To access this member you can use a type ascription:
    (expect: core.Expect[R]).toString()
    Definition Classes
    Expect → AnyRef → Any

Inherited from Expectable[R]

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion fluentToCoreExpect from Expect[R] to core.Expect[R]

Inherited by implicit conversion any2stringadd from Expect[R] to any2stringadd[Expect[R]]

Inherited by implicit conversion StringFormat from Expect[R] to StringFormat[Expect[R]]

Inherited by implicit conversion Ensuring from Expect[R] to Ensuring[Expect[R]]

Inherited by implicit conversion ArrowAssoc from Expect[R] to ArrowAssoc[Expect[R]]

Transformations

Ungrouped