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

explicit wrapping in withExpectations needed when working with specs2 Specification #489

Open
poohsen opened this issue Sep 7, 2023 · 0 comments

Comments

@poohsen
Copy link

poohsen commented Sep 7, 2023

ScalaMock Version (e.g. 3.5.0)

5.2.0
(specs2: 4.20.2)

Scala Version (e.g. 2.12)

2.13

Runtime (JVM or JS)

JVM

Please describe the expected behavior of the issue

The examples on https://scalamock.org/user-guide/sharing-specs2/ make it look like writing expectations inside a specs2 Specification should work without further boiler-plate as long as the test is wrapped in a in new MockContext {}.

Please provide a description of what actually happens

However, I find that the expectation is ignored if it's not wrapped in a withExpectations call.
I'm not sure if the problem is the documentation - the withExpectations boiler-plate needs to be there, or the code itself - withExpectations should be called under the hood somehow but isn't.

Reproducible Test Case

import org.scalamock.specs2.MockContext
import org.specs2.mutable.Specification

class MockTest extends Specification {

  class Testable() {
    def ret(): Int = 2
  }

  "expectation" should {
    "fail" in new MockContext {
      val m = mock[Testable]

      // this should fail IMO but it doesn't.
      // if I wrap it in `withExpectations`, however, it fails when 
      // using `once()` and works when using `never()` - as expected
      (m.ret _).expects().returns(1).once()
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant