org.scalatest.GivenWhenThen.scala Maven / Gradle / Ivy
Show all versions of scalatest_2.11.0-RC2 Show documentation
/*
* Copyright 2001-2013 Artima, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.scalatest
/**
* Trait that contains methods named given
, when
, then
, and and
,
* which take a string message and implicit Informer
, and forward the message to the informer.
*
*
* Here's an example:
*
*
*
* package org.scalatest.examples.flatspec.info
*
* import collection.mutable
* import org.scalatest._
*
* class SetSpec extends FlatSpec with GivenWhenThen {
*
* "A mutable Set" should "allow an element to be added" in {
* Given("an empty mutable Set")
* val set = mutable.Set.empty[String]
*
* When("an element is added")
* set += "clarity"
*
* Then("the Set should have size 1")
* assert(set.size === 1)
*
* And("the Set should contain the added element")
* assert(set.contains("clarity"))
*
* info("That's all folks!")
* }
* }
*
*
*
* If you run this SetSpec
from the interpreter, you will see the following output:
*
*
*
* scala> new SetSpec execute
* A mutable Set
* - should allow an element to be added
* + Given an empty mutable Set
* + When an element is added
* + Then the Set should have size 1
* + And the Set should contain the added element
* + That's all folks!
*
*
*
* Note: The lower case forms of given
, when
, then
and and
were
* deprecated in ScalaTest because using then
as an identifier was deprecated in Scala 2.10.
*
*
* @author Bill Venners
*/
trait GivenWhenThen { this: Informing =>
/**
*
* The lower case form of given
was
* deprecated because using then
as an identifier was deprecated in Scala 2.10.
* Please use the upper case form, Given
, instead.
*
*/
@deprecated("Please use Given(message: String)(implicit info: Informer) instead.")
def given(message: String) {
Given(message)
}
/**
* Forwards a message to an implicit Informer
, preceded by "Given."
*
* @param message the message to forward to the passed informer
*/
def Given(message: String) {
info(Resources("givenMessage", message))
}
/**
*
* The lower case form of when
was
* deprecated because using then
as an identifier was deprecated in Scala 2.10.
* Please use the upper case form, When
, instead.
*
*/
@deprecated("Please use When(message: String)(implicit info: Informer) instead.")
def when(message: String) {
When(message)
}
/**
* Forwards a message to an implicit Informer
, preceded by "When ".
*
* @param message the message to forward to the passed informer
*/
def When(message: String) {
info(Resources("whenMessage", message))
}
/**
*
* The lower case form of then
was
* deprecated because using then
as an identifier was deprecated in Scala 2.10.
* Please use the upper case form, Then
, instead.
*
*/
@deprecated("Please use Then(message: String)(implicit info: Informer) instead.")
def then(message: String) {
Then(message)
}
/**
* Forwards a message to an implicit Informer
, preceded by "Then ".
*
* @param message the message to forward to the passed informer
*/
def Then(message: String) {
info(Resources("thenMessage", message))
}
/**
*
* The lower case form of and
was
* deprecated because using then
as an identifier was deprecated in Scala 2.10.
* Please use the upper case form, And
, instead.
*
*/
@deprecated("Please use And(message: String)(implicit info: Informer) instead.")
def and(message: String) {
And(message)
}
/**
* Forwards a message to an implicit Informer
, preceded by "And ".
*
* @param message the message to forward to the passed informer
*/
def And(message: String) {
info(Resources("andMessage", message))
}
}