Skip to content

Instantly share code, notes, and snippets.

@dukex
Created May 9, 2014 14:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dukex/050dd55bf5d173c886ae to your computer and use it in GitHub Desktop.
Save dukex/050dd55bf5d173c886ae to your computer and use it in GitHub Desktop.
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