added TestData to mocks

pull/14/merge
Mat Ryer 2013-04-30 10:35:17 -06:00
parent 044591a481
commit 87ce1d3239
2 changed files with 29 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package mock
import (
"fmt"
"github.com/stretchrcom/stew/objects"
"github.com/stretchrcom/testify/assert"
"reflect"
"runtime"
@ -46,6 +47,21 @@ type Mock struct {
// Holds the calls that were made to this mocked object.
Calls []Call
// TestData holds any data that might be useful for testing. Testify ignores
// this data completely allowing you to do whatever you like with it.
testData objects.Map
}
// TestData holds any data that might be useful for testing. Testify ignores
// this data completely allowing you to do whatever you like with it.
func (m *Mock) TestData() objects.Map {
if m.testData == nil {
m.testData = make(objects.Map)
}
return m.testData
}
/*

View File

@ -33,6 +33,19 @@ func (i *TestExampleImplementation) TheExampleMethod2(yesorno bool) {
Mock
*/
func Test_Mock_TestData(t *testing.T) {
var mockedService *TestExampleImplementation = new(TestExampleImplementation)
if assert.NotNil(t, mockedService.TestData()) {
mockedService.TestData().Set("something", 123)
assert.Equal(t, 123, mockedService.TestData().Get("something"))
}
}
func Test_Mock_On(t *testing.T) {
// make a test impl object