Skip to content
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

Return the configured answers when no answer found #1032

Merged

Conversation

maeserichar
Copy link
Contributor

This PR modifies the way the MockKException is constructed when a mock is called with a set of parameters that wasn't configured, so it also adds to the exception message all the answers configured for that mock.

The aim of this change is to help understand why is the mock's call really failing, giving some extra information to the developer.

Copy link
Collaborator

@Raibaz Raibaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one, thanks for putting this together!

Just a few nits on the format of the log message but otherwise LGTM

@@ -87,7 +87,9 @@ open class MockKStub(
childMockK(invocation.allEqMatcher(), invocation.method.returnType)
}
} else {
throw MockKException("no answer found for: ${gatewayAccess.safeToString.exec { invocation.toString() }}")
val configuredAnswers = answers.map { it.matcher.toString() }.joinToString(separator = "\n") { it }
throw MockKException("no answer found for: ${gatewayAccess.safeToString.exec { invocation.toString() }}" +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove the first semicolon here and replace "between" with "among"

@Raibaz Raibaz merged commit 0f56adb into mockk:master Jan 30, 2023
hyochan pushed a commit to dooboolab-community/react-native-iap that referenced this pull request Jun 22, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [io.mockk:mockk](https://mockk.io)
([source](https://togithub.com/mockk/mockk)) | `1.13.4` -> `1.13.5` |
[![age](https://badges.renovateapi.com/packages/maven/io.mockk:mockk/1.13.5/age-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://badges.renovateapi.com/packages/maven/io.mockk:mockk/1.13.5/adoption-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://badges.renovateapi.com/packages/maven/io.mockk:mockk/1.13.5/compatibility-slim/1.13.4)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://badges.renovateapi.com/packages/maven/io.mockk:mockk/1.13.5/confidence-slim/1.13.4)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>mockk/mockk</summary>

### [`v1.13.5`](https://togithub.com/mockk/mockk/releases/tag/1.13.5)

#### What's Changed

- Return the configured answers when no answer found by
[@&#8203;maeserichar](https://togithub.com/maeserichar) in
[mockk/mockk#1032
- Recognize atLeast = 0 when mocked methods is never called by
[@&#8203;hfxbse](https://togithub.com/hfxbse) in
[mockk/mockk#970
- Update class declaration name to match with test class by
[@&#8203;Sandhya2902](https://togithub.com/Sandhya2902) in
[mockk/mockk#1044
- Update to Junit 5 by
[@&#8203;Sandhya2902](https://togithub.com/Sandhya2902) in
[mockk/mockk#1045
- Issue [#&#8203;997](https://togithub.com/mockk/mockk/issues/997) -
Simulate garbage collected proxy by
[@&#8203;ygaller](https://togithub.com/ygaller) in
[mockk/mockk#1052
- Enable Gradle build scan publishing by
[@&#8203;Goooler](https://togithub.com/Goooler) in
[mockk/mockk#1060
- Added the "Top Level functions" section by
[@&#8203;polarene](https://togithub.com/polarene) in
[mockk/mockk#1061
- corrected incongruent code in "Object mock" by
[@&#8203;polarene](https://togithub.com/polarene) in
[mockk/mockk#1063
- Kotlin 1.8.20 by
[@&#8203;SimonMarquis](https://togithub.com/SimonMarquis) in
[mockk/mockk#1047

#### New Contributors

- [@&#8203;maeserichar](https://togithub.com/maeserichar) made their
first contribution in
[mockk/mockk#1032
- [@&#8203;hfxbse](https://togithub.com/hfxbse) made their first
contribution in
[mockk/mockk#970
- [@&#8203;ygaller](https://togithub.com/ygaller) made their first
contribution in
[mockk/mockk#1052
- [@&#8203;Goooler](https://togithub.com/Goooler) made their first
contribution in
[mockk/mockk#1060

**Full Changelog**:
mockk/mockk@v1.13.4...1.13.5

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/dooboolab-community/react-native-iap).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS45OC40IiwidXBkYXRlZEluVmVyIjoiMzUuMTMxLjAiLCJ0YXJnZXRCcmFuY2giOiJtYWluIn0=-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants