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

  • Home
  • SEARCH
  • 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 9180851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:09:05+00:00 2026-06-17T18:09:05+00:00

Specs2 promotes functional style when dealing with Acceptance specification (even Unit specification if we

  • 0

Specs2 promotes functional style when dealing with Acceptance specification (even Unit specification if we want).

Risks of using old style (mutable style) are mentioned in the spec Specs2 philosophy and concernes potential unwanted side-effects:

The important things to know are:

side-effects are only used to build the specification fragments, by
mutating a variable they are also used to short-circuit the execution
of an example as soon as there is a failure (by throwing an exception).
If you build fragments in the body of examples or execute the same
specification concurrently
, the sky should fall down. “context”
management is to be done with case classes or traits (see
org.specs2.examples.MutableSpec)

I don’t figure out how a same specification could be run concurrently since each specification is distinct from the other (separated class’s instances), even if we run the same twice or more simultaneously.

Indeed, specFragments (mutable variable):

protected[mutable] var specFragments: Fragments = new Fragments()

is declared in a trait called FragmentBuilder, not in an object(in scala sense => singleton) or other shared thing…, so specFragments is a local variable to each Specification‘s instance.

So what might a scenario be risking concurrency mechanism?

I don’t really figure out a true scenario (non-stupid) proving the benefit of Specs2 functional style.

  • 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-17T18:09:06+00:00Added an answer on June 17, 2026 at 6:09 pm

    The issues with mutable specification can only be seen when the specification is being built, not when it is executed. When building a mutable specification it’s easy to have unexpected side-effect

    import org.specs2._
    
    val spec = new mutable.Specification {
      "example" >> ok
    }
    import spec._
    
    def addTitle {
      // WHOOPS, forgot to remove this line!
      // test, add also an example
      "this is only for testing" >> ok
    
      "new title".title
    }
    addTitle
    

    And the output is:

    new title
    
    + example
    + this is only for testing
    
    Total for specification new title
    Finished in 0 ms
    2 examples, 0 failure, 0 error
    

    So, you’re right, the highlighted sentence in the guide (“execute the same specification concurrently”) is ambiguous. The construction of the specification itself might be unsafe if several threads were building the same specification object but not if they were running it (the whole process being called “execute” in that sentence).

    Your other question is: what are the benefits of the “functional style”? The main benefit, from a user point of view, is that it is another style of writing specifications where all the text comes first and all the code is put elsewhere.

    In conclusion, do not fear the mutable style of Specification if you like it!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an acceptance test using Specs2. I want to use ImpermanentGraphDatabase in order
I'm using specs2 (v1.8.2) on with Scala (v2.9.1) to write acceptance tests. Following the
I'm trying to test a model method using Play Framework 2.0 and Specs2. Global.scala
We're using cdh3u4, Hadoop and HBase. I'm trying to run a unit test that
Moving from the Specs2 to Scalatest I tried using the WordSpec, but with no
Here's a simple specification reproducing the issue: package ro.igstan.learning import org.specs2.matcher.ThrownExpectations import org.specs2.mock.Mockito import
In the context of Specs2, a purist may argue that one should use unit
I don't want to execute some code when it comes from test (Specs2) For
I'm trying to write the following spec using Specs2 but can't seem to get
I'm trying to test-drive some Scala code using Specs2 and Mockito. I'm relatively new

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.