Skip to content

Cannot access variables declared outside the with_mock function #193

@andreea-boeru

Description

@andreea-boeru

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions