0

Before you point to the documentation, please point out what's wrong with this minimal, failing example:

import org.scalatest.FlatSpec
import org.scalamock.scalatest.proxy.MockFactory

class StubbingTest extends FlatSpec with MockFactory {
  trait Foo {
    def f(x: Int): Int
  }

  "foo" should "stub" in {
    val foo = stub[Foo]

    (foo.f _).when(3).returns(4)

    assert(foo.f(3) == 4)
  }
}

Which results in java.lang.NoSuchMethodException: com.sun.proxy.$Proxy4.mock$f$0() at line 11: (foo.f _).when ...

According to the documentation, this should work. What am I missing here?

stewSquared
  • 827
  • 5
  • 24

1 Answers1

0

I figured it out by pure luck while browsing the Scaladoc:

Change

import org.scalamock.scalatest.proxy.MockFactory

to

import org.scalamock.scalatest.MockFactory

My IDE's Auto-import failed me, but it would have really helped if the ScalaMock documentation examples included proper imports.

stewSquared
  • 827
  • 5
  • 24
  • 1
    Holy shit this was subtle. Took me a couple hours to find it. Hopefully, this helps someone else. – stewSquared Nov 01 '17 at 15:13
  • 1
    looks like you answered your own question. Do you think the documentation could be improved? The user guide actually lists the imports already: http://scalamock.org/user-guide/integration/ and so do the scaldocs: https://static.javadoc.io/org.scalamock/scalamock_2.11/4.0.0/index.html#org.scalamock.package – Philipp Nov 02 '17 at 07:36
  • Yeah, but it'd be nicer if it were closer to the code examples I was looking at. Perhaps once per page to assist the copy pasta chefs in the world :P – stewSquared Dec 14 '17 at 04:07