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

Allow to copy an existing mock #1213

Open
3 tasks done
polarene opened this issue Jan 30, 2024 · 1 comment
Open
3 tasks done

Allow to copy an existing mock #1213

polarene opened this issue Jan 30, 2024 · 1 comment

Comments

@polarene
Copy link
Contributor

Prerequisites

Please answer the following questions for yourself before submitting an issue.

  • I am running the latest version
  • I checked the documentation and found no answer
  • I checked to make sure that this issue has not already been filed

Expected Behavior

I've encountered a scenario where I needed more than one mock of the same type but with a subset of different stubbings. Initializing each mock from scratch leads to duplication, which can only be avoided writing a custom function.
I'd like to have a copy factory function so I could write:

val first = mockk<Car> {
  // base stubbings
  every { drive(Direction.NORTH) } returns Outcome.OK
  every { door(DoorType.FRONT_LEFT).windowState() } returns WindowState.UP
}
val second = mockk(first) {
  // redefine a subset of stubbings
  every { drive(Direction.SOUTH) } returns Outcome.ERROR
}

second will be a new mock instance having all the configuration copied over, and its stubbings don't affect first.

Current Behavior

The library currently doesn't support this feature.

@polarene
Copy link
Contributor Author

I've started working on this feature but I'm still studying how to clone the internal data structures.

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

No branches or pull requests

1 participant