Last active
December 20, 2015 00:28
-
-
Save jcinnamond/6041504 to your computer and use it in GitHub Desktop.
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 gospec | |
import ( | |
"testing" | |
) | |
type specrunner struct { | |
t *testing.T | |
} | |
type spec struct { | |
t *testing.T | |
description string | |
actual interface{} | |
inverted bool | |
} | |
func New(t *testing.T) *specrunner { | |
return &specrunner{t} | |
} | |
func (runner *specrunner) Check(actual interface{}) *spec { | |
return &spec{actual: actual, t: runner.t} | |
} | |
func (spec *spec) As(description string) *spec { | |
spec.description = description | |
return spec | |
} | |
func (spec *spec) Not() *spec { | |
spec.inverted = true | |
return spec | |
} | |
func (spec *spec) Equals(expected interface{}) { | |
failed := spec.actual != expected | |
if spec.inverted { | |
failed = !failed | |
} | |
if failed { | |
error := "expected" | |
if spec.description != "" { | |
error += " " + spec.description + " to equal" | |
} | |
spec.t.Errorf("%s %q got %q", error, expected, spec.actual) | |
} | |
} |
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 restful | |
import ( | |
"github.com/jcinnamond/gospec" | |
"testing" | |
) | |
// func TestCollectionPath (t *testing.T) { | |
// api := ApiResource{Path: "/api/thing"} | |
// if api.collectionPath() != "/api/thing/?" { | |
// t.Errorf("expected collectionPath to be `/api/thing/?`, got %s", api.collectionPath()) | |
// } | |
// } | |
func TestCollectionPath(t *testing.T) { | |
spec := gospec.New(t) | |
api := ApiResource{Path: "/api/thing"} | |
spec.Check(api.collectionPath()).As("collectionPath").Equals("/api/thing/?") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment