{"modulePath":"github.com/raspberrypython/testify","version":"v0.0.0-20150620232711-089c7181b8c7","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package mock\n\nProvides a system by which it is possible to mock your objects and verify calls are happening as expected.\n\n### Example Usage {#hdr-Example_Usage}\n\nThe mock package provides an object, Mock, that tracks activity on another object.  It is usually embedded into a test object as shown below:\n\n\ttype MyTestObject struct {\n\t  // add a Mock object instance\n\t  mock.Mock\n\n\t  // other fields go here as normal\n\t}\n\nWhen implementing the methods of an interface, you wire your functions up to call the Mock.Called(args...) method, and return the appropriate values.\n\nFor example, to mock a method that saves the name and age of a person and returns the year of their birth or an error, you might write this:\n\n\tfunc (o *MyTestObject) SavePersonDetails(firstname, lastname string, age int) (int, error) {\n\t  args := o.Called(firstname, lastname, age)\n\t  return args.Int(0), args.Error(1)\n\t}\n\nThe Int, Error and Bool methods are examples of strongly typed getters that take the argument index position. Given this argument list:\n\n\t(12, true, \"Something\")\n\nYou could read them out strongly typed like this:\n\n\targs.Int(0)\n\targs.Bool(1)\n\targs.String(2)\n\nFor objects of your own type, use the generic Arguments.Get(index) method and make a type assertion:\n\n\treturn args.Get(0).(*MyObject), args.Get(1).(*AnotherObjectOfMine)\n\nThis may cause a panic if the object you are getting is nil (the type assertion will fail), in those cases you should check for nil first.\n\n## Constants\n\n```go\nconst (\n\t// The \"any\" argument.  Used in Diff and Assert when\n\t// the argument being tested shouldn't be taken into consideration.\n\tAnything string = \"mock.Anything\"\n)\n```\n\n## Functions\n\n```go\nfunc AssertExpectationsForObjects(t TestingT, testObjects ...interface{}) bool\n```\nAssertExpectationsForObjects asserts that everything specified with On and Return of the specified objects was in fact called as expected.\n\nCalls may have occurred in any order.\n\n## Types\n\n```go\ntype AnythingOfTypeArgument string\n```\nAnythingOfTypeArgument is a string that contains the type of an argument for use when type checking.  Used in Diff and Assert.\n\n```go\nfunc AnythingOfType(t string) AnythingOfTypeArgument\n```\nAnythingOfType returns an AnythingOfTypeArgument object containing the name of the type to check for.  Used in Diff and Assert.\n\nFor example:\n\n\tAssert(t, AnythingOfType(\"string\"), AnythingOfType(\"int\"))\n\n```go\ntype Arguments []interface{}\n```\nArguments holds an array of method arguments or return values.\n\n```go\nfunc (args Arguments) Assert(t TestingT, objects ...interface{}) bool\n```\nAssert compares the arguments with the specified objects and fails if they do not exactly match.\n\n```go\nfunc (args Arguments) Bool(index int) bool\n```\nBool gets the argument at the specified index. Panics if there is no argument, or if the argument is of the wrong type.\n\n```go\nfunc (args Arguments) Diff(objects []interface{}) (string, int)\n```\nDiff gets a string describing the differences between the arguments and the specified objects.\n\nReturns the diff string and number of differences found.\n\n```go\nfunc (args Arguments) Error(index int) error\n```\nError gets the argument at the specified index. Panics if there is no argument, or if the argument is of the wrong type.\n\n```go\nfunc (args Arguments) Get(index int) interface{}\n```\nGet Returns the argument at the specified index.\n\n```go\nfunc (args Arguments) Int(index int) int\n```\nInt gets the argument at the specified index. Panics if there is no argument, or if the argument is of the wrong type.\n\n```go\nfunc (args Arguments) Is(objects ...interface{}) bool\n```\nIs gets whether the objects match the arguments specified.\n\n```go\nfunc (args Arguments) String(indexOrNil ...int) string\n```\nString gets the argument at the specified index. Panics if there is no argument, or if the argument is of the wrong type.\n\nIf no index is provided, String() returns a complete string representation of the arguments.\n\n```go\ntype Call struct {\n\n\t// The name of the method that was or will be called.\n\tMethod string\n\n\t// Holds the arguments of the method.\n\tArguments Arguments\n\n\t// Holds the arguments that should be returned when\n\t// this method is called.\n\tReturnArguments Arguments\n\n\t// The number of times to return the return arguments when setting\n\t// expectations. 0 means to always return the value.\n\tRepeatability int\n\n\t// Holds a channel that will be used to block the Return until it either\n\t// recieves a message or is closed. nil means it returns immediately.\n\tWaitFor \u003c-chan time.Time\n\n\t// Holds a handler used to manipulate arguments content that are passed by\n\t// reference. It's useful when mocking methods such as unmarshalers or\n\t// decoders.\n\tRun func(Arguments)\n}\n```\nCall represents a method call and is used for setting expectations, as well as recording activity.\n\n```go\ntype Mock struct {\n\n\t// Represents the calls that are expected of\n\t// an object.\n\tExpectedCalls []Call\n\n\t// Holds the calls that were made to this mocked object.\n\tCalls []Call\n\t// contains filtered or unexported fields\n}\n```\nMock is the workhorse used to track activity on another object. For an example of its usage, refer to the \"Example Usage\" section at the top of this document.\n\n```go\nfunc (m *Mock) After(d time.Duration) *Mock\n```\nAfter sets how long to block until the call returns\n\n\tMock.On(\"MyMethod\", arg1, arg2).After(time.Second)\n\n```go\nfunc (m *Mock) AssertCalled(t TestingT, methodName string, arguments ...interface{}) bool\n```\nAssertCalled asserts that the method was called.\n\n```go\nfunc (m *Mock) AssertExpectations(t TestingT) bool\n```\nAssertExpectations asserts that everything specified with On and Return was in fact called as expected.  Calls may have occurred in any order.\n\n```go\nfunc (m *Mock) AssertNotCalled(t TestingT, methodName string, arguments ...interface{}) bool\n```\nAssertNotCalled asserts that the method was not called.\n\n```go\nfunc (m *Mock) AssertNumberOfCalls(t TestingT, methodName string, expectedCalls int) bool\n```\nAssertNumberOfCalls asserts that the method was called expectedCalls times.\n\n```go\nfunc (m *Mock) Called(arguments ...interface{}) Arguments\n```\nCalled tells the mock object that a method has been called, and gets an array of arguments to return.  Panics if the call is unexpected (i.e. not preceeded by appropriate .On .Return() calls) If Call.WaitFor is set, blocks until the channel is closed or receives a message.\n\n```go\nfunc (m *Mock) On(methodName string, arguments ...interface{}) *Mock\n```\nOn starts a description of an expectation of the specified method being called.\n\n\tMock.On(\"MyMethod\", arg1, arg2)\n\n```go\nfunc (m *Mock) Once()\n```\nOnce indicates that that the mock should only return the value once.\n\n\tMock.On(\"MyMethod\", arg1, arg2).Return(returnArg1, returnArg2).Once()\n\n```go\nfunc (m *Mock) Return(returnArguments ...interface{}) *Mock\n```\nReturn finishes a description of an expectation of the method (and arguments) specified in the most recent On method call.\n\n\tMock.On(\"MyMethod\", arg1, arg2).Return(returnArg1, returnArg2)\n\n```go\nfunc (m *Mock) Run(fn func(Arguments)) *Mock\n```\nRun sets a handler to be called before returning. It can be used when mocking a method such as unmarshalers that takes a pointer to a struct and sets properties in such struct\n\n\tMock.On(\"Unmarshal\", AnythingOfType(\"*map[string]interface{}\").Return().Run(function(args Arguments) {\n\t\targ := args.Get(0).(*map[string]interface{})\n\t\targ[\"foo\"] = \"bar\"\n\t})\n\n```go\nfunc (m *Mock) TestData() objx.Map\n```\nTestData holds any data that might be useful for testing.  Testify ignores this data completely allowing you to do whatever you like with it.\n\n```go\nfunc (m *Mock) Times(i int)\n```\nTimes indicates that that the mock should only return the indicated number of times.\n\n\tMock.On(\"MyMethod\", arg1, arg2).Return(returnArg1, returnArg2).Times(5)\n\n```go\nfunc (m *Mock) Twice()\n```\nTwice indicates that that the mock should only return the value twice.\n\n\tMock.On(\"MyMethod\", arg1, arg2).Return(returnArg1, returnArg2).Twice()\n\n```go\nfunc (m *Mock) WaitUntil(w \u003c-chan time.Time) *Mock\n```\nWaitUntil sets the channel that will block the mock's return until its closed or a message is received.\n\n\tMock.On(\"MyMethod\", arg1, arg2).WaitUntil(time.After(time.Second))\n\n```go\ntype TestingT interface {\n\tLogf(format string, args ...interface{})\n\tErrorf(format string, args ...interface{})\n}\n```\nTestingT is an interface wrapper around \\*testing.T\n\n","path":"github.com/raspberrypython/testify/mock","name":"mock","synopsis":"Provides a system by which it is possible to mock your objects and verify calls are happening as expected.","isRedistributable":true}
