https://kotlinlang.org logo
Title
m

Matteo Mirk

05/16/2023, 2:54 PM
I know it sounds weird, but does exist a way to copy an initialized mock? I couldn't find a way...
m

Mattia Tommasone

05/16/2023, 2:55 PM
what do you want to do exactly? copying a mock does not seem like a very good idea to me 😅
m

Matteo Mirk

05/16/2023, 3:00 PM
yeah I know 😛 it's always the same problem, working on legacy code, where a lot of mocks (worse, mocked data) are declared with lots of stubbing; so I was looking for a short way to copy one and add some different stubbing. But if it's not doable, it's not a problem. In the end I encapsulated the existing mock creation in a function and carried on.
I was looking if anything like this existed:
val newMock = mockk(anotherMock) {
  every {...}
  ...
}
m

Mattia Tommasone

05/16/2023, 8:00 PM
it doesn’t, but if you want to put together a PR about it i won’t complain 🙂
m

Matteo Mirk

05/17/2023, 7:38 AM
haha nice weekend project idea! 😄
I'll keep that in mind
m

Mattia Tommasone

05/17/2023, 7:38 AM
the weather forecast for the weekend in Italy is awful anyway 😄
m

Matteo Mirk

05/17/2023, 7:56 AM
haha yes! terrible rainy week...