File: mockery.R

package info (click to toggle)
r-cran-mockery 0.4.1.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 168 kB
  • sloc: sh: 13; makefile: 2
file content (34 lines) | stat: -rw-r--r-- 780 bytes parent folder | download | duplicates (3)
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
#' R package to make mocking easier
#'
#' There are great tools for unit testing in R out there already but
#' they don't come with a lot of support for mock objects. This
#' package aims at fixing that.
#'
#' @docType package
#' @name mockery
#'
#' @examples
#' library(mockery)
#' 
#' m <- mock(TRUE, FALSE, TRUE)
#' 
#' # this will make summary call our mock function rather then
#' # UseMethod; thus, summary() will return values as above
#' stub(summary, 'UseMethod', m)
#' 
#' summary(iris) # returns TRUE
#' summary(cars) # returns FALSE
#' summary(co2)  # returns TRUE
#' 
#' \dontrun{
#' library(testthat)
#' 
#' m <- mock(TRUE)
#' f <- function() read.csv('data.csv')
#' 
#' with_mock(read.csv = m, {
#'   f()
#'   expect_call(m, 1, read.csv('data.csv'))
#' })
#' }
NULL