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

Mocking Slick Table results in compile error #507

Open
lolgab opened this issue Feb 21, 2024 · 5 comments
Open

Mocking Slick Table results in compile error #507

lolgab opened this issue Feb 21, 2024 · 5 comments
Labels

Comments

@lolgab
Copy link

lolgab commented Feb 21, 2024

ScalaMock Version (e.g. 3.5.0)

6.0.0-M1

Scala Version (e.g. 2.12)

2.13.12

Runtime (JVM or JS)

JVM

Please describe the expected behavior of the issue

It should stub successfully without errors

Please provide a description of what actually happens

Mocking Slick classes fails to compile

Reproducible Test Case

scala-cli test example.test.scala

Gives the following output:

[error] ./example.test.scala:17:21
[error] type mismatch;
[error]  found   : slick.lifted.Query[O(in method ++),Foo#TableElementType,D(in method ++)]
[error]     (which expands to)  slick.lifted.Query[O(in method ++),String,D(in method ++)]
[error]  required: slick.lifted.Query[(some other)O(in method ++),Foo#TableElementType,(some other)D(in method ++)]
[error]     (which expands to)  slick.lifted.Query[(some other)O(in method ++),String,(some other)D(in method ++)]
[error]   val example = stub[FooQuery]
[error]     
// example.test.scala

//> using scala 2
//> using lib org.scalamock::scalamock:6.0.0-M1
//> using lib org.scalatest::scalatest:3.2.18
//> using lib com.typesafe.slick::slick:3.4.1

import org.scalamock.scalatest.MockFactory
import org.scalatest.funsuite.AnyFunSuite
import slick.jdbc.H2Profile.api._

class Foo(tag: Tag) extends Table[String](tag, "FOO") {
  def * = column[String]("foo")
}
class FooQuery extends TableQuery(new Foo(_))

class test extends AnyFunSuite with MockFactory {
  val example = stub[FooQuery]
}

Self-contained reproduction

import org.scalamock.scalatest.MockFactory
import org.scalatest.funsuite.AnyFunSuite

class Foo extends Query
class Query[+E, U, C[_]] {
  def bar[O >: E, R, D[_]](other: Query[O, U, D]) = ???
}

class test extends AnyFunSuite with MockFactory {
  val example = stub[Foo]
}
@goshacodes
Copy link
Contributor

goshacodes commented Feb 24, 2024

Hi!
If you could provide a corresponding example without slick that would spare a huge amount of time for me

@lolgab
Copy link
Author

lolgab commented Feb 24, 2024

Hi @goshacodes,
I managed to extract a self-contained reproduction and added it to the issue description.

@goshacodes
Copy link
Contributor

Thank you!

@goshacodes
Copy link
Contributor

Hi again, I think it is impossible to make this work with scala 2. Works with scala 3 and latest slick

@lolgab
Copy link
Author

lolgab commented Mar 30, 2024

@goshacodes Good to know! One more reason to migrate to Scala 3.
You can work around the issue by defining a trait and mocking that instead of mocking the class itself, which is what we are doing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants