Skip to content

Commit

Permalink
Tweaks and improvements - Fixes stretchr#154
Browse files Browse the repository at this point in the history
  • Loading branch information
matryer committed Apr 20, 2015
1 parent 3b361f7 commit e22aedd
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
7 changes: 2 additions & 5 deletions assert/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion assert/doc.go
Original file line number Diff line number Diff line change
@@ -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
//
Expand Down
7 changes: 5 additions & 2 deletions assert/forward_assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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...)
}
Expand Down
4 changes: 2 additions & 2 deletions assert/forward_assertions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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")

Expand Down
8 changes: 4 additions & 4 deletions assert/http_assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion doc.go
Original file line number Diff line number Diff line change
@@ -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:
//
Expand All @@ -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"
)

0 comments on commit e22aedd

Please sign in to comment.