Closed blurrcat closed 7 years ago
There are some documented ways of reusing specs, I think the first option might be suitable for your usecase
Describe("Cache", func() {
var c Cache
AssertCacheBehavior := func(){
It("should ...")
It("should ...")
}
Describe("LRU Cache", func(){
BeforeEach(func(){
c = NewLRUCache()
} )
AssertCacheBehavior()
})
Describe("Other Cache", func(){
BeforeEach(func(){
c = NewOtherCache()
} )
AssertCacheBehavior()
})
})
Thanks @tinygrasshopper! This is exactly what I'm looking for. Coming from TDD, the phrase "shared behaviors" just didn't ring the bell for me. Guess I should have read the docs more carefully!
Say we have an interface called
Cache
and I have a spec that tests its various methods:Suppose I have 2 implementations of
Cache
, likeLRUCache
andLFUCache
, is there a way to re-use the spec? For example, by allowing the Describe callback accepting some parameters? Thetable
extension seems to work only on theIt
level.Currently I wrap the spec inside a for loop:
What's the recommended way to do it? Thanks in advance.