From e22aedd37671fb115be6c0c25129c405cb575cfd Mon Sep 17 00:00:00 2001 From: Mat Ryer Date: Mon, 20 Apr 2015 11:19:11 +0100 Subject: [PATCH] Tweaks and improvements - Fixes #154 --- assert/assertions.go | 7 ++----- assert/doc.go | 2 +- assert/forward_assertions.go | 7 +++++-- assert/forward_assertions_test.go | 4 ++-- assert/http_assertions.go | 8 ++++---- doc.go | 6 +++++- 6 files changed, 19 insertions(+), 15 deletions(-) diff --git a/assert/assertions.go b/assert/assertions.go index 1c4b269..e4a920f 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -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 diff --git a/assert/doc.go b/assert/doc.go index 7c7f759..f678106 100644 --- a/assert/doc.go +++ b/assert/doc.go @@ -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 // diff --git a/assert/forward_assertions.go b/assert/forward_assertions.go index 67a6925..d8d3f53 100644 --- a/assert/forward_assertions.go +++ b/assert/forward_assertions.go @@ -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...) } diff --git a/assert/forward_assertions_test.go b/assert/forward_assertions_test.go index e9a4151..3df3f39 100644 --- a/assert/forward_assertions_test.go +++ b/assert/forward_assertions_test.go @@ -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") diff --git a/assert/http_assertions.go b/assert/http_assertions.go index 0419c1b..1246e58 100644 --- a/assert/http_assertions.go +++ b/assert/http_assertions.go @@ -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 { diff --git a/doc.go b/doc.go index 3bde65c..377d5cc 100644 --- a/doc.go +++ b/doc.go @@ -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" )