Skip to content

Instantly share code, notes, and snippets.

@jcinnamond
Last active December 20, 2015 00:28
Show Gist options
  • Save jcinnamond/6041504 to your computer and use it in GitHub Desktop.
Save jcinnamond/6041504 to your computer and use it in GitHub Desktop.
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)
}
}
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