Skip to content

Commit

Permalink
more updates to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
LandonTClipp committed Jul 9, 2023
1 parent 89aa686 commit 0040d3d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
4 changes: 0 additions & 4 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 17 additions & 1 deletion docs/examples.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 0040d3d

Please sign in to comment.