File: call-expectations.Rd

package info (click to toggle)
r-cran-mockery 0.4.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 172 kB
  • sloc: sh: 13; makefile: 2
file content (55 lines) | stat: -rw-r--r-- 1,378 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/expectations.R
\name{call-expectations}
\alias{call-expectations}
\alias{expect_call}
\alias{expect_args}
\alias{expect_called}
\title{Expectation: does the given call match the expected?}
\usage{
expect_call(mock_object, n, expected_call)

expect_args(mock_object, n, ...)

expect_called(mock_object, n)
}
\arguments{
\item{mock_object}{A \code{\link{mock}} object.}

\item{n}{Call number or total number of calls.}

\item{expected_call}{Expected call expression; will be compared unevaluated.}

\item{...}{Arguments as passed in a call.}
}
\description{
Together with \code{\link{mock}} can be used to verify whether the
call expression (\code{\link{expect_call}}) and/or argument values
(\code{\link{expect_args}}) match the expected.
}
\details{
With \code{expect_called} you can check how many times has the mock
object been called.
}
\examples{
library(testthat)

# expect call expression (signature)
m <- mock()
with_mock(summary = m, summary(iris))

# it has been called once
expect_called(m, 1)

# the first (and only) call's arguments matches summary(iris)
expect_call(m, 1, summary(iris))

# expect argument value
m <- mock()
a <- iris
with_mock(summary = m, summary(object = a))
expect_args(m, 1, object = a)
# is an equivalent to ...
expect_equal(mock_args(m)[[1]], list(object = a))

}