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

spec tree in docs #903

Closed
axilis-marko opened this issue Feb 8, 2022 · 1 comment
Closed

spec tree in docs #903

axilis-marko opened this issue Feb 8, 2022 · 1 comment

Comments

@axilis-marko
Copy link

I was going through the docs and came up on something in the Mental model .
This is the code layout used as an example in the section:

var _ = Describe("Books", func() {
  var book *books.Book

  BeforeEach(func() {
    //Closure A
    book = &books.Book{
      Title: "Les Miserables",
      Author: "Victor Hugo",
      Pages: 2783,
    }
    Expect(book.IsValid()).To(BeTrue())
  })

  Describe("Extracting names", func() {
    When("author has both names", func() {
      It("extracts the last name", func() {        
        //Closure B
        Expect(book.AuthorLastName()).To(Equal("Hugo"))
      })

      It("extracts the first name", func() {
        //Closure C
        Expect(book.AuthorFirstName()).To(Equal("Victor"))
      })      
    })

    When("author has one name", func() {
      BeforeEach(func() {
        //Closure D
        book.Author = "Hugo"
      })  

      It("extracts the last name", func() {
        //Closure E
        Expect(book.AuthorLastName()).To(Equal("Hugo"))
      })

      It("returns empty first name", func() {
        //Closure F
        Expect(book.AuthorFirstName()).To(BeZero())
      })
    })

  })
})

And it goes on to say:

"We could represent the spec tree that Ginkgo generates as follows:"

Describe: "Books"
  |_BeforeEach: <Closure-A>
  |_Describe: "Extracting names"
  |_When: "author has both names"
    |_It: "extracts the last name", <Closure-B>
    |_It: "extracts the first name", <Closure-C>
  |_When: "author has one name"
    |_BeforeEach: <Closure-D>
    |_It: "extracts the last name", <Closure-E>
    |_It: "returns empty first name", <Closure-F>

Shouldn’t it be that the When nodes are subnodes of the second Describe? Giving the following spec tree:

Describe: "Books"
  |_BeforeEach: <Closure-A>
  |_Describe: "Extracting names"
    |_When: "author has both names"
      |_It: "extracts the last name", <Closure-B>
      |_It: "extracts the first name", <Closure-C>
    |_When: "author has one name"
      |_BeforeEach: <Closure-D>
      |_It: "extracts the last name", <Closure-E>
      |_It: "returns empty first name", <Closure-F>
@onsi onsi closed this as completed in 359913b Feb 11, 2022
@onsi
Copy link
Owner

onsi commented Feb 11, 2022

Hey @axilis-marko - you are exactly right. thanks for catching that! I've just pushed a fix up now.

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