Tweaks and improvements - Fixes #154

pull/156/head
Mat Ryer 2015-04-20 11:19:11 +01:00
parent 3b361f7ebb
commit e22aedd376
6 changed files with 19 additions and 15 deletions

View File

@ -36,15 +36,12 @@ func ObjectsAreEqual(expected, actual interface{}) bool {
return true
}
// Last ditch effort
if fmt.Sprintf("%#v", expected) == fmt.Sprintf("%#v", actual) {
return true
}
return false
}
// ObjectsAreEqualValues gets whether two objects are equal, or if their
// values are equal.
func ObjectsAreEqualValues(expected, actual interface{}) bool {
if ObjectsAreEqual(expected, actual) {
return true

View File

@ -1,4 +1,4 @@
// A set of comprehensive testing tools for use with the normal Go testing system.
// Package assert provides a set of comprehensive testing tools for use with the normal Go testing system.
//
// Example Usage
//

View File

@ -2,10 +2,13 @@ package assert
import "time"
// Assertions provides assertion methods around the
// TestingT interface.
type Assertions struct {
t TestingT
}
// New makes a new Assertions object for the specified TestingT.
func New(t TestingT) *Assertions {
return &Assertions{
t: t,
@ -85,7 +88,7 @@ func (a *Assertions) Empty(object interface{}, msgAndArgs ...interface{}) bool {
return Empty(a.t, object, msgAndArgs...)
}
// Empty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or a
// NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or a
// slice with len == 0.
//
// if assert.NotEmpty(obj) {
@ -152,7 +155,7 @@ func (a *Assertions) NotContains(s, contains interface{}, msgAndArgs ...interfac
return NotContains(a.t, s, contains, msgAndArgs...)
}
// Uses a Comparison to assert a complex condition.
// Condition uses a Comparison to assert a complex condition.
func (a *Assertions) Condition(comp Comparison, msgAndArgs ...interface{}) bool {
return Condition(a.t, comp, msgAndArgs...)
}

View File

@ -264,7 +264,7 @@ func TestNoErrorWrapper(t *testing.T) {
mockAssert := New(new(testing.T))
// start with a nil error
var err error = nil
var err error
assert.True(mockAssert.NoError(err), "NoError should return True for nil arg")
@ -280,7 +280,7 @@ func TestErrorWrapper(t *testing.T) {
mockAssert := New(new(testing.T))
// start with a nil error
var err error = nil
var err error
assert.False(mockAssert.Error(err), "Error should return False for nil arg")

View File

@ -59,9 +59,9 @@ func HTTPError(t TestingT, handler http.HandlerFunc, mode, url string, values ur
return code >= http.StatusBadRequest
}
// HttpBody is a helper that returns HTTP body of the response. It returns
// HTTPBody is a helper that returns HTTP body of the response. It returns
// empty string if building a new request fails.
func HttpBody(handler http.HandlerFunc, mode, url string, values url.Values) string {
func HTTPBody(handler http.HandlerFunc, mode, url string, values url.Values) string {
w := httptest.NewRecorder()
req, err := http.NewRequest(mode, url+"?"+values.Encode(), nil)
if err != nil {
@ -78,7 +78,7 @@ func HttpBody(handler http.HandlerFunc, mode, url string, values url.Values) str
//
// Returns whether the assertion was successful (true) or not (false).
func HTTPBodyContains(t TestingT, handler http.HandlerFunc, mode, url string, values url.Values, str interface{}) bool {
body := HttpBody(handler, mode, url, values)
body := HTTPBody(handler, mode, url, values)
contains := strings.Contains(body, fmt.Sprint(str))
if !contains {
@ -95,7 +95,7 @@ func HTTPBodyContains(t TestingT, handler http.HandlerFunc, mode, url string, va
//
// Returns whether the assertion was successful (true) or not (false).
func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, mode, url string, values url.Values, str interface{}) bool {
body := HttpBody(handler, mode, url, values)
body := HTTPBody(handler, mode, url, values)
contains := strings.Contains(body, fmt.Sprint(str))
if contains {

6
doc.go
View File

@ -1,4 +1,4 @@
// A set of packages that provide many tools for testifying that your code will behave as you intend.
// Package testify is a set of packages that provide many tools for testifying that your code will behave as you intend.
//
// testify contains the following packages:
//
@ -11,8 +11,12 @@
// The suite package provides a basic structure for using structs as testing suites, and methods on those structs as tests. It includes setup/teardown functionality in the way of interfaces.
package testify
// blank imports help docs.
import (
// assert package
_ "github.com/stretchr/testify/assert"
// http package
_ "github.com/stretchr/testify/http"
// mock package
_ "github.com/stretchr/testify/mock"
)