Last active
January 2, 2016 21:49
-
-
Save daneharrigan/8366046 to your computer and use it in GitHub Desktop.
golang BDD concept
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
}) | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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