Skip to content

Commit

Permalink
Merge pull request #7 from n-s-f/fix-vignette-builder
Browse files Browse the repository at this point in the history
Fix vignette builder
  • Loading branch information
lbartnik committed Oct 24, 2016
2 parents 7e67292 + bf369e4 commit 84b7ff2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 33 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
^.*\.Rproj$
^\.Rproj\.user$
4 changes: 4 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ BugReports: https://github.com/n-s-f/mockery/issues
Imports:
testthat,
utils
Suggests:
knitr,
rmarkdown (>= 1.0)
License: MIT + file LICENSE
Collate:
'expect_called.R'
Expand All @@ -27,4 +30,5 @@ Collate:
'mockery.R'
'mock-object.R'
'stub.R'
VignetteBuilder: knitr
RoxygenNote: 5.0.1
54 changes: 21 additions & 33 deletions vignettes/mocks-and-testthat.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ vignette: >
%\VignetteEncoding{UTF-8}
---

```{r echo=FALSE, results='hide'}
```{r include=FALSE}
library(mockery)
library(knitr)
opts_chunk$set(results = 'hold')
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
```


Expand Down Expand Up @@ -75,13 +75,11 @@ can also choose to cycle through the list of retun values by setting the
```{r cycle_no, eval=FALSE}
m <- mock(1, 2)
m()
#> [1] 1
m()
#> [1] 2
m()
```
```
## [1] 1
## [1] 2
## Error: too many calls to mock object and cycle set to FALSE
#> Error: too many calls to mock object and cycle set to FALSE
```

```{r cycle_true}
Expand Down Expand Up @@ -123,8 +121,6 @@ e <- new.env()
m <- mock(x + y, envir = e, cycle = TRUE)
m()
```
```{r return_expression_env_2nd}
e$x <- 10
m()
```
Expand Down Expand Up @@ -172,11 +168,9 @@ And here is what happens when we get the number of calls wrong.

```{r expect_no_calls_error, eval=FALSE}
expect_no_calls(m, 1)
#> Error: mock object has not been called 1 time.
expect_no_calls(m, 3)
```
```
## Error: mock object has not been called 1 time.
## Error: mock object has not been called 3 times.
#> Error: mock object has not been called 3 times.
```

### Verify the call signature
Expand All @@ -198,9 +192,7 @@ And here is what happens if the call doesn't match.

```{r call_doesnt_match, eval=FALSE}
expect_call(m, 1, summary(x))
```
```
## Error: expected call summary(x) does not mach actual call summary(iris).
#> Error: expected call summary(x) does not mach actual call summary(iris).
```

### Verify values of argument
Expand All @@ -218,18 +210,16 @@ Here is what happens if the value turns out to be different.

```{r expect_args_different, eval=FALSE}
expect_args(m, 1, iris[-1, ])
```
```
## Error: arguments to call #1 not equal to expected arguments.
## Component 1: Attributes: < Component "row.names": Numeric: lengths (150, 149) differ >
## Component 1: Component 1: Numeric: lengths (150, 149) differ
## Component 1: Component 2: Numeric: lengths (150, 149) differ
## Component 1: Component 3: Numeric: lengths (150, 149) differ
## Component 1: Component 4: Numeric: lengths (150, 149) differ
## Component 1: Component 5: Lengths: 150, 149
## Component 1: Component 5: Lengths (150, 149) differ (string compare on first 149)
## Component 1: Component 5: 2 string mismatches
## expected argument list does not mach actual one.
#> Error: arguments to call #1 not equal to expected arguments.
#> Component 1: Attributes: < Component "row.names": Numeric: lengths (150, 149) differ >
#> Component 1: Component 1: Numeric: lengths (150, 149) differ
#> Component 1: Component 2: Numeric: lengths (150, 149) differ
#> Component 1: Component 3: Numeric: lengths (150, 149) differ
#> Component 1: Component 4: Numeric: lengths (150, 149) differ
#> Component 1: Component 5: Lengths: 150, 149
#> Component 1: Component 5: Lengths (150, 149) differ (string compare on first 149)
#> Component 1: Component 5: 2 string mismatches
#> expected argument list does not mach actual one.
```

If the call has been made with an explicit argument name the same has
Expand All @@ -248,11 +238,9 @@ Omitting the name results in an error.

```{r expect_args_unnamed, eval=FALSE}
expect_args(m, 1, iris)
```
```
## Error: arguments to call #1 not equal to expected arguments.
## names for target but not for current
## expected argument list does not mach actual one.
#> Error: arguments to call #1 not equal to expected arguments.
#> names for target but not for current
#> expected argument list does not mach actual one.
```


Expand Down

0 comments on commit 84b7ff2

Please sign in to comment.