From 0040d3d76c74746263adfdef7e3dc96743e45f60 Mon Sep 17 00:00:00 2001 From: LandonTClipp Date: Sat, 8 Jul 2023 20:54:54 -0400 Subject: [PATCH] more updates to docs --- docs/configuration.md | 4 ---- docs/examples.md | 18 +++++++++++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index f51c319d..00176b2a 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -31,10 +31,6 @@ Recommended Basic Config Copy the recommended basic configuration to a file called `.mockery.yaml` at the top-level of your repo: ```yaml title=".mockery.yaml" -filename: "mock_{{.InterfaceName}}.go" -dir: "mocks/{{.PackagePath}}" -mockname: "Mock{{.InterfaceName}}" -outpkg: "{{.PackageName}}" with-expecter: true packages: github.com/your-org/your-go-project: diff --git a/docs/examples.md b/docs/examples.md index 0ed64186..71a3111e 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -1,6 +1,9 @@ Examples ======== +!!! tip + IDEs are really useful when interacting with mockery objects. All mockery objects embed the [`github.com/stretchr/testify/mock.Mock`](https://pkg.go.dev/github.com/stretchr/testify/mock#Mock) object so you have access to both methods provided by mockery, and from testify itself. IDE auto-completion will show you all methods available for your use. + ### Simple case Given this interface: @@ -35,7 +38,20 @@ func TestString(t *testing.T) { } ``` -Note that in combination with using the mock's constructor and the [`.EXPECT()`](features.md#expecter-structs) directives, your test will automatically fail if the expected call is not made. +Note that in combination with using the mock's constructor and the [`.EXPECT()`](features.md#expecter-structs) directives, your test will automatically fail if the expected call is not made. + +??? tip "Alternate way of specifying expectations" + You can also use the `github.com/stretchr/testify/mock.Mock` object directly (instead of using the `.EXPECT()` methods, which provide type-safe-ish assertions). + + ```go title="string_test.go" + func TestString(t *testing.T) { + mockStringer := NewMockStringer(t) + mockStringer.On("String").Return("mockery") + assert.Equal(t, "mockery", Foo(mockStringer)) + } + ``` + + We recommend always interacting with the assertions through `.EXPECT()` as mockery auto-generates methods that call out to `Mock.On()` themselves, providing you with compile-time safety. Consider if all your expectations for `String()` use the `Mock.On()` methods, and you decide to add an argument to `String()` to become `String(foo string)`. Now, your existing tests will only fail when you run them. If you had used `.EXPECT()` and regenerated your mocks after changing the function signature, your IDE, and the go compiler itself, would both tell you immediately that your expectations don't match the function signature. ### Function type case