Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
bleakley authored May 10, 2019
1 parent 15b2487 commit f65daa6
Showing 1 changed file with 39 additions and 38 deletions.
77 changes: 39 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,54 +59,55 @@ So(testSlice, Exactly(1, func(actual interface{}, expected ...interface{}) strin
Contains custom assertions that work with [goconvey](https://github.com/smartystreets/goconvey).

For example, if we have some code that returns an error:
```golang
package thehulk

package thehulk

import (
"fmt"
)

type Hulk struct {
isHulked boolean
}
import (
"fmt"
)

func (h *Hulk) Hulkify(angerLevel int) error {
if angerLevel < 3 {
return fmt.Errorf("Not angry enough: %d", angerLevel)
}
h.isHulked = true
return nil
}
type Hulk struct {
isHulked bool
}

func (h *Hulk) Hulkify(angerLevel int) error {
if angerLevel < 3 {
return fmt.Errorf("Not angry enough: %d", angerLevel)
}
h.isHulked = true
return nil
}
```
We might test it like this:
```golang
package thehulk_test

package thehulk_test

import (
"fmt"
"testing"
import (
"fmt"
"testing"

. "github.com/smartystreets/goconvey/convey"
. "github.com/recursionpharma/go-testutils/assertions"
)
. "github.com/smartystreets/goconvey/convey"
. "github.com/recursionpharma/go-testutils/assertions"
)

func TestHulkify (t *testing.T) {
t.Parallel()
func TestHulkify (t *testing.T) {
t.Parallel()

Convey("Given an anger level", t, func() {
Convey("Given an anger level", t, func() {

Convey("If the anger is too low, an error should be returned", func() {
angerLevel := 2
err := h.Hulkify(angerLevel)
So(err, ShouldHaveErrorMessageWithSubstring, fmt.Sprintf("%d", angerLevel))
})
Convey("If the anger is too low, an error should be returned", func() {
angerLevel := 2
err := h.Hulkify(angerLevel)
So(err, ShouldHaveErrorMessageWithSubstring, fmt.Sprintf("%d", angerLevel))
})

Convey("If the anger is high enough, no error should be returned", func() {
err := h.Hulkify(5)
So(err, ShouldBeNil)
})
})
}
Convey("If the anger is high enough, no error should be returned", func() {
err := h.Hulkify(5)
So(err, ShouldBeNil)
})
})
}
```

## This repo

Expand Down

0 comments on commit f65daa6

Please sign in to comment.