| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/expectations.R |
| 3 |
\name{call-expectations} |
| 4 |
\alias{call-expectations} |
| 5 |
\alias{expect_call} |
| 6 |
\alias{expect_args} |
| 7 |
\alias{expect_called} |
| 8 |
\title{Expectation: does the given call match the expected?} |
| 9 |
\usage{ |
| 10 |
expect_call(mock_object, n, expected_call) |
| 11 |
|
| 12 |
expect_args(mock_object, n, ...) |
| 13 |
|
| 14 |
expect_called(mock_object, n) |
| 15 |
} |
| 16 |
\arguments{ |
| 17 |
\item{mock_object}{A \code{\link{mock}} object.} |
| 18 |
|
| 19 |
\item{n}{Call number or total number of calls.} |
| 20 |
|
| 21 |
\item{expected_call}{Expected call expression; will be compared unevaluated.} |
| 22 |
|
| 23 |
\item{...}{Arguments as passed in a call.} |
| 24 |
} |
| 25 |
\description{ |
| 26 |
Together with \code{\link{mock}} can be used to verify whether the |
| 27 |
call expression (\code{\link{expect_call}}) and/or argument values |
| 28 |
(\code{\link{expect_args}}) match the expected. |
| 29 |
} |
| 30 |
\details{ |
| 31 |
With \code{expect_called} you can check how many times has the mock |
| 32 |
object been called. |
| 33 |
} |
| 34 |
\examples{ |
| 35 |
library(testthat) |
| 36 |
|
| 37 |
# expect call expression (signature) |
| 38 |
m <- mock() |
| 39 |
m(iris) |
| 40 |
|
| 41 |
# it has been called once |
| 42 |
expect_called(m, 1) |
| 43 |
|
| 44 |
# the first (and only) call's arguments matches summary(iris) |
| 45 |
expect_call(m, 1, m(iris)) |
| 46 |
|
| 47 |
# expect argument value |
| 48 |
m <- mock() |
| 49 |
a <- iris |
| 50 |
m(object = a) |
| 51 |
expect_args(m, 1, object = a) |
| 52 |
# is an equivalent to ... |
| 53 |
expect_equal(mock_args(m)[[1]], list(object = a)) |
| 54 |
|
| 55 |
} |