You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you want to discuss a new feature, please ignore/clear this form.
ScalaMock Version (e.g. 3.5.0)
5.2.0
Scala Version (e.g. 2.12)
2.13
Runtime (JVM or JS)
JVM
Please describe the expected behavior of the issue
Trying to mock a trait with scala Parser. Receive error like follows:
Parameter type in structural refinement may not refer to an abstract type defined outside that refinement
val mockedCommandDispatcher = mock[UserRepositoryManagementCommandDispatcher]
Reproducible Test Case
Please provide a minimised code snippet that fails, ideally, written as a failing test case in ScalaTest.
This will help us a lot in diagnosing the problem and work on a fix.
If the issue is more complex or requires configuration, please provide a link to a project on Github that reproduces the issue.
`
importorg.scalatest.flatspec.AnyFlatSpecimportorg.scalatest.matchers.should.Matchersimportorg.scalamock.scalatest.MockFactoryimportscala.util.parsing.combinator.RegexParsersimportscala.concurrent.Futureimportscala.concurrent.ExecutionContext.Implicits.globaltraitPareserTrait {
deffindUser(username: String):Future[(String, String)]
defparseUser:Parser[Future[String]] = ("find-user"~> word |":") ^^ { username =>
findUser(username).map(result =>s"${result._1} for username ${result._2}")
}
}
classParserTraitTestextendsAnyFlatSpecwithMatcherswithMockFactorywithParserTraitwithRegexParsers {
"ParserTrait" should "parse user correctly with the expected username" in {
valparserTrait= mock[ParserTrait]
valexpectedUsername="John"valexpectedResult= ("User found", expectedUsername)
(parserTrait.findUser _)
.expects(expectedUsername)
.returning(Future.successful(expectedResult))
valinput=s"find-user $expectedUsername"valresult:Future[String] = parse(parserTrait.parseUser, input) match {
caseSuccess(parsedResult, _) => parsedResult
caseFailure(msg, _) =>Future.failed(newRuntimeException(s"Parsing failed: $msg"))
}
// Now you can assert on the parsed result without worrying about the implementation details.
result.map { parsedValue =>
parsedValue shouldBe s"${expectedResult._1} for username ${expectedResult._2}"
}
}
}
The text was updated successfully, but these errors were encountered:
If you want to discuss a new feature, please ignore/clear this form.
ScalaMock Version (e.g. 3.5.0)
5.2.0
Scala Version (e.g. 2.12)
2.13
Runtime (JVM or JS)
JVM
Please describe the expected behavior of the issue
Trying to mock a trait with scala Parser. Receive error like follows:
Parameter type in structural refinement may not refer to an abstract type defined outside that refinement
val mockedCommandDispatcher = mock[UserRepositoryManagementCommandDispatcher]
Reproducible Test Case
Please provide a minimised code snippet that fails, ideally, written as a failing test case in ScalaTest.
This will help us a lot in diagnosing the problem and work on a fix.
If the issue is more complex or requires configuration, please provide a link to a project on Github that reproduces the issue.
`
The text was updated successfully, but these errors were encountered: