kiritsuku
kiritsuku

Reputation: 53358

Scala specs: nest in-statements

is it possible to nest following specs test code

"ClassX" should {
  "throw an IllegalArgumentException if n < 0" in {
    ClassX(-1) must throwA[IllegalArgumentException]
  }
  "throw an IllegalArgumentException if n > 50" in {
    ClassX(51) must throwA[IllegalArgumentException]
  }
  "throw an IllegalArgumentException if n == 35" in {
    ClassX(35) must throwA[IllegalArgumentException]
  }
}

in another in-Statement like:

"ClassX" should {
  "throw an IllegalArgumentException if" in {
    "n < 0" in {
      ClassX(-1) must throwA[IllegalArgumentException]
    }
    "n > 50" in  {
      ClassX(51) must throwA[IllegalArgumentException]
    }
    "n == 35" in  {
      ClassX(35) must throwA[IllegalArgumentException]
    }
  }
}

Because it is easier to read and write

Upvotes: 1

Views: 435

Answers (2)

iwein
iwein

Reputation: 26161

I prefer code like this:

 "My Component" >> {
   " some general function" can {
     "do stuff that I like" in {
       //…
     }
     "do stuff others like" in {
       //…
     }
   }
 }

but as you might notice there are a gazillion ways to do it.

Upvotes: 0

David Winslow
David Winslow

Reputation: 8590

Yes. See http://code.google.com/p/specs/wiki/DeclareSpecifications for an overview of all the ways you can structure Specs specifications.

Upvotes: 2

Related Questions