forked from sethp-nr/icanhazdadjoke
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_test.go
55 lines (46 loc) · 1.13 KB
/
client_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package icanhazdadjoke
import (
"net/http"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/ghttp"
)
var _ = Describe("The dad joke client", func() {
var server *ghttp.Server
var client *Client
BeforeEach(func() {
server = ghttp.NewServer()
client = NewClient(serverUrl(server))
})
JustBeforeEach(func() {
Expect(client).To(Not(BeNil()))
})
AfterEach(func() {
server.Close()
})
Describe("fetching plain text joke", func() {
BeforeEach(func() {
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/"),
ghttp.VerifyHeader(http.Header{
"User-Agent": []string{UserAgent},
}),
ghttp.VerifyHeader(http.Header{
"Accept": []string{"text/plain"},
}),
// https://icanhazdadjoke.com/j/fiyPR7wPZDd
ghttp.RespondWith(200, "When does a joke become a dad joke? When it becomes apparent."),
),
)
})
It("retrieves a random joke", func() {
Expect(client.GetRandomJokeText()).To(ContainSubstring("apparent"))
})
})
})
func serverUrl(server *ghttp.Server) FuncOpt {
return func(c *Client) {
c.url = server.URL()
}
}