Skip to content

Commit

Permalink
v3: Rename styles of mocks to be less confusing (#900)
Browse files Browse the repository at this point in the history
When talking about mockery in-person, I noticed it's hard to differentiate "mockery mocks" from "moq mocks".
This change disambiguates the different styles by giving them phonetically different sounds.
  • Loading branch information
LandonTClipp authored Jan 20, 2025
1 parent 0df888f commit 11f28d4
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .mockery.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
template: "mockery"
template: "testify"
tags: "custom2"
formatter: "goimports"
all: True
Expand Down
4 changes: 2 additions & 2 deletions .mockery_moq.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
template: moq
template: matryer
mockname: "Moq{{.InterfaceName}}"
filename: "mocks_moq_test.go"
filename: "mocks_matryer_test.go"
all: true
template-data:
skip-ensure: False
Expand Down
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ tasks:
mocks.remove:
desc: remove all mock files
cmds:
- find . -name '*_mock.go' -o -name 'mock_*_test.go' -o -name 'mocks.go' -o -name "mocks_moq.go" -o -name 'mocks_test.go' -o -name 'mocks_moq_test.go' -o -name 'mocks_*_test.go' | xargs -r rm
- find . -name '*_mock.go' -o -name 'mock_*_test.go' -o -name 'mocks.go' -o -name "mocks_moq.go" -o -name 'mocks_test.go' -o -name 'mocks_*_test.go' | xargs -r rm
- rm -rf mocks/

mocks.generate.mockery:
Expand Down
8 changes: 4 additions & 4 deletions docs/template-moq.md → docs/template-matryer.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: Moq
title: matryer
---

Moq
matryer/moq
====


Expand All @@ -21,7 +21,7 @@ Moq
=== "`.mockery.yml`"

```yaml
template: moq
template: matryer
packages:
github.com/vektra/mockery/v3/pkg/fixtures:
config:
Expand Down Expand Up @@ -112,7 +112,7 @@ Moq
}
```

Moq-style mocks are far simpler, and probably more intuitive, than mockery-style mocks. All that's needed is to define the function that will be run when the mock's method is called.
Moq-style mocks are far simpler, and probably more intuitive, than testify-style mocks. All that's needed is to define the function that will be run when the mock's method is called.

## `template-data`

Expand Down
6 changes: 3 additions & 3 deletions docs/template-mockery.md → docs/template-testify.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
title: Mockery
title: testify
---

Mockery
=======

Features for `#!yaml template: mockery`.
Features for `#!yaml template: testify`.

Choosing this template will render a traditional "mockery-style" template. The
section below shows what will be rendered for the given interface.
Expand All @@ -25,7 +25,7 @@ section below shows what will be rendered for the given interface.
=== "`.mockery.yml`"

```yaml
template: mockery
template: testify
packages:
github.com/vektra/mockery/v3/pkg/fixtures:
config:
Expand Down
8 changes: 4 additions & 4 deletions docs/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ templates that you can select with the `#!yaml template:` config parameter.

## Template Options

### `#!yaml template: "mockery"`
### `#!yaml template: "testify"`

[`mockery`](template-mockery.md) templates generate powerful, testify-based mock objects. They allow you to create expectations using argument-to-return-value matching logic.
[`testify`](template-testify.md) templates generate powerful, testify-based mock objects. They allow you to create expectations using argument-to-return-value matching logic.

```go
package test
Expand All @@ -28,9 +28,9 @@ func TestRequesterMock(t *testing.T) {
}
```

### `#!yaml template: "moq"`
### `#!yaml template: "matryer"`

[`moq`](template-moq.md) templates draw from the mocks generated from the project at https://github.com/matryer/moq. This project was folded into mockery, and thus moq-style mocks can be natively generated from within mockery.
[`matryer`](template-matryer.md) templates draw from the mocks generated from the project at https://github.com/matryer/moq. This project was folded into mockery, and thus moq-style mocks can be natively generated from within mockery.

Mocks generated using this template allow you to define precise functions to be run. Example:

Expand Down
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions internal/template_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ const (
)

var (
//go:embed moq.templ
templateMoq string
//go:embed mockery.templ
templateMockery string
//go:embed mock_matryer.templ
templateMatryer string
//go:embed mock_testify.templ
templateTestify string
)

var styleTemplates = map[string]string{
"moq": templateMoq,
"mockery": templateMockery,
"matryer": templateMatryer,
"testify": templateTestify,
}

// findPkgPath returns the fully-qualified go import path of a given dir. The
Expand Down
4 changes: 2 additions & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ nav:
- Templates: templates.md
- Running: running.md
- Templates:
- template-mockery.md
- template-moq.md
- template-testify.md
- template-matryer.md
- Features:
- replace-type.md
- Notes:
Expand Down

0 comments on commit 11f28d4

Please sign in to comment.