New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
with_mock appears not to work #5
Comments
Thanks. This is by design, see the last example in the README. How can we document this better? |
This was referenced Dec 18, 2020
With the pull request: library(mockr)
realFunction <- function() {
"real value"
}
functionToTest <- function(title) {
result <- realFunction()
cat(title, "result is", result, "\n")
}
functionToTest("without mock:")
#> without mock: result is real value
replacementFunction <- function() {
"replacement value"
}
with_mock(
realFunction = replacementFunction,
functionToTest("mocking with replacementFunction:")
)
#> Warning: Replacing functions in evaluation environment: `realFunction()`
#> mocking with replacementFunction: result is replacement value
with_mock(
realFunction = function() "inline value",
functionToTest("mocking with inline replacement:")
)
#> Warning: Replacing functions in evaluation environment: `realFunction()`
#> mocking with inline replacement: result is inline value Created on 2020-12-18 by the reprex package (v0.3.0) |
krlmlr
added a commit
that referenced
this issue
Dec 18, 2020
- Functions declared in evaluation environments are now also replaced, with a warning (#5).
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
mockr::with_mock
appears not to work in this case:output:
If I replace
library(mockr)
withlibrary(testthat)
and re-run without any other changes, the output is as expected:I am using mockr version 0.1 (from
install.packages("mockr")
) and testthat 2.0.0.9000 with R version 3.5.1 on Mac OS X 10.13.6 (High Sierra).The text was updated successfully, but these errors were encountered: