Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8766043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:26:56+00:00 2026-06-13T16:26:56+00:00

I recently added a dependency on Specs2 to a project and noticed that some

  • 0

I recently added a dependency on Specs2 to a project and noticed that some existing tests written with ScalaTest and Mockito failed. These tests passed again once Specs2 was removed. Why does this happen?

lazy val scalatestandspecscoexisting = Project(
  id = "scalatest-and-specs-coexisting",
  base = file("."),
  settings = Project.defaultSettings ++
    GraphPlugin.graphSettings ++
    Seq(
    name := "Scalatest-And-Specs-Coexisting",
    organization := "com.bifflabs",
    version := "0.1",
    scalaVersion := "2.9.2",
//  libraryDependencies ++= Seq(scalaTest, mockito)   //Tests Pass, no-specs2
    libraryDependencies ++= Seq(scalaTest, specs2, mockito)  //Tests Fail
  )
)

The tests that failed all used Mockito and all setup a mock method with two different parameters. One of the calls to the mock does not return value it was set up with. The example below fails. A further requirement was that type must be a Function1 (or have apply method).

import org.scalatest.FunSuite
import org.scalatest.mock.MockitoSugar
import org.mockito.Mockito.when

trait MockingBird {
  //Behavior only reproduces when input is Function1
  def sing(input: Set[String]): String
}

class MockSuite extends FunSuite with MockitoSugar {

  val iWannaRock = Set("I wanna Rock")
  val rock = "Rock!"

  val wereNotGonnaTakeIt = Set("We're not gonna take it")
  val no = "No! We ain't gonna take it"

  test("A mock should match on parameter but isn't") {

    val mockMockingBird = mock[MockingBird]
    when(mockMockingBird.sing(iWannaRock)).thenReturn(rock)
    //Appears to return this whenever any Set is passed to sing
    when(mockMockingBird.sing(wereNotGonnaTakeIt)).thenReturn(no)

    // Succeeds because it was set up last
    assert(mockMockingBird.sing(wereNotGonnaTakeIt) === no)
    // Fails because the mock returns "No! We ain't gonna take it"
    assert(mockMockingBird.sing(iWannaRock) === rock)
  }
}

Output:

 [info] MockSuite:
 [info] - A mock should match on parameter but isn't *** FAILED ***
 [info]   "[No! We ain't gonna take it]" did not equal "[Rock!]" (MockSuite.scala:38)
 [error] Failed: : Total 1, Failed 1, Errors 0, Passed 0, Skipped 0
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T16:26:57+00:00Added an answer on June 13, 2026 at 4:26 pm

    EDIT – according to Eric’s comment below, this is a bug in Specs2 ≤ 1.12.2. Should be fixed in 1.12.3.

    It turns out that Specs2 redefines some of the behavior in Mockito in order to get by-name parameters to match.

    Eric answered my question

    “I don’t like this, but that’s the only way I found to match byname
    parameters: http://bit.ly/UF9bVC . You might want that.”

    From the Specs2 documentation

    Byname

    Byname parameters can be verified but this will not work if the specs2
    jar is not put first on the classpath, before the mockito jar. Indeed
    specs2 redefines a Mockito class for intercepting method calls so that
    byname parameters are properly handled.

    In order to get my tests to pass again, I did the opposite of what was suggested in the specs2 documentation and added Specs2 dependency after Mockito. I have not tried, but I would expect by-name parameter matching to fail.

    lazy val scalatestandspecscoexisting = Project(
      id = "scalatest-and-specs-coexisting",
      base = file("."),
      settings = Project.defaultSettings ++
        GraphPlugin.graphSettings ++
        Seq(
        name := "Scalatest-And-Specs-Coexisting",
        organization := "com.bifflabs",
        version := "0.1",
        scalaVersion := "2.9.2",
    //  libraryDependencies ++= Seq(scalaTest, mockito)   //Tests Pass
        libraryDependencies ++= Seq(scalaTest, mockito, specs2)  //Tests Pass
    //  libraryDependencies ++= Seq(scalaTest, specs2, mockito)  //Tests Fail
      )
    )
    

    My tests now pass

    [info] MockSuite:
    [info] - A mock should match on parameter but isn't
    [info] Passed: : Total 1, Failed 0, Errors 0, Passed 1, Skipped 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently added some namespaces to my web.config file so that all of my
I recently added some new jar's to my android project. Some of the jars
I've recently added ActiveScaffold to an existing Rails project, and the problem I'm having
I recently added a stored procedure to my SQL Azure database. I added that
I recently added a feature to a large application written in Delphi (version 2009)
I recently added these lines to my ~/.bashrc file to show the current branch
I recently added some url re-writing to my web application and had to added
We have recently added AppFabric as a caching option in our project (Windows server
I recently added a new project to my Visual Studio 2008 solution. Now, as
We recently added a feature to our software that requires .NET 2.0 SP2. This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.