wix / specs2-jmock

This is a specs2 adapter + DSL for using the popular mocking framework JMock

GitHub

specs2-jmock

Build Status Maven Central

This is a specs2 adapter + DSL for using the popular mocking framework JMock

Installation

Maven

<dependency>
    <groupId>com.wix</groupId>
    <artifactId>specs2-jmock_${scala.version}</artifactId>
    <version>x.y.z</version>
    <scope>test</scope>
</dependency>

SBT

libraryDependencies += "com.wix" %% "specs2-jmock" % "x.y.z"

Usage

Mixin the JMock trait to your Specification class, and use the DSL.

Example

import com.wixpress.common.specs2.JMock

class JMockTest extends Specification with JMock  {

  "My JMock test" should { 
    "Do something" in {
      val mockFoo = mock[FooTrait]
      checking {
        allowing(mockFoo).bar.willReturn("foo")
        oneOf(mockFoo).baz()
      }
      val result = mockFoo.bar
      mockFoo.baz
      result must be equalTo "foo"
    }
    ...
    
  }

You can see more examples in the tests.

License

Use of this source code is governed by a BSD-style license which you can find here.