-
Notifications
You must be signed in to change notification settings - Fork 100
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
Add ability to capture arguments #234
Comments
See http://scalamock.org/user-guide/advanced_topics/ , topic "Returning values (onCall)" It's neither internal or undocumented :) |
I'm aware of that, and was looking for something a bit more first-class, but ok! |
i don't know what "more first-class" means. looking for some syntactic sugar? |
Yes, more sugar. Perhaps something like this: trait Foo {
def increment(a: Int): Int
}
val fooMock = mock[Foo]
val captor = capture[Int]
(foo.increment _).expects(captor).once()
println(captor.value) If there's an appetite for this I can take a stab at it. |
got something on a branch that works like this: it should "capture the arguments of mocks - capture one" in {
val m = mock[TestTrait]
val c1 = CaptureOne[Int]()
m.oneParam _ expects capture(c1) once()
m.oneParam(42)
c1.value should be (42)
}
it should "capture the arguments of mocks - capture all" in {
val m = mock[TestTrait]
val c = CaptureAll[Int]()
m.oneParam _ expects capture(c) repeat 3
m.oneParam(99)
m.oneParam(17)
m.oneParam(583)
c.value should be (583)
c.values should be (Seq(99, 17, 583))
} I'll push it later and you can review / comment @vakhtang ? |
Looks great, thanks! |
added argument capturing. fixes #234
As far as I can tell ScalaMock lacks the ability to capture arguments a la Mockito's
ArgumentCaptor
. This StackOverflow post alludes to a mechanism that exists under-the-hood. It'd be great to expose it, or if it doesn't actually exist, add it. I imagine this can be implemented as a custom matcher.The text was updated successfully, but these errors were encountered: