Learn R Programming

testthat (version 3.3.0)

mock_output_sequence: Mock a sequence of output from a function

Description

Specify multiple return values for mocking

Usage

mock_output_sequence(..., recycle = FALSE)

Value

A function that you can use within local_mocked_bindings() and with_mocked_bindings()

Arguments

...

<dynamic-dots> Values to return in sequence.

recycle

whether to recycle. If TRUE, once all values have been returned, they will be returned again in sequence.

See Also

Other mocking: local_mocked_bindings()

Examples

Run this code
# inside local_mocked_bindings()
if (FALSE) {
local_mocked_bindings(readline = mock_output_sequence("3", "This is a note", "n"))
}
# for understanding
mocked_sequence <- mock_output_sequence("3", "This is a note", "n")
mocked_sequence()
mocked_sequence()
mocked_sequence()
try(mocked_sequence())
recycled_mocked_sequence <- mock_output_sequence(
  "3", "This is a note", "n",
  recycle = TRUE
)
recycled_mocked_sequence()
recycled_mocked_sequence()
recycled_mocked_sequence()
recycled_mocked_sequence()

Run the code above in your browser using DataLab