Skip to content

Commit

Permalink
Work with default return without expected params
Browse files Browse the repository at this point in the history
Fix #31
  • Loading branch information
rekby committed May 13, 2019
1 parent 8bae907 commit 9aa01d2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
6 changes: 5 additions & 1 deletion template.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,11 @@ const (
// if default expectation was set then invocations count should be greater than zero
if m.{{$method.Name}}Mock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.after{{$method.Name}}Counter) < 1 {
{{- if $method.HasParams}}
m.t.Errorf("Expected call to {{$mock}}.{{$method.Name}} with params: %#v", *m.{{$method.Name}}Mock.defaultExpectation.params)
if m.{{$method.Name}}Mock.defaultExpectation.params == nil {
m.t.Error("Expected call to {{$mock}}.{{$method.Name}}")
} else {
m.t.Errorf("Expected call to {{$mock}}.{{$method.Name}} with params: %#v", *m.{{$method.Name}}Mock.defaultExpectation.params)
}
{{else}}
m.t.Error("Expected call to {{$mock}}.{{$method.Name}}")
{{end -}}
Expand Down
8 changes: 6 additions & 2 deletions tests/formatter_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions tests/formatter_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,20 @@ func TestFormatterMock_ReturnAfterSet(t *testing.T) {
formatterMock.FormatMock.Return("Should not work")
}

func TestFormatterMock_ReturnWithoutExpectForFixedArgsMethod(t *testing.T) {
// Test for issue https://github.com/gojuno/minimock/issues/31

tester := NewTesterMock(t)
defer tester.MinimockFinish()

tester.ErrorMock.Expect("Expected call to FormatterMock.Format")
tester.FailNowMock.Expect()

formatterMock := NewFormatterMock(tester)
formatterMock.FormatMock.Return("")
formatterMock.MinimockFinish()
}

func TestFormatterMock_Set(t *testing.T) {
tester := NewTesterMock(t)

Expand Down

0 comments on commit 9aa01d2

Please sign in to comment.