mirror of https://github.com/stretchr/testify.git
Revert "add mock.MethodCalled(methodName, args...)"
This reverts commit 17a0bd50e9
.
Should avoid simply exporting an internal method.
pull/441/head
parent
34687ebd28
commit
f712be9266
|
@ -213,7 +213,7 @@ func (m *Mock) On(methodName string, arguments ...interface{}) *Call {
|
|||
// Recording and responding to activity
|
||||
// */
|
||||
|
||||
func (m *Mock) FindExpectedCall(method string, arguments ...interface{}) (int, *Call) {
|
||||
func (m *Mock) findExpectedCall(method string, arguments ...interface{}) (int, *Call) {
|
||||
m.mutex.Lock()
|
||||
defer m.mutex.Unlock()
|
||||
for i, call := range m.ExpectedCalls {
|
||||
|
@ -287,11 +287,8 @@ func (m *Mock) Called(arguments ...interface{}) Arguments {
|
|||
}
|
||||
parts := strings.Split(functionPath, ".")
|
||||
functionName := parts[len(parts)-1]
|
||||
return m.MethodCalled(functionName, arguments...)
|
||||
}
|
||||
|
||||
func (m *Mock) MethodCalled(functionName string, arguments ...interface{}) Arguments {
|
||||
found, call := m.FindExpectedCall(functionName, arguments...)
|
||||
found, call := m.findExpectedCall(functionName, arguments...)
|
||||
|
||||
if found < 0 {
|
||||
// we have to fail here - because we don't know what to do
|
||||
|
|
|
@ -2,11 +2,10 @@ package mock
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
/*
|
||||
|
@ -562,7 +561,7 @@ func Test_Mock_findExpectedCall(t *testing.T) {
|
|||
m.On("Two", 2).Return("two")
|
||||
m.On("Two", 3).Return("three")
|
||||
|
||||
f, c := m.FindExpectedCall("Two", 3)
|
||||
f, c := m.findExpectedCall("Two", 3)
|
||||
|
||||
if assert.Equal(t, 2, f) {
|
||||
if assert.NotNil(t, c) {
|
||||
|
@ -581,7 +580,7 @@ func Test_Mock_findExpectedCall_For_Unknown_Method(t *testing.T) {
|
|||
m.On("Two", 2).Return("two")
|
||||
m.On("Two", 3).Return("three")
|
||||
|
||||
f, _ := m.FindExpectedCall("Two")
|
||||
f, _ := m.findExpectedCall("Two")
|
||||
|
||||
assert.Equal(t, -1, f)
|
||||
|
||||
|
@ -595,7 +594,7 @@ func Test_Mock_findExpectedCall_Respects_Repeatability(t *testing.T) {
|
|||
m.On("Two", 3).Return("three").Twice()
|
||||
m.On("Two", 3).Return("three").Times(8)
|
||||
|
||||
f, c := m.FindExpectedCall("Two", 3)
|
||||
f, c := m.findExpectedCall("Two", 3)
|
||||
|
||||
if assert.Equal(t, 2, f) {
|
||||
if assert.NotNil(t, c) {
|
||||
|
@ -1185,15 +1184,3 @@ func Test_WaitUntil_Parallel(t *testing.T) {
|
|||
// Allow the first call to execute, so the second one executes afterwards
|
||||
ch2 <- time.Now()
|
||||
}
|
||||
|
||||
func Test_MethodCalled(t *testing.T) {
|
||||
m := new(Mock)
|
||||
m.On("foo", "hello").Return("world")
|
||||
|
||||
found, _ := m.FindExpectedCall("foo", "hello")
|
||||
require.True(t, found >= 0)
|
||||
retArgs := m.MethodCalled("foo", "hello")
|
||||
require.True(t, len(retArgs) == 1)
|
||||
require.Equal(t, "world", retArgs[0])
|
||||
m.AssertExpectations(t)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue