Created
December 13, 2010 23:09
-
-
Save mkmik/739767 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package eu.rinfrastructures | |
import org.specs._ | |
trait FunctionalMatchers { | |
import org.specs.matcher.Matcher | |
type byNameMatcherFunction [A] = (=> A) => (Boolean, String, String) | |
type byValueMatcherFunction[A] = A => (Boolean, String, String) | |
implicit def byNameFunction2matcher[A] (f : byNameMatcherFunction[A]) = new Matcher[A] { | |
def apply(v: => A) = f(v) | |
} | |
implicit def byValueFunction2matcher[A] (f : byValueMatcherFunction[A]) = new Matcher[A] { | |
def apply(v: => A) = f(v) | |
} | |
} | |
trait ShortMatcher { | |
// cannot use by-name functional literals | |
def fBeLazyEven(number: => Int) = { | |
val b = number; (b % 2 == 0, b + " is even", b + " is odd") | |
} | |
val beLazyEven = fBeLazyEven _ | |
} | |
trait VeryShortMatcher { | |
def beEven = (b: Int) => (true, "great", "failure") | |
} | |
object newSpecification extends Specification with FunctionalMatchers | |
with ShortMatcher with VeryShortMatcher { | |
"short matchers" should { | |
"allow us to do" in { | |
"it's terse".size must beEven | |
"it's terse".size must beLazyEven | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment