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 9197381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:03:46+00:00 2026-06-17T22:03:46+00:00

Specs2’s documentation and samples show some codes about the use of Given/Then/When style in

  • 0

Specs2’s documentation and samples show some codes about the use of Given/Then/When style in an acceptance test.

Here one of them:

"A given-when-then example for the addition"                   ^
    "Given the following number: ${1}"                         ^ number1 ^
    "And a second number: ${2}"                                ^ number2 ^
    "And a third number: ${3}"                                 ^ number3

  val number1: Given[Int]               = (_:String).toInt
  val number2: When[Int, (Int, Int)]    = (n1: Int) => (s: String) => (n1, s.toInt)
  val number3: When[Seq[Int], Seq[Int]] = (numbers: Seq[Int]) => (s: String) => numbers :+ s.toInt

However, it only deal with some primitive objects as Int here (normal since it’s a sample).

But how to deal with complex objects? Using Datatables?

Ideal would be to define, within some file of “fixtures”, datatables (or similar things) defining complex objects.

External datatable defining the User “Mik”

"name" |   "job"    | "e-mail"
"mik"  | "engineer" | "mik@mik.com"

I would like to create a Given statement like this one:

"Given the following user: ${Mik}"       ^ retrieve_user_from_database ^

val user: Given[User]               = .....Some ideal codes here to map Mik's values to User model.

What is a good practice and what does Specs2 currently provide?

  • 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-17T22:03:47+00:00Added an answer on June 17, 2026 at 10:03 pm

    If you want to retrieve a user from an existing database, you can do the following:

    "Given the following user: ${Mik}" ^ user ^
    
    val user: Given[User] = (name: String) => database.getUserByName(name) 
    

    Now you might want to populate your database with users before doing that. One possibility is indeed to use Datatables:

    def populateDatabase = 
      "name" ||   "job"    | "e-mail"        |
      "mik"  !! "engineer" ! "mik@mik.com"   |
      "eric" !! "engineer" ! "eric@eric.com" | { (name, job, email) => 
        database.saveUser(User(name, job, email)) must not(throwAn[Exception])
      }
    

    and put this in a Step before your G/W/T group:

    Step(populateDatabase) ^
    "Given the following user: ${Mik}"  ^ user ^
    "This user should be an ${engineer} ^ jobOk ^
                                          end
    
    val user: Given[User] = (name: String) => database.getUserByName(name)
    val jobOk: Then[User] = (user: User) => (job: String) => user.job must_== job
    
    • 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
Specs2 promotes functional style when dealing with Acceptance specification (even Unit specification if we
Is there some preferred way to design a Specs2 test, with lots of tests
I don't want to execute some code when it comes from test (Specs2) For
I'm trying to test-drive some Scala code using Specs2 and Mockito. I'm relatively new
I have written a ScalaCheck test case within Specs2. The test case gives up
I'm trying to test a model method using Play Framework 2.0 and Specs2. Global.scala
I'm using specs2 (v1.8.2) on with Scala (v2.9.1) to write acceptance tests. Following the
I have been testing my code with Specs2 for some time now and in
I'm using Slick with a Play Framework 2.1 and I have some troubles. Given

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.