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

Nested Describe Functions Fail #24

Open
FlippieCoetser opened this issue Mar 20, 2023 · 1 comment
Open

Nested Describe Functions Fail #24

FlippieCoetser opened this issue Mar 20, 2023 · 1 comment

Comments

@FlippieCoetser
Copy link

According to Testhat Documentation, nesting describe() functions should be possible: link

Below is a copy of the example in the documentation

# Nested specs:
## code
addition <- function(a, b) a + b
division <- function(a, b) a / b

## specs
describe("math library", {
  describe("addition()", {
    it("can add two numbers", {
      expect_equal(1 + 1, addition(1, 1))
    })
  })
  describe("division()", {
    it("can divide two numbers", {
      expect_equal(10 / 2, division(10, 2))
    })
    it("can handle division by 0") #not yet implemented
  })
})

However, when trying to run the example in VS code, an error is thrown:

image

Removing the nesting like so:

## specs
describe("math library", { 
  it("can add two numbers", {
    expect_equal(1 + 1, addition(1, 1))
  })
  it("can divide two numbers", {
    expect_equal(10 / 2, division(10, 2))
  })
  it("can handle division by 0") #not yet implemented
})

Works as expected.

image

@meakbiyik
Copy link
Owner

Oof, finally someone stumbled upon some edge case of my hack of running tests by themselves 😅 Thanks for the issue, although, note that testthat has file atomicity, so anything finer than that might not be trustworthy. I will check this out at some point, but no promises.

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

No branches or pull requests

2 participants