Skip to content

Instantly share code, notes, and snippets.

@mgenov
Forked from karlseguin/spec.go
Last active August 29, 2015 14:17
Show Gist options
  • Save mgenov/ddbfd489dc4609a20f5b to your computer and use it in GitHub Desktop.
Save mgenov/ddbfd489dc4609a20f5b to your computer and use it in GitHub Desktop.
package tests
import (
"testing"
)
type S struct {
t *testing.T
}
type SR struct {
t *testing.T
expected []interface{}
}
func Spec(t *testing.T) (*S) {
return &S{t:t}
}
func (s *S) Expect(expected ... interface{}) (sr *SR) {
return &SR{t: s.t, expected: expected,}
}
func (sr *SR) ToEqual(actuals ... interface{}) {
for index, actual := range(actuals) {
if sr.expected[index] != actual {
sr.t.Errorf("expected %+v to equal %+v", sr.expected[index], actual)
}
}
}
func (sr *SR) ToNotEqual(actuals ... interface{}) {
for index, actual := range(actuals) {
if sr.expected[index] == actual {
sr.t.Errorf("expected %+v to not equal %+v", sr.expected[index], actual)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment