franela / goblin

Minimal and Beautiful Go testing framework
MIT License
887 stars 79 forks source link

Feature/skip describe standalone #84

Open sockol opened 4 years ago

sockol commented 4 years ago

Motivations

Goblin is inspired by Mocha, and Mocha has a set of functions that allows you to skip tests. Goblin supports skipping with Xit().

Xit("skip this", func(){})

Mocha allows you to invoke tests with a skip() function:

it.skip("skip this", function(){})

Since Go does not allow us to have a struct and a function with the same name we cannot have

g.It()// It is a function attached to the G struct
g.It.Skip() // It is a nested struct in G

Alternatively, and as a way to set up skipping It tests in a future PR, we can follow this pattern:

// skip this It test
g.Skip.It("skip this", func(){})
// skip all tests in this block 
g.Skip.Describe("skip these", func(){
  g.It("skip this", func(){})
})

Changes made

  1. Add the ability to skip all tests within a describe block if it was added using g.Skip.Describe(). The before and after hooks on a skipped test in this Skip.Describe block behave the same way as g.Xit() tests - they do not run. Each Describe and It block within a Skip.Describe() will be logged in yellow.

  2. Add a test for g.Skip.Describe()

Alternatives considered:

Tried adding a new struct Xdescribe which holds Describe. The issue I ran into when trying to implement this is that each It and Describe block currently has a .parent field which references a *Describe block. That would require a big refactor to convert every Describe and Xdescribe block to implement the same interface so that the .parent in every It and Describe will refer to this interface like Runnable(). I am not completely clear if this will work, but looking for feedback if you guys think this is the preferred solution @marcosnils @xetorthio

sockol commented 4 years ago

bumping this pr