Skip to content
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

Cannot access variables declared outside the with_mock function #193

Closed
andreea-bogdan opened this issue Oct 28, 2014 · 2 comments · Fixed by #207
Closed

Cannot access variables declared outside the with_mock function #193

andreea-bogdan opened this issue Oct 28, 2014 · 2 comments · Fixed by #207

Comments

@andreea-bogdan
Copy link

R version: 3.1.0
testthat: 0.9.1

Small example of the problem

test_that( "test",
          {
            value <- 1.5
            with_mock(
              expect_equal(2 * 3, 4),
              all.equal = function(x, y, ...) {value}
            )
          }
)

If I am executing the above code snippet through the “Test package” button in RStudio, then I get the error:

“1. Error: test -----------------------------------------------------------------
object 'value' not found”

Currently it seems it is not possible to reference from the mocked function variables which are declared outside the scope of the with_mock function

@krlmlr
Copy link
Member

krlmlr commented Jan 5, 2015

@andreea-bogdan: Thanks for reporting this. Could you please test my pull request? Install with devtools::install_github("hadley/devtools#207")

@hadley
Copy link
Member

hadley commented Jan 7, 2015

Should be fixed now.

@hadley hadley closed this as completed Jan 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants