The name of the function being tested must be provided as the top level
<function name> in the above example).
Arguments to the function can be specified by chaining the
on to the
A lambda (block) can be passed to functions that support either a required or
optional lambda by chaining the
with_lambda method on to the
The return value of the function can be tested by chaining the
method on to the
If the function is expected to raise an exception (for example, when testing
input validation), this can be tested by chaining the
on to the
Some complex functions require access to the parser’s scope (for example,
functions that look up values of variables that are not passed in as
arguments). For this reason, the scope is available to the tests as the
Using the above example, to stub out a
lookupvar call that the function
being tested uses, the following could be used (if using rspec-mocks).
If the function being tested modifies the catalogue in some way, the standard catalogue matchers (as used when testing classes or defined types) are available to be used.
An example of a function where this is needed is the
from puppetlabs/stdlib which adds resources to the catalogue.
The catalogue is exposed to the tests as the