-
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
Issues mocking curried method with variable argument parameter #131
Comments
I'm seeing the same behaviour here. In my case the repeated parameter is in the first parameter list and the second parameter list is an implicit parameter list. Example:
The above compiles but the test fails (correctly) because a Seq("b") is actually passed.
|
that is an interesting one.
but that ends in a compiler error:
|
We are looking forward for the solution of this bug. Thank you so much. |
If |
I'm personally having trouble mocking a method as such
|
sorry, closed accidentally |
Maybe this workaround is helpful in the meantime: "Varargs in 2nd param list" should "be mockable" in {
trait TypeToMock {
def bar(i: Int)(what: String*): String
}
trait Workaround extends TypeToMock {
def bar(i: Int)(what: Any*): String
}
val m = mock[Workaround]
(m.bar(_: Int)(_: Seq[_])) expects (42, Seq("1", "2")) returning "baz" once()
m.bar(42)("1", "2") === "baz"
} |
@barkhorn Any idea how to mock or create a workaround for this: I just have to mock the first get() method that doesn't have any varargs string parameter, but some overloaded methods of it do have which I am not using but the problem remains.
With Mockito it works. ? |
Shortened the interface a bit to not depend on any external stuff:
Testcase:
probably need to create Record, Key, Policy differently. I stubbed them out to illustrate the pattern. Note: Any further requests/discussions on workarounds needs to be StackOverflow please. |
This thread seemed to go off the rails a bit. I'm a little confused. Is there still no way to use ScalaMock with |
This works fine with 6.0.0-M1 and scala 3 since there is one parameter list and type is inferred. trait DataStore {
def insertAt(timestamp: Long, elements: String*): Unit
}
val dataStore = mock[DataStore]
val timestamp = 40L
(dataStore.insertAt _).expects(*, Seq("TestString", "TestString2")).returns(())
dataStore.insertAt(timestamp, "TestString", "TestString2")
} |
I'll search for solution with scala 3. At first glance it can be done. But not really simple |
The documentation is unclear about how this interaction should be handled, and I can't seem to find a combination that works.
Given this trait:
And this test suite:
I expected that mocking
insertAt
would be fairly straightforward.However, this did not compile.
Removing the offending
*
didn't match the signature, but did compile.Unfortunately, this caused the test to fail.
Attempting to modify the mock to expect a WrappedArray was the next attempt.
This took me back to a compilation error, which did confirm that
String
was the appropriate type for that mock parameter.One final stab it the dark was to keep the
String
in the signature, but expect anArray
(WrappedArray
cannot be instantiated directly)This also does not compile.
So, at this point, I'm stuck. Can this be mocked?
The text was updated successfully, but these errors were encountered: