allow github syntax highlighting

This commit is contained in:
dickeyxxx 2014-07-01 08:43:26 -07:00
parent ce71e91e8d
commit 81cfe446ab

View File

@ -31,6 +31,7 @@ The `assert` package provides some helpful methods that allow you to write bette
See it in action: See it in action:
```go
func TestSomething(t *testing.T) { func TestSomething(t *testing.T) {
// assert equality // assert equality
@ -52,12 +53,14 @@ See it in action:
} }
} }
```
* Every assert func takes the `testing.T` object as the first argument. This is how it writes the errors out through the normal `go test` capabilities. * Every assert func takes the `testing.T` object as the first argument. This is how it writes the errors out through the normal `go test` capabilities.
* Every assert func returns a bool indicating whether the assertion was successful or not, this is useful for if you want to go on making further assertions under certain conditions. * Every assert func returns a bool indicating whether the assertion was successful or not, this is useful for if you want to go on making further assertions under certain conditions.
if you assert many times, use the below: if you assert many times, use the below:
```go
func TestSomething(t *testing.T) { func TestSomething(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
@ -78,6 +81,7 @@ if you assert many times, use the below:
assert.Equal("Something", object.Value) assert.Equal("Something", object.Value)
} }
} }
```
`http` package `http` package
-------------- --------------
@ -91,6 +95,7 @@ The `mock` package provides a mechanism for easily writing mock objects that can
An example test function that tests a piece of code that relies on an external object `testObj`, can setup expectations (testify) and assert that they indeed happened: An example test function that tests a piece of code that relies on an external object `testObj`, can setup expectations (testify) and assert that they indeed happened:
```go
package yours package yours
import ( import (
@ -143,6 +148,7 @@ An example test function that tests a piece of code that relies on an external o
testObj.Mock.AssertExpectations(t) testObj.Mock.AssertExpectations(t)
} }
```
For more information on how to write mock code, check out the [API documentation for the `mock` package](http://godoc.org/github.com/stretchr/testify/mock). For more information on how to write mock code, check out the [API documentation for the `mock` package](http://godoc.org/github.com/stretchr/testify/mock).
@ -153,6 +159,7 @@ The `suite` package provides functionality that you might be used to from more c
An example suite is shown below: An example suite is shown below:
```go
// Basic imports // Basic imports
import ( import (
"testing" "testing"
@ -185,6 +192,7 @@ An example suite is shown below:
func TestExampleTestSuite(t *testing.T) { func TestExampleTestSuite(t *testing.T) {
suite.Run(t, new(ExampleTestSuite)) suite.Run(t, new(ExampleTestSuite))
} }
```
For a more complete example, using all of the functionality provided by the suite package, look at our [example testing suite](https://github.com/stretchr/testify/blob/master/suite/suite_test.go) For a more complete example, using all of the functionality provided by the suite package, look at our [example testing suite](https://github.com/stretchr/testify/blob/master/suite/suite_test.go)
@ -192,6 +200,7 @@ For more information on writing suites, check out the [API documentation for the
`Suite` object has assertion methods: `Suite` object has assertion methods:
```go
// Basic imports // Basic imports
import ( import (
"testing" "testing"
@ -222,6 +231,7 @@ For more information on writing suites, check out the [API documentation for the
func TestExampleTestSuite(t *testing.T) { func TestExampleTestSuite(t *testing.T) {
suite.Run(t, new(ExampleTestSuite)) suite.Run(t, new(ExampleTestSuite))
} }
```
------ ------
@ -240,6 +250,7 @@ This will then make the following packages available to you:
Import the `testify/assert` package into your code using this template: Import the `testify/assert` package into your code using this template:
```go
package yours package yours
import ( import (
@ -252,6 +263,7 @@ Import the `testify/assert` package into your code using this template:
assert.True(t, true, "True is true!") assert.True(t, true, "True is true!")
} }
```
------ ------