Skip to content

Instantly share code, notes, and snippets.

@daneharrigan
Last active January 2, 2016 21:49
Show Gist options
  • Save daneharrigan/8366046 to your computer and use it in GitHub Desktop.
Save daneharrigan/8366046 to your computer and use it in GitHub Desktop.
golang BDD concept
package bdd_test
import (
"testing"
. "github.com/daneharrigan/bdd"
)
func TestSpecs(t *testing.T) {
defer Runner(t)
Describe("description", func(){
Before(func(){
// do something
})
After(func(){
// do something
})
It("does something", func(){
Expect("string").ToEqual("string")
})
})
}
package bdd
import "testing"
var desc []*Desc
type Desc struct {
Description string
Tests []*Test
Before func()
After func()
}
type Test struct {
Description string
Fn func()
}
func Runner(t *testing.T) {
}
func Describe(s string, fn func()) {
desc = append(desc, &Desc{ Description: s })
fn()
}
func It(s string, fn func()) {
i := len(desc) - 1
desc[i].Tests = append(desc[i].Tests, &Test{ Description: s, Fn: fn })
}
func Before(fn func()) {
desc[len(desc) - 1].Before = fn
}
func After(fn func()) {
desc[len(desc) - 1].After = fn
}
func Expect(s string) Expectation {
return Expectation{Value: s}
}
// Expectations
type Expectation struct {
Value string
}
func (e Expectation) ToEqual(s string) {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment