Created
May 9, 2014 14:26
-
-
Save dukex/050dd55bf5d173c886ae 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 xpto | |
import ( | |
"fmt" | |
"io/ioutil" | |
"net/http" | |
"net/http/httptest" | |
"strings" | |
"testing" | |
. "github.com/franela/goblin" | |
. "github.com/onsi/gomega" | |
) | |
func Fixture(name string) ([]byte, error) { | |
filename := strings.Replace(name, "/", "-", -1) | |
return ioutil.ReadFile("fixtures/" + filename + ".json") | |
} | |
func Test(t *testing.T) { | |
g := Goblin(t) | |
g.Describe("CreateActivity", func() { | |
var ts *httptest.Server | |
g.Before(func() { | |
ts = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
w.WriteHeader(200) | |
body, _ := Fixture(r.Method + r.URL.Path) | |
fmt.Fprint(w, string(body)) | |
})) | |
}) | |
g.After(func() { | |
ts.Close() | |
}) | |
g.It("returns a Activity", func() { | |
hubbiz := NewHubbiz(ts.URL) | |
activityParams := map[string]interface{}{"Content": "Post", "Actor": []string{"users:1"}} | |
activity, _ := hubbiz.CreateActivity(activityParams) | |
Expect(activity.Content).Should(Equal("My Post")) | |
}) | |
g.It("returns request Error", func() { | |
hubbiz := NewHubbiz(":") | |
activityParams := map[string]interface{}{"Content": "Post"} | |
activity, err := hubbiz.CreateActivity(activityParams) | |
Expect(activity).Should(BeNil()) | |
Expect(err).ShouldNot(BeNil()) | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment