-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
is there an support for RETURNS_DEEP_STUBS #128
Comments
Hi @wangtengda0310, could you provide more details? E.g. could you specify the Interfaces and what you expect from the methods to return exactly. Thanks. |
interface/interface.go package _interface
type Foo interface {
Foo() Bar
}
type Bar interface {
Bar() string
} pegomock/pegomock_test.go package pegomock
import (
"github.com/petergtz/pegomock/v4"
"github.com/stretchr/testify/assert"
"testing"
)
//go:generate pegomock generate --package=pegomock myproj/interface Foo
//go:generate pegomock generate --package=pegomock myproj/interface Bar
func TestFoobar(t *testing.T) {
t.Run("this is ugly", func(t *testing.T) {
foo := NewMockFoo()
bar := NewMockBar()
pegomock.When(foo.Foo()).ThenReturn(bar)
pegomock.When(bar.Bar()).ThenReturn("baz")
assert.Equal(t, "baz", foo.Foo().Bar())
})
t.Run("this is pretty but nil pointer error", func(t *testing.T) {
foo := NewMockFoo()
pegomock.When(foo.Foo().Bar()).ThenReturn("baz")
assert.Equal(t, "baz", foo.Foo().Bar())
})
} go.mod module myproj
go 1.22.5
require (
github.com/petergtz/pegomock/v4 v4.1.0
github.com/stretchr/testify v1.9.0
)
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gopherjs/gopherjs v1.17.2 // indirect
github.com/jtolds/gls v4.20.0+incompatible // indirect
github.com/onsi/gomega v1.27.6 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/smarty/assertions v1.15.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
) |
there is a |
Thanks for clarifying. Pegomock doesn't support that feature. I guess it could be implemented, but it's not trivial to do so. As the mockito documentation says, this pattern should be used in very rare cases, such as legacy code. If you still need it and are willing to contribute, I'd be happy to merge a PR. |
pegomock.When(mock.Foo().Bar()).ThenReturn("how to mock Bar() conveniently?")
The text was updated successfully, but these errors were encountered: