Add an arbitrary When
to this ExpectBlock
.
Add an arbitrary When
to this ExpectBlock
.
This is helpful to refactor code. For example: imagine you have an error case you want to add to
multiple ExpectBlock
s. You could leverage this method to do so in the following way:
def errorCaseWhen(expectBlock: ExpectBlock[String]): When[String] = { expectBlock .when("Some error") .returning("Got some error") } def parseOutputA: Expect[String] = { val e = new Expect("some command", "") e.expect .when(...) .sendln(...) e.expect .addWhen(errorCaseWhen) .exit() } def parseOutputB: Expect[String] = { val e = new Expect("some command", "") e.expect .when(...) .sendln(..) .returning(...) .addWhen(errorCaseWhen) }
This function returns the added When which allows you to add further actions, see the exit action of the
parseOutputA
method in the above code.
It is possible to add more than one When using this method, however this is discouraged since it will make the code somewhat more illegible because "hidden" Whens will also be added.
If you need to add more than one When you have two options:
e.expect .when(...) .sendln(..) .returning(...) .addWhen(errorCaseWhen) .addWhen(anotherWhen)
e.expect .when(...) .sendln(..) .returning(...) .addWhens(multipleWhens)
function that adds the When
.
the added When
.
Add arbitrary When
s to this ExpectBlock
.
Add arbitrary When
s to this ExpectBlock
.
This method is very similar to the addWhen
with the following differences:
f
has a more relaxed type.function that adds When
s.
this ExpectBlock.
Adds a new TimeoutWhen
that matches whenever a Timeout in thrown while trying to read text
from the process output (stdOut).
Adds a new TimeoutWhen
that matches whenever a Timeout in thrown while trying to read text
from the process output (stdOut).
the pattern to match against.
the new TimeoutWhen
.
Adds a new EndOfFileWhen
that matches whenever the EndOfFile in the process output (stdOut) is reached.
Adds a new EndOfFileWhen
that matches whenever the EndOfFile in the process output (stdOut) is reached.
the pattern to match against.
the new EndOfFileWhen
.
Adds a new RegexWhen
that matches whenever the regex pattern
successfully matches
against the text read from the process output (stdOut).
Adds a new RegexWhen
that matches whenever the regex pattern
successfully matches
against the text read from the process output (stdOut).
the pattern to match against.
the new RegexWhen
.
Adds a new StringWhen
that matches whenever pattern
is contained
in the text read from the process output (stdOut).
Adds a new StringWhen
that matches whenever pattern
is contained
in the text read from the process output (stdOut).
the pattern to match against.
the new StringWhen
.