259 Commits

Author SHA1 Message Date
Paul Bellamy
925c3ad43b Reverse the stacktrace on assertion output (to match panic) 2015-06-05 10:13:41 +01:00
Paul Bellamy
a7a0af787a Add a basic stacktrace to the assertion output 2015-06-04 14:00:35 +01:00
Ernesto Jiménez
3c81d9b268 Merge pull request #175 from stretchr/variadic
Mocking variadic functions
2015-06-02 23:16:36 +01:00
Ernesto Jiménez
4464dda05e Add extra tests mocking variadic functions 2015-06-02 20:23:13 +01:00
Ernesto Jiménez
d6265bda1a Add test mocking variadic function 2015-06-02 19:59:43 +01:00
Ernesto Jiménez
93a84c883d Merge pull request #147 from multiplay/master
Fix race condition with ExpectedCalls
2015-06-02 14:37:00 +01:00
Lee Packham
9768526b70 Fix race condition with ExpectedCalls
There is race condition caused when a method being tested calls a mocked
method within a go routine. For example, caching might be done a go
routine and that caching might be mocked.

There is already a mutex protecting the lists on the Mock object -
however Return() appends to ExpectedCalls and findExpectedCall could
run at the same time.
2015-06-02 12:54:01 +01:00
Ernesto Jiménez
232e856367 Merge pull request #170 from TechnotronicOz/versioning-strategy
Updated README for versioning strategy
v1.0
2015-05-27 15:45:55 +01:00
Matt Carter
d4befe148c Updated README for versioning strategy 2015-05-21 20:36:59 -05:00
Ernesto Jiménez
dab07ac62d Merge pull request #164 from HawaiianSpork/delta_nan
Address #162: InDelta should fail when actual value is not a number.
2015-05-12 13:42:33 +01:00
Michael R. Maletich
4e2053a4af Address #162: InDelta should fail when actual value is not a number.
Comparting a float with NaN is always false so the assertion would always pass.
Added a check that either the actual or expected values are NaN.

InDelta will now fail if either the actual or expected value are NaN.
2015-05-12 11:54:42 +00:00
Ernesto Jiménez
5ab65693f4 Merge pull request #160 from stretchr/issue-159
Address #159: Meaningful panic when expecting Func
2015-05-07 13:08:08 +01:00
Ernesto Jiménez
1faea58ff8 Address #159: Meaningful panic when expecting Func
We cannot compare two Func arguments to check if they are equal using
the reflect package. This leads to the following misleading panic:

```go
handler := func(http.ResponseWriter, *http.Request) {}
muxMock.On("HandleFunc", "/", handler)
muxMock.HandleFunc("/", handler)
// panics arguing handler != handler
```

Since we cannot fix this behaviour using reflection, this patch
provides a better panic with a meaningful workaround.

```go
handler := func(http.ResponseWriter, *http.Request) {}
muxMock.On("HandleFunc", "/", handler)
// panics recommending defining the expectatin with:
//   AnythingOfType("func(http.ResponseWriter, *http.Request)")
```

Solution following the panic's instructions:

```go
handler := func(http.ResponseWriter, *http.Request) {}
muxMock.On("HandleFunc", "/",
  mock.AnythingOfType("func(http.ResponseWriter, *http.Request)"))
muxMock.HandleFunc("/", handler)
```
2015-05-06 19:35:54 +01:00
Ernesto Jiménez
8bfd855592 Add test cases mocking methods with Func arguments 2015-05-06 19:24:54 +01:00
Ernesto Jiménez
73a8112e05 Merge pull request #158 from stretchr/mock-run-handler
Allow mocking methods updating referenced structs
2015-05-04 23:00:33 +01:00
Ernesto Jiménez
a369d6f598 Allow mocking methods updating referenced structs
Some methods in Go take a pointer to a struct or a map and are supposed
to set some values in the referenced argument. Using Return is not
enough to mock such methods.

We are introducing a Run method that allows setting a Call handler to
make your mock update such referenced values.

Example usage mocking a service that finds a user in a data store and
fills the values in the provided struct:

```go
m.On("Find", 1, mock.AnythingOfType(*User))
  .Return(nil)
  .Run(func(args mock.Arguments) {
  u := args.Get(0).(*User)
  u.ID = 1
  u.Email = "mail@example.com"
})
```
2015-05-04 16:56:39 +01:00
Mat Ryer
e22aedd376 Tweaks and improvements - Fixes #154 2015-04-20 11:19:11 +01:00
Davide D'Agostino
3b361f7ebb Merge pull request #134 from lazywei/master
Add InDeltaSlice.
2015-04-18 12:10:15 -07:00
Chih-Wei Chang
8b75665fbf Add InEpsilonSlice and corresponding testing. 2015-04-18 22:40:21 +08:00
Davide D'Agostino
08c64393a9 Merge pull request #139 from sul3n3t/equalvalues-doc
Doc entry for EqualValues assertion
2015-04-17 12:10:28 -07:00
Davide D'Agostino
e9fe59ca38 Merge pull request #148 from ernesto-jimenez/master
Mock can block returns with .After and .WaitUntil
2015-04-17 12:07:20 -07:00
Davide D'Agostino
1d30fbccfe Merge pull request #153 from lummie/lummie-patch-1
Fix "go vet" errors for incorrect printf verb
2015-04-17 12:06:42 -07:00
lummie
3a9efeedd4 Fix "go vet" errors for incorrect printf verb
github.com/stretchr/testify/mock/mock.go:289: arg m.ExpectedCalls for printf verb %s of wrong type: []mock.Call                                                                                                                       
github.com/stretchr/testify/mock/mock.go:298: arg m.ExpectedCalls for printf verb %s of wrong type: []mock.Call
2015-04-17 16:21:01 +01:00
Davide D'Agostino
59fc8e570c Revert "Remove sprintf equality check"
This reverts commit 842aeb8181a59ae6d0fac42eaef90ca01ba59c53.
2015-04-16 16:28:52 -07:00
Tyler Bunnell
4f9c9aeeaa Don't handle func comparisons 2015-04-16 11:41:42 -06:00
Tyler Bunnell
842aeb8181 Remove sprintf equality check
Fix #143
2015-04-16 10:41:30 -06:00
Ernesto Jiménez
0792dedcd1 Mock can block returns with .After and .WaitUntil
You sometimes want to test concurrent behaviour like timeouts, but it
was not currently possible with our mocks.

This commits adds the following functions to Mock:

`After` will block m.Called for the given duration before returning.

```golang
func (m *Mock) After(d time.Duration) *Mock

Mock.On("MyMethod", arg1).After(1 * time.Millisecond)
```

`WaitUntil` is the primitive under `After`, and it's exposed in case you
want somebody wants more control over the returns. `Called` blocks until the w
channel is closed or receives a message.

```golang
func (m *Mock) WaitUntil(w <-chan time.Time) *Mock

Mock.On("MyMethod", arg1).WaitUntil(time.After(1 * time.Millisecond))
```
2015-04-07 23:42:31 +01:00
Justin Cummins
4a32eaca39 Doc entry for EqualValues assertion
Also fixes missing right-bracket on Equal assertions.
2015-02-19 13:25:01 -08:00
Mat Ryer
e4ec8152c1 Merge pull request #137 from sul3n3t/forward-equalvalues
Forwards EqualValues assertion
2015-02-18 14:18:46 -08:00
Justin Cummins
d5621338a3 Forwards EqualValues assertion 2015-02-18 14:08:46 -08:00
Chih-Wei Chang
f0b02af48e Add InDeltaSlice. 2015-02-18 10:38:24 +08:00
Tyler
efa3c4c364 Merge pull request #131 from parkr/patch-1
assert: fix syntax error in http assertion comments
2015-02-10 18:53:42 -07:00
Parker Moore
9cce94c41a assert: fix syntax error in http assertion comments 2015-02-10 17:17:43 -08:00
Tyler
6cfa05f71d Merge pull request #130 from pquerna/add_assert_equal_values
Add assert.EqualValues, which attempts to convert types to test equality
2015-02-10 18:00:25 -07:00
Paul Querna
e73f5c7e39 Add assert.EqualValues, which attempts to convert types to test equality. Fixes #129 2015-02-10 16:56:43 -08:00
Tyler
43d0eed245 Merge pull request #128 from icecrime/equality_without_conversions
Exclude `ConvertibleTo` from equality test
2015-02-10 14:21:14 -07:00
Arnaud Porterie
9bab92ede2 Exclude conversions from equality tests
`ObjectsAreEqual` using `ConvertibleTo` causes the `ObjectsAreEqual`
function to be asymmetrical and producing incorrect assertions.

Signed-off-by: Arnaud Porterie <arnaud.porterie@docker.com>
2015-02-06 16:08:28 -08:00
nelsam
33a31e5dbe Merge pull request #121 from stretchr/suite_getters
Add getters for *assert.Assertions and *require.Assertions
2015-01-22 11:43:47 -07:00
nelsam
fe50b6aa5a Merge pull request #122 from stretchr/issues/120
Fixed regexp messages.  Resolves #120.
2015-01-22 11:42:56 -07:00
Samuel Nelson
ff9ded0d23 Fixed regexp messages. Resolves #120. 2015-01-19 12:45:07 -07:00
Samuel Nelson
354307edce Add getters for *assert.Assertions and *require.Assertions 2015-01-19 12:15:53 -07:00
Tyler
e897f97d66 Merge pull request #93 from dlclark/master
Fixed regexp error messages to include input values to aide debugging
2015-01-13 10:39:58 -07:00
nelsam
2160c81a96 Merge pull request #109 from anupcshan/master
Use mockedObj.Method(args) instead of mockedObj.Mock.Method(args).
2015-01-10 12:35:18 -07:00
nelsam
8bb32e75f4 Merge pull request #113 from andreas/require-assertions
Add require.Assertions like assert.Assertions
2015-01-10 12:32:59 -07:00
nelsam
945825c690 Update README.md 2015-01-10 12:25:02 -07:00
Samuel Nelson
02a8ab057b Reverse ConvertibleTo check to avoid panic
in `ObjectsAreEqual`, `expectedValue.Convert(actualType)` was being called when
`actualType.ConvertibleTo(reflect.TypeOf(expected))` was true.  This was a problem
for situations such as when expected was an int and actual was a string, since
ints are `ConvertibleTo` strings, but the reverse is not true.

Changing the ConvertibleTo check to `expectedValue.Type().ConvertibleTo(actualType)`
solves the issue.
2015-01-10 12:18:57 -07:00
Samuel Nelson
85138dbfa5 Move to stretchr/testify travis 2015-01-10 12:10:57 -07:00
Andreas Garnæs
49c0f07da4 Add require.Assertions like assert.Assertions. 2015-01-06 16:39:32 +00:00
Andreas Garnæs
ecf599d7db Update require package to match assert package. 2015-01-06 16:38:10 +00:00
Andreas Garnæs
8033b5cf75 Remove false documentation. 2015-01-06 16:37:26 +00:00