franela/goblin

Add support for mocking library

piclemx opened this issue · 6 comments

Will be cool if we can have the possibility to make it work with goblin gomock, mockery or others.

gomock and other mocking libraries usually rely. on *testing.T to work. As you can access that from goblin I believe it should work without too many effort. Have you tried to setup an example?

@marcosnils you can access it but when the mock fail it's not goblin error handler.

@piclemx do you have a simple example where this fails?.

@marcosnils there is an example, based on official example in testify:

package yours

import (
  "testing"
  "github.com/stretchr/testify/mock"
)

type MyMockedObject struct{
  mock.Mock
}

func (m *MyMockedObject) DoSomething(number int) (bool, error) {
  args := m.Called(number)
  return args.Bool(0), args.Error(1)
}

/*
  Actual test functions
*/

// TestSomething is an example of how to use our test object to
// make assertions about some target code we are testing.
// make assertions about func result
func TestSomething(t *testing.T) {
  g := Goblin(t)

  g.Describe("Test", func() {
    g.It("Test", func() {    
      testObj := new(MyMockedObject)
      testObj.On("DoSomething", 123).Return(true, nil)
      res := targetFuncThatDoesSomethingWithObj(testObj)

      // So, if this failed, we will see "1 tests failed" in output
      g.Assert(res).Equal(nil)

      // assert that the expectations were met
      // But if this failed — "1 tests complete"
      // Exit code will be 1, it is ok. And there will be a lot of logs about unexpected call,
      // but every thing will be ok in goblin output
      testObj.AssertExpectations(t)
  })
  })
}

@marcosnils as I can see, #55 will fix problem from that issue =) Let's finish #55?

@marcosnils never mind, different problem